diff options
Diffstat (limited to 'blog')
-rw-r--r-- | blog/admin.py | 4 | ||||
-rw-r--r-- | blog/urls.py | 14 | ||||
-rw-r--r-- | blog/views.py | 22 |
3 files changed, 24 insertions, 16 deletions
diff --git a/blog/admin.py b/blog/admin.py index b6b7835..7455800 100644 --- a/blog/admin.py +++ b/blog/admin.py @@ -1,12 +1,14 @@ # vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab: from django.contrib import admin -from elgarito.blog.models import Articulo, Comentario +from blog.models import Articulo, Comentario + class ArticuloAdmin(admin.ModelAdmin): list_display = ('titulo', 'autor', 'created_on') admin.site.register(Articulo, ArticuloAdmin) + class ComentarioAdmin(admin.ModelAdmin): list_display = ('texto', 'autor', 'created_on') diff --git a/blog/urls.py b/blog/urls.py index b04d4cd..04324df 100644 --- a/blog/urls.py +++ b/blog/urls.py @@ -1,9 +1,11 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url -urlpatterns = patterns('elgarito.blog.views', - (r'^$', 'index'), +urlpatterns = patterns( + 'blog.views', + + url(r'^$', 'index'), - (r'^(?P<articulo_id>\d+)/$', 'articulo'), - (r'^nuevo/$', 'nuevo'), - (r'^(?P<articulo_id>\d+)/crear_comentario/$', 'crear_comentario'), + url(r'^(?P<articulo_id>\d+)/$', 'articulo'), + url(r'^nuevo/$', 'nuevo'), + url(r'^(?P<articulo_id>\d+)/crear_comentario/$', 'crear_comentario'), ) diff --git a/blog/views.py b/blog/views.py index ac56d21..182905b 100644 --- a/blog/views.py +++ b/blog/views.py @@ -1,15 +1,17 @@ -from elgarito.blog.models import Articulo, ArticuloForm, Comentario, ComentarioForm +from blog.models import Articulo, ArticuloForm, Comentario, ComentarioForm from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.http import HttpResponseRedirect from django.contrib.auth.decorators import user_passes_test + def index(request): lista_articulos = Articulo.objects.all() return render_to_response('blog/index.html', RequestContext(request, { 'lista_articulos': lista_articulos})) + def articulo(request, articulo_id): articulo = get_object_or_404(Articulo, pk=articulo_id) lista_comentarios = Comentario.objects.filter(articulo__pk=articulo_id) @@ -21,27 +23,29 @@ def articulo(request, articulo_id): 'form': form, 'user': request.user})) + @user_passes_test(lambda u: u.has_perm('blog.can_add_comentario'), login_url='/usuarios/login/') def crear_comentario(request, articulo_id): articulo = get_object_or_404(Articulo, pk=articulo_id) comentario = Comentario(id=None, - texto = request.POST['texto'], - autor = request.user, - articulo = articulo, - ) + texto=request.POST['texto'], + autor=request.user, + articulo=articulo, + ) comentario.save() return HttpResponseRedirect('/blog/%s/' % articulo_id) + @user_passes_test(lambda u: u.has_perm('blog.can_add_articulo'), login_url='/usuarios/login/') def nuevo(request): if request.POST: articulo = Articulo(id=None, - titulo = request.POST['titulo'], - texto = request.POST['texto'], - autor = request.user, - ) + titulo=request.POST['titulo'], + texto=request.POST['texto'], + autor=request.user, + ) articulo.save() return HttpResponseRedirect('/blog/%s/' % articulo.id) else: |