Commit 4800d5b6 by benjaoming

Decorator for muting notifications + Issue #11 fix

parent 2eae064d
...@@ -4,6 +4,8 @@ from django.utils.translation import ugettext as _ ...@@ -4,6 +4,8 @@ from django.utils.translation import ugettext as _
import models import models
_disable_notifications = False
def notify(message, key, target_object=None, url=None): def notify(message, key, target_object=None, url=None):
""" """
Notify subscribing users of a new event. Key can be any kind of string, Notify subscribing users of a new event. Key can be any kind of string,
...@@ -22,6 +24,9 @@ def notify(message, key, target_object=None, url=None): ...@@ -22,6 +24,9 @@ def notify(message, key, target_object=None, url=None):
""" """
if _disable_notifications:
return 0
if target_object: if target_object:
if not isinstance(target_object, Model): if not isinstance(target_object, Model):
raise TypeError(_(u"You supplied a target_object that's not an instance of a django Model.")) raise TypeError(_(u"You supplied a target_object that's not an instance of a django Model."))
......
...@@ -3,6 +3,17 @@ from django.utils import simplejson as json ...@@ -3,6 +3,17 @@ from django.utils import simplejson as json
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
import django_notify
def disable_notify(func):
"""Disable notifications within a """
def wrap(request, *args, **kwargs):
django_notify._disable_notifications = True
response = func(request, *args, **kwargs)
django_notify._disable_notifications = False
return response
return wrap
def login_required_ajax(func): def login_required_ajax(func):
"""Similar to login_required. But if the request is an ajax request, then """Similar to login_required. But if the request is an ajax request, then
it returns an error in json with a 403 status code.""" it returns an error in json with a 403 status code."""
...@@ -25,3 +36,4 @@ def json_view(func): ...@@ -25,3 +36,4 @@ def json_view(func):
response.write(data) response.write(data)
return response return response
return wrap return wrap
...@@ -22,7 +22,7 @@ class NotificationType(models.Model): ...@@ -22,7 +22,7 @@ class NotificationType(models.Model):
return self.key return self.key
class Meta: class Meta:
db_tablespace = settings.DB_TABLESPACE db_table = settings.DB_TABLE_PREFIX + '_notificationtype'
verbose_name = _(u'type') verbose_name = _(u'type')
verbose_name_plural = _(u'types') verbose_name_plural = _(u'types')
...@@ -36,7 +36,7 @@ class Settings(models.Model): ...@@ -36,7 +36,7 @@ class Settings(models.Model):
return _(u"Settings for %s") % self.user.username return _(u"Settings for %s") % self.user.username
class Meta: class Meta:
db_tablespace = settings.DB_TABLESPACE db_table = settings.DB_TABLE_PREFIX + '_settings'
verbose_name = _(u'settings') verbose_name = _(u'settings')
verbose_name_plural = _(u'settings') verbose_name_plural = _(u'settings')
...@@ -52,7 +52,7 @@ class Subscription(models.Model): ...@@ -52,7 +52,7 @@ class Subscription(models.Model):
return _("Subscription for: %s") % str(self.settings.user.username) return _("Subscription for: %s") % str(self.settings.user.username)
class Meta: class Meta:
db_tablespace = settings.DB_TABLESPACE db_table = settings.DB_TABLE_PREFIX + '_subscription'
verbose_name = _(u'subscription') verbose_name = _(u'subscription')
verbose_name_plural = _(u'subscriptions') verbose_name_plural = _(u'subscriptions')
...@@ -97,6 +97,6 @@ class Notification(models.Model): ...@@ -97,6 +97,6 @@ class Notification(models.Model):
return "%s: %s" % (str(self.subscription.settings.user), self.message) return "%s: %s" % (str(self.subscription.settings.user), self.message)
class Meta: class Meta:
db_tablespace = settings.DB_TABLESPACE db_table = settings.DB_TABLE_PREFIX + '_notification'
verbose_name = _(u'notification') verbose_name = _(u'notification')
verbose_name_plural = _(u'notifications') verbose_name_plural = _(u'notifications')
...@@ -2,8 +2,7 @@ from django.conf import settings as django_settings ...@@ -2,8 +2,7 @@ from django.conf import settings as django_settings
_ = lambda x: x _ = lambda x: x
# don't change this :) DB_TABLE_PREFIX = 'notify'
DB_TABLESPACE = 'notify'
# You need to switch this setting on, otherwise nothing will happen :) # You need to switch this setting on, otherwise nothing will happen :)
ENABLED = getattr(django_settings, "NOTIFY_ENABLED", True) ENABLED = getattr(django_settings, "NOTIFY_ENABLED", True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment