def send_now(users, label, extra_context=None, on_site=None, sender=None, related_object_id=None): """ Creates a new notice. This is intended to be how other apps create new notices. notification.send(user, "friends_invite_sent", { "spam": "eggs", "foo": "bar", ) You can pass in on_site=False to prevent the notice emitted from being displayed on the site. """ if extra_context is None: extra_context = {} notice_type = NoticeType.objects.get(label=label) protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http") current_site = Site.objects.get_current() current_language = get_language() for user in users: # get user language for user from language store defined in # NOTIFICATION_LANGUAGE_MODULE setting try: language = get_notification_language(user) except LanguageStoreNotAvailable: language = None if language is not None: # activate the user's language activate(language) # update context with user specific translations context = Context({ "recipient": user, "sender": sender, "notice": ugettext(notice_type.display), "current_site": current_site, }) context.update(extra_context) messages = get_formatted_message( ['notice.html'], notice_type, context, 'notice') notice_setting = get_notification_setting(user, notice_type, 'email') if on_site is None: on_site = notice_setting.on_site notice = Notice.objects.create( recipient=user, message=messages['notice.html'], notice_type=notice_type, on_site=on_site, sender=sender, related_object_id=related_object_id) for backend in get_backends(): send_user_notification(user, notice_type, backend, context) # reset environment to original language activate(current_language)
def next(self): self.index += 1 try: item = get_backends()[self.index] except IndexError: raise StopIteration else: return (item.slug, item.title)
def next(self): self.index += 1 if self.index == 0: return ('on_site', "On Site") try: item = get_backends()[self.index - 1] return (item.slug, item.title) except IndexError: raise StopIteration
def next(self): self.index += 1 if self.index == 0: return ('on_site', "On Site") try: item = get_backends()[self.index-1] return (item.slug, item.title) except IndexError: raise StopIteration
def send_now(users, label, extra_context=None, on_site=None, sender=None, related_object_id=None, backends=get_backends()): """ Creates a new notice. This is intended to be how other apps create new notices. notification.send(user, "friends_invite_sent", { "spam": "eggs", "foo": "bar", ) You can pass in on_site=False to prevent the notice emitted from being displayed on the site. """ if extra_context is None: extra_context = {} notice_type = NoticeType.objects.get(label=label) protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http") current_site = Site.objects.get_current() current_language = get_language() for user in users: # get user language for user from language store defined in # NOTIFICATION_LANGUAGE_MODULE setting try: language = get_notification_language(user) except LanguageStoreNotAvailable: language = None if language is not None: # activate the user's language activate(language) # update context with user specific translations context = Context({ "recipient": user, "sender": sender, "notice": ugettext(notice_type.display), "current_site": current_site, }) context.update(extra_context) messages = get_formatted_message(['notice.html'], notice_type, context, 'notice') notice_setting = get_notification_setting(user, notice_type, 'email') if on_site is None: on_site = notice_setting.on_site notice = Notice.objects.create(recipient=user, message=messages['notice.html'], notice_type=notice_type, on_site=on_site, sender=sender, related_object_id=related_object_id) if len(backends) > 0 and isinstance(backends[0], str): backends = get_backends(backends) for backend in backends: send_user_notification(user, notice_type, backend, context) # reset environment to original language activate(current_language)
def send_now(users, label, extra_context=None, on_site=True, sender=None): """ Creates a new notice. This is intended to be how other apps create new notices. notification.send(user, 'friends_invite_sent', { 'spam': 'eggs', 'foo': 'bar', ) You can pass in on_site=False to prevent the notice emitted from being displayed on the site. """ if extra_context is None: extra_context = {} notice_type = NoticeType.objects.get(label=label) protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http") current_site = Site.objects.get_current() notices_url = u"%s://%s%s" % ( protocol, unicode(current_site), reverse("notification_notices"), ) current_language = get_language() for user in users: # get user language for user from language store defined in # NOTIFICATION_LANGUAGE_MODULE setting try: language = get_notification_language(user) except LanguageStoreNotAvailable: language = None if language is not None: # activate the user's language activate(language) # update context with user specific translations context = Context({ "recipient": user, "sender": sender, "notice": ugettext(notice_type.display), "notices_url": notices_url, "current_site": current_site, }) context.update(extra_context) messages = get_formatted_messages(['notice.html'], notice_type, context, 'notice') notice = Notice.objects.create(recipient=user, message=messages['notice.html'], notice_type=notice_type, on_site=on_site, sender=sender) for backend in get_backends(): send_user_notification(user, notice_type, backend, context) # reset environment to original language activate(current_language)