Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added received and sent methods taking a User instance to Notice.objects

  • Loading branch information...
commit 9f2aa6d986e7bba1dab162a8287b8b937daa9a83 1 parent 57f4da8
@brosner brosner authored
Showing with 24 additions and 6 deletions.
  1. +1 −0  CHANGELOG
  2. +23 −6 notification/models.py
View
1  CHANGELOG
@@ -3,6 +3,7 @@ BI = backward incompatible change
0.2.0
-----
+ * added received and sent methods taking a User instance to Notice.objects
* BI: added nullable Notice.sender and modified send_now and queue to take
an optional sender
* BI: renamed Notice.user to Notice.recipient
View
29 notification/models.py
@@ -93,7 +93,7 @@ def should_send(user, notice_type, medium):
class NoticeManager(models.Manager):
- def notices_for(self, user, archived=False, unseen=None, on_site=None):
+ def notices_for(self, user, archived=False, unseen=None, on_site=None, sent=False):
"""
returns Notice objects for the given user.
@@ -104,22 +104,39 @@ def notices_for(self, user, archived=False, unseen=None, on_site=None):
If unseen=True, return only unseen notices.
If unseen=False, return only seen notices.
"""
- if archived:
- qs = self.filter(user=user)
+ if sent:
+ lookup_kwargs = {"sender": user}
else:
- qs = self.filter(user=user, archived=archived)
+ lookup_kwargs = {"recipient": user}
+ qs = self.filter(**lookup_kwargs)
+ if not archived:
+ self.filter(archived=archived)
if unseen is not None:
qs = qs.filter(unseen=unseen)
if on_site is not None:
qs = qs.filter(on_site=on_site)
return qs
- def unseen_count_for(self, user, **kwargs):
+ def unseen_count_for(self, recipient, **kwargs):
"""
returns the number of unseen notices for the given user but does not
mark them seen
"""
- return self.notices_for(user, unseen=True, **kwargs).count()
+ return self.notices_for(recipient, unseen=True, **kwargs).count()
+
+ def received(self, recipient, **kwargs):
+ """
+ returns notices the given recipient has recieved.
+ """
+ kwargs["sent"] = False
+ return self.notices_for(recipient, **kwargs)
+
+ def sent(self, sender, **kwargs):
+ """
+ returns notices the given sender has sent
+ """
+ kwargs["sent"] = True
+ return self.notices_for(sender, **kwargs)
class Notice(models.Model):
Please sign in to comment.
Something went wrong with that request. Please try again.