summaryrefslogtreecommitdiff
path: root/news/views.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-20 16:10:09 -0500
committerDan McGee <dan@archlinux.org>2010-09-21 09:10:02 -0500
commit41dc37c8126f062257ce7d5fc8fcf84286b55a88 (patch)
treec73e8f661ffb68d036f528257148243036b28a82 /news/views.py
parent7c92ddbd3c86d6aaa34abd4b2d3f12775801b50b (diff)
Update news views to use slug instead of ID
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'news/views.py')
-rw-r--r--news/views.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/news/views.py b/news/views.py
index d7148d5b..7fa92c8a 100644
--- a/news/views.py
+++ b/news/views.py
@@ -1,7 +1,7 @@
from django import forms
from django.contrib.auth.decorators import permission_required
from django.http import HttpResponse
-from django.shortcuts import redirect
+from django.shortcuts import get_object_or_404, redirect
from django.views.decorators.cache import never_cache
from django.views.generic import list_detail, create_update
from django.views.generic.simple import direct_to_template
@@ -10,8 +10,13 @@ import markdown
from .models import News
-def view(request, newsid):
- return list_detail.object_detail(request, News.objects.all(), newsid,
+def view_redirect(request, object_id):
+ newsitem = get_object_or_404(News, pk=object_id)
+ return redirect(newsitem, permanent=True)
+
+def view(request, slug=None):
+ return list_detail.object_detail(request, News.objects.all(),
+ slug=slug,
template_name="news/view.html",
template_object_name='news')
@@ -44,19 +49,19 @@ def add(request):
@permission_required('news.delete_news')
@never_cache
-def delete(request, newsid):
+def delete(request, slug):
return create_update.delete_object(request,
News,
- object_id=newsid,
+ slug=slug,
post_delete_redirect='/news/',
template_name='news/delete.html',
template_object_name='news')
@permission_required('news.change_news')
@never_cache
-def edit(request, newsid):
+def edit(request, slug):
return create_update.update_object(request,
- object_id=newsid,
+ slug=slug,
form_class=NewsForm,
template_name="news/add.html")