Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed issue_notice flag and replaced with on_site flag. This is bac…

…kward

incompatible in that SQL migration is needed and the keyword argument changed.
Its default value is the same. Due to the backward incompatible change here,
the recipient argument name changed to users. That is backward incompatible if
you relied on the old name.

git-svn-id: https://django-notification.googlecode.com/svn/trunk@96 590c3fc9-4838-0410-bb95-17a0c9b37ca9
  • Loading branch information...
commit ab0734221f98438dc8e4b21f85047359fd7ff874 1 parent 3aaccc8
@brosner brosner authored
Showing with 12 additions and 6 deletions.
  1. +11 −5 notification/models.py
  2. +1 −1  notification/views.py
View
16 notification/models.py
@@ -82,7 +82,7 @@ def should_send(user, notice_type, medium):
class NoticeManager(models.Manager):
- def notices_for(self, user, archived=False, unseen=None):
+ def notices_for(self, user, archived=False, unseen=None, on_site=None):
"""
returns Notice objects for the given user.
@@ -99,6 +99,8 @@ def notices_for(self, user, archived=False, unseen=None):
qs = self.filter(user=user, 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):
@@ -116,6 +118,7 @@ class Notice(models.Model):
added = models.DateTimeField(_('added'), default=datetime.datetime.now)
unseen = models.BooleanField(_('unseen'), default=True)
archived = models.BooleanField(_('archived'), default=False)
+ on_site = models.BooleanField(_('on site'))
objects = NoticeManager()
@@ -186,7 +189,7 @@ def get_formatted_messages(formats, label, context):
'notification/%s' % format), context)
return format_templates
-def send(recipient, label, extra_context={}, issue_notice=True):
+def send(users, label, extra_context={}, on_site=True):
"""
Creates a new notice.
@@ -196,6 +199,9 @@ def send(recipient, label, extra_context={}, issue_notice=True):
'spam': 'eggs',
'foo': 'bar',
)
+
+ You can pass in on_site=False to prevent the notice emitted from being
+ displayed on the site.
"""
notice_type = NoticeType.objects.get(label=label)
@@ -214,7 +220,7 @@ def send(recipient, label, extra_context={}, issue_notice=True):
'full.html',
) # TODO make formats configurable
- for user in recipient:
+ for user in users:
recipients = []
# get user profiles if available
try:
@@ -251,8 +257,8 @@ def send(recipient, label, extra_context={}, issue_notice=True):
'message': messages['plain'],
}, context)
- if issue_notice:
- notice = Notice.objects.create(user=user, message=messages['teaser'], notice_type=notice_type)
+ notice = Notice.objects.create(user=user, message=messages['teaser'],
+ notice_type=notice_type, on_site=on_site)
if should_send(user, notice_type, "1") and user.email: # Email
recipients.append(user.email)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
View
2  notification/views.py
@@ -19,7 +19,7 @@ def feed_for_user(request):
@login_required
def notices(request):
notice_types = NoticeType.objects.all()
- notices = Notice.objects.notices_for(request.user)
+ notices = Notice.objects.notices_for(request.user, on_site=True)
settings_table = []
for notice_type in NoticeType.objects.all():
settings_row = []
Please sign in to comment.
Something went wrong with that request. Please try again.