mirror of
https://github.com/Hopiu/django-notifications.git
synced 2026-05-09 13:54:44 +00:00
Adds delete option, fixes #37
This commit is contained in:
parent
e0c7c75349
commit
2b81726dec
2 changed files with 22 additions and 2 deletions
|
|
@ -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<slug>\d+)/$', 'mark_as_read', name='mark_as_read'),
|
||||
url(r'^mark-as-unread/(?P<slug>\d+)/$', 'mark_as_unread', name='mark_as_unread'),
|
||||
url(r'^delete/(?P<slug>\d+)/$', 'delete', name='delete'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue