Skip to content

Commit

Permalink
Removed issue_notice flag and replaced with on_site flag. This is bac…
Browse files Browse the repository at this point in the history
…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
brosner committed Sep 13, 2008
1 parent 3aaccc8 commit ab07342
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand All @@ -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()

Expand Down Expand Up @@ -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.
Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion notification/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit ab07342

Please sign in to comment.