Permalink
Browse files

Added mark_all_seen view that marks all unseen notices as seen. Also …

…improved NoticeManager.notices_for method by adding a unseen parameter.

git-svn-id: https://django-notification.googlecode.com/svn/trunk@80 590c3fc9-4838-0410-bb95-17a0c9b37ca9
  • Loading branch information...
1 parent d63d0fc commit 49c0cb691400363be6bfc229f2b3d5b27e5b3a2c @brosner brosner committed Jul 11, 2008
Showing with 21 additions and 5 deletions.
  1. +10 −3 notification/models.py
  2. +2 −1 notification/urls.py
  3. +9 −1 notification/views.py
View
@@ -85,17 +85,24 @@ def should_send(user, notice_type, medium):
class NoticeManager(models.Manager):
- def notices_for(self, user, archived=False):
+ def notices_for(self, user, archived=False, unseen=None):
"""
returns Notice objects for the given user.
If archived=False, it only include notices not archived.
If archived=True, it returns all notices for that user.
+
+ If unseen=None, it includes all notices.
+ If unseen=True, return only unseen notices.
+ If unseen=False, return only seen notices.
"""
if archived:
- return self.filter(user=user)
+ qs = self.filter(user=user)
else:
- return self.filter(user=user, archived=archived)
+ qs = self.filter(user=user, archived=archived)
+ if unseen is not None:
+ qs = qs.filter(unseen=unseen)
+ return qs
def unseen_count_for(self, user):
"""
View
@@ -2,8 +2,9 @@
# @@@ from atom import Feed
-from notification.views import notices
+from notification.views import notices, mark_all_seen
urlpatterns = patterns('',
url(r'^$', notices, name="notification_notices"),
+ url(r'^mark_all_seen/$', mark_all_seen, name="notification_mark_all_seen"),
)
View
@@ -61,4 +61,12 @@ def delete(request, noticeid=None, next_page=None):
return HttpResponseRedirect(next_page)
except Notice.DoesNotExist:
return HttpResponseRedirect(next_page)
- return HttpResponseRedirect(next_page)
+ return HttpResponseRedirect(next_page)
+
+@login_required
+def mark_all_seen(request):
+ for notice in Notice.objects.notices_for(request.user, unseen=True):
+ notice.unseen = False
+ notice.save()
+ return HttpResponseRedirect(reverse("notification_notices"))
+

0 comments on commit 49c0cb6

Please sign in to comment.