From 2b81726dec956364491e069c0e8180fbdae7ee62 Mon Sep 17 00:00:00 2001 From: "theodore.therone@gmail.com" Date: Tue, 14 Oct 2014 01:31:53 +0000 Subject: [PATCH] Adds delete option, fixes #37 --- notifications/urls.py | 1 + notifications/views.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/notifications/urls.py b/notifications/urls.py index 9b867c2..ad36edb 100644 --- a/notifications/urls.py +++ b/notifications/urls.py @@ -8,4 +8,5 @@ urlpatterns = patterns('notifications.views', url(r'^mark-all-as-read/$', 'mark_all_as_read', name='mark_all_as_read'), url(r'^mark-as-read/(?P\d+)/$', 'mark_as_read', name='mark_as_read'), url(r'^mark-as-unread/(?P\d+)/$', 'mark_as_unread', name='mark_as_unread'), + url(r'^delete/(?P\d+)/$', 'delete', name='delete'), ) diff --git a/notifications/views.py b/notifications/views.py index d714798..f9fbb2e 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -27,7 +27,7 @@ def all(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. action_list = paginator.page(paginator.num_pages) - + return render_to_response('notifications/list.html', { 'member': request.user, 'action_list': action_list, @@ -38,10 +38,15 @@ def unread(request): return render(request, 'notifications/list.html', { 'notifications': request.user.notifications.unread() }) - + @login_required def mark_all_as_read(request): request.user.notifications.mark_all_as_read() + + next = request.REQUEST.get('next') + + if next: + return redirect(next) return redirect('notifications:all') @login_required @@ -71,3 +76,17 @@ def mark_as_unread(request, slug=None): return redirect(next) return redirect('notifications:all') + +@login_required +def delete(request, slug=None): + id = slug2id(slug) + + notification = get_object_or_404(Notification, recipient=request.user, id=id) + notification.delete() + + next = request.REQUEST.get('next') + + if next: + return redirect(next) + + return redirect('notifications:all')