summaryrefslogtreecommitdiff
path: root/todolists
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-29 16:15:28 -0500
committerDan McGee <dan@archlinux.org>2011-04-07 17:03:33 -0500
commitd456ff32aa3255113eab9e9c83676660807514e8 (patch)
tree0bd606f768a5192a98c52a6b46fec82bb9fe5f75 /todolists
parentb2f7cd61e89c59bb52a542f6667aabd53743681c (diff)
Convert todolist delete to class-based view
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'todolists')
-rw-r--r--todolists/urls.py7
-rw-r--r--todolists/views.py14
2 files changed, 11 insertions, 10 deletions
diff --git a/todolists/urls.py b/todolists/urls.py
index 187d4820..8814d65e 100644
--- a/todolists/urls.py
+++ b/todolists/urls.py
@@ -1,4 +1,7 @@
from django.conf.urls.defaults import patterns
+from django.contrib.auth.decorators import permission_required
+
+from .views import DeleteTodolist
urlpatterns = patterns('todolists.views',
(r'^$', 'list'),
@@ -6,8 +9,8 @@ urlpatterns = patterns('todolists.views',
(r'^add/$', 'add'),
(r'^edit/(?P<list_id>\d+)/$', 'edit'),
(r'^flag/(\d+)/(\d+)/$', 'flag'),
- (r'^delete/(?P<object_id>\d+)/$',
- 'delete_todolist'),
+ (r'^delete/(?P<pk>\d+)/$',
+ permission_required('main.delete_todolist')(DeleteTodolist.as_view())),
)
# vim: set ts=4 sw=4 et:
diff --git a/todolists/views.py b/todolists/views.py
index 6bd456ae..a2029be0 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -7,7 +7,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.db import transaction
from django.db.models import Count
from django.views.decorators.cache import never_cache
-from django.views.generic.create_update import delete_object
+from django.views.generic import DeleteView
from django.views.generic.simple import direct_to_template
from django.template import Context, loader
from django.utils import simplejson
@@ -109,13 +109,11 @@ def edit(request, list_id):
}
return direct_to_template(request, 'general_form.html', page_dict)
-@permission_required('main.delete_todolist')
-@never_cache
-def delete_todolist(request, object_id):
- return delete_object(request, object_id=object_id, model=Todolist,
- template_name="todolists/todolist_confirm_delete.html",
- post_delete_redirect='/todo/')
-
+class DeleteTodolist(DeleteView):
+ model = Todolist
+ # model in main == assumes name 'main/todolist_confirm_delete.html'
+ template_name = 'todolists/todolist_confirm_delete.html'
+ success_url = '/todo/'
@transaction.commit_on_success
def create_todolist_packages(form, creator=None):