diff --git a/notification/backends/base.py b/notification/backends/base.py index 9c3a1142..b597abb4 100644 --- a/notification/backends/base.py +++ b/notification/backends/base.py @@ -57,12 +57,16 @@ def default_context(self): }) def get_target_url(self, extra_context, sender, recipient): - target_url = extra_context['target'].url if 'target' in extra_context and hasattr(extra_context['target'], - 'url') else sender.get_absolute_url() - if 'target' in extra_context and recipient == extra_context['target']: - target_url = sender.get_absolute_url() - if 'pm_message' in extra_context: - target_url = extra_context['pm_message'].get_absolute_url() + target = getattr(extra_context, 'target', None) + target_url = getattr(target, 'url', None) + pm_message = getattr(extra_context, 'pm_message', None) + + alternate_url_source = pm_message + if not target_url or target and recipient == target: + alternate_url_source = sender + + if hasattr(alternate_url_source, 'get_absolute_url'): + target_url = alternate_url_source.get_absolute_url() if hasattr(target_url, '__call__'): target_url = target_url() diff --git a/notification/backends/email.py b/notification/backends/email.py index dc30ed75..d8af5993 100644 --- a/notification/backends/email.py +++ b/notification/backends/email.py @@ -41,7 +41,7 @@ def deliver(self, recipient, sender, notice_type, extra_context): "recipient": recipient, "sender": sender, "notice": ugettext(notice_type.past_tense), - 'default_profile_photo': settings.DEFAULT_PROFILE_PHOTO, + 'default_profile_photo': getattr(settings, 'DEFAULT_PROFILE_PHOTO', None), 'target_url': target_url, }) context.update(extra_context) diff --git a/notification/backends/onsite.py b/notification/backends/onsite.py index 648829b4..f25b6d6e 100644 --- a/notification/backends/onsite.py +++ b/notification/backends/onsite.py @@ -31,7 +31,7 @@ def deliver(self, recipient, sender, notice_type, extra_context): "recipient": recipient, "sender": sender, "notice": ugettext(notice_type.past_tense), - 'default_profile_photo': settings.DEFAULT_PROFILE_PHOTO, + 'default_profile_photo': getattr(settings, 'DEFAULT_PROFILE_PHOTO', None), 'target_url': target_url, }) context.update(extra_context) diff --git a/notification/models.py b/notification/models.py index d0d1a9be..1bc893b6 100644 --- a/notification/models.py +++ b/notification/models.py @@ -61,12 +61,14 @@ class Meta: verbose_name_plural = _("notice types") @classmethod - def create(cls, label, display, past_tense, description, default=2, verbosity=1): + def create(cls, label, display, description, past_tense=None, default=2, verbosity=1): """ Creates a new NoticeType. This is intended to be used by other apps as a post_syncdb manangement step. """ + if not past_tense: + past_tense = display try: notice_type = cls._default_manager.get(label=label) updated = False