Skip to content

Instantly share code, notes, and snippets.

View tonylattke's full-sized avatar

Tony Lattke tonylattke

View GitHub Profile
@tonylattke
tonylattke / views.py
Last active August 29, 2015 14:22
Django Parte III: Pruebas de vistas
from django.core.urlresolvers import reverse
from django.test import TestCase
from posts.models import Post
class PostsViewsTestCase(TestCase):
fixtures = ['posts__testdata.json']
# Prueba de la página de inicio
def test_index(self):
@tonylattke
tonylattke / models.py
Last active August 29, 2015 14:22
Django Parte III: Pruebas de modelo
from django.utils import timezone
from django.test import TestCase
from posts.models import Post
class PostTestCase(TestCase):
fixtures = ['posts__testdata.json']
# Inicialización de las variables
def setUp(self):
@tonylattke
tonylattke / __init__.py
Created June 6, 2015 08:22
Django Parte III: tests/__init__.py
from posts.tests.models import *
from posts.tests.views import *
@tonylattke
tonylattke / urls.py
Last active August 29, 2015 14:22
Django Parte III: URLS modificados
from django.conf.urls import url
from . import views
urlpatterns = [
# Post
url(r'^$' , views.index, name='posts_index'), # Listar
url(r'^(?P<post_id>[0-9]+)?$' , views.obtener, name='posts_obtener'), # Obtener
url(r'^crear$' , views.crear, name='posts_crear'), # Crear
url(r'^crear_do$' , views.crear_do, name='posts_crear_do'), # Crear do
@tonylattke
tonylattke / posts__testdata.json
Created June 6, 2015 08:19
Django Parte III: Post fixtures
[
{
"pk": 1,
"model": "posts.post",
"fields": {
"pub_fecha": "2015-05-05 16:23:42",
"nombre": "Hola",
"contenido": "Funciona",
"autor":"Tony"
}
@tonylattke
tonylattke / saludar.py
Created June 6, 2015 07:21
Django Parte III: Comando saludar
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from posts.models import *
class Command(BaseCommand):
args = ''
help = 'Tarea que saluda'
@tonylattke
tonylattke / admin.py
Last active August 29, 2015 14:22
Django Parte III: Configuraciones del admin
from django.contrib import admin
from django import forms
from .models import Post
''' ******************************* Ayudas ******************************* '''
#Formato Form
class Text_Form(forms.ModelForm):
contenido = forms.CharField( widget=forms.Textarea )
@tonylattke
tonylattke / models.py
Created June 6, 2015 06:58
Django Parte III: Configuraciones del modelo
from django.db import models
from django.utils import timezone
from datetime import timedelta
class Post(models.Model):
nombre = models.CharField(max_length=200)
autor = models.CharField(max_length=200)
contenido = models.TextField()
pub_fecha = models.DateTimeField('fecha')
@tonylattke
tonylattke / base.html
Created May 30, 2015 23:21
Django Parte II: Base del html con autentificación
{% block sidebar_content %}
{% endblock sidebar_content %}
<div class="well">
{% if user.is_authenticated %}
<a href="/sesion/logout">Cerrar sesión</a>
{% else %}
<a href="/sesion/login">Iniciar sesión</a>
{% endif %}
</div>
@tonylattke
tonylattke / views.py
Last active August 29, 2015 14:22
Django Parte II: Vistas de Post
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.core.urlresolvers import reverse
from datetime import datetime
import json
from .models import Post
##################################### POST ####################################