Permalink
Browse files

Views for archive and delete Notice.

git-svn-id: https://django-notification.googlecode.com/svn/trunk@15 590c3fc9-4838-0410-bb95-17a0c9b37ca9
  • Loading branch information...
1 parent 6ddf778 commit fbdefe8dd63b1555976456774413d4c4b5ae2b34 jjconti committed May 23, 2008
Showing with 32 additions and 1 deletion.
  1. +32 −1 notification/views.py
View
33 notification/views.py
@@ -1,6 +1,9 @@
from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
from django.template import RequestContext
-from notification.models import notices_for, NoticeType
+from django.contrib.auth.decorators import login_required, permission_required
+
+from notification.models import *
def notices(request):
notice_types = NoticeType.objects.all()
@@ -12,3 +15,31 @@ def notices(request):
"notices": notices,
"notice_types": notice_types,
}, context_instance=RequestContext(request))
+
+@login_required
+def archive(request, noticeid=None, next_page=None):
+ if noticeid:
+ try:
+ notice = Notice.objects.get(id=noticeid)
+ if request.user == notice.user or request.user.is_superuser:
+ notice.archive()
+ else: # you can archive other users' notices
+ # only if you are superuser.
+ return HttpResponseRedirect(next_page)
+ except Notice.DoesNotExist:
+ return HttpResponseRedirect(next_page)
+ return HttpResponseRedirect(next_page)
+
+@login_required
+def delete(request, noticeid=None, next_page=None):
+ if noticeid:
+ try:
+ notice = Notice.objects.get(id=noticeid)
+ if request.user == notice.user or request.user.is_superuser:
+ notice.delete()
+ else: # you can delete other users' notices
+ # only if you are superuser.
+ return HttpResponseRedirect(next_page)
+ except Notice.DoesNotExist:
+ return HttpResponseRedirect(next_page)
+ return HttpResponseRedirect(next_page)

0 comments on commit fbdefe8

Please sign in to comment.