Skip to content

Commit

Permalink
pluggable-backends: Implemented backend loading from settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner committed May 31, 2008
1 parent b997164 commit 3df0787
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions notification/backends/__init__.py
@@ -1,2 +1,19 @@


from django.conf import settings
from django.core import exceptions

from base import BaseBackend from base import BaseBackend

def load_backends():
backends = []
for label, backend_path in getattr(settings, "NOTIFICATION_BACKENDS", tuple()):
dot = backend_path.rindex('.')
backend_mod, backend_class = backend_path[:dot], backend_path[dot+1:]
try:
mod = __import__(backend_mod, {}, {}, [""])
except ImportError, e:
raise exceptions.ImproperlyConfigured, 'Error importing notification backend %s: "%s"' % (backend_mod, e)
# add the backend label and an instaniated backend class to the
# backends list.
backends.append(label, getattr(backend_mod, "")())
return dict(backend_list)
11 changes: 8 additions & 3 deletions notification/models.py
Expand Up @@ -11,6 +11,8 @@
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext from django.utils.translation import ugettext


from notification import backends



class NoticeType(models.Model): class NoticeType(models.Model):


Expand All @@ -31,12 +33,13 @@ class Meta:
verbose_name = _("notice type") verbose_name = _("notice type")
verbose_name_plural = _("notice types") verbose_name_plural = _("notice types")


# if this gets updated, the create() method below needs to be as well... NOTIFICATION_BACKENDS = backends.load_backends()
NOTICE_MEDIA = ( NOTICE_MEDIA = tuple(
("1", _("Email")), ((i, backend_label) for i, backend_label in enumerate(NOTIFICATION_BACKENDS.keys()))
) )


# how spam-sensitive is the medium # how spam-sensitive is the medium
# TODO: fix this with the backends
NOTICE_MEDIA_DEFAULTS = { NOTICE_MEDIA_DEFAULTS = {
"1": 2 # email "1": 2 # email
} }
Expand Down Expand Up @@ -244,6 +247,8 @@ def send(users, notice_type_label, message_template, object_list=None, issue_not
This is intended to be how other apps create new notices. This is intended to be how other apps create new notices.
""" """
backends = NOTIFICATION_BACKENDS.values()

notice_type = NoticeType.objects.get(label=notice_type_label) notice_type = NoticeType.objects.get(label=notice_type_label)
message = encode_message(message_template, object_list) message = encode_message(message_template, object_list)


Expand Down

0 comments on commit 3df0787

Please sign in to comment.