Author: leidel
Date: Wed Jan 21 00:50:58 2009
New Revision: 138
Modified:
trunk/docs/usage.txt
trunk/notification/models.py
Log:
Fixes issue 25 - importing notification broken. Uses simple check for
existance in settings.INSTALLED_APPS.
Modified: trunk/docs/usage.txt
==============================================================================
--- trunk/docs/usage.txt (original)
+++ trunk/docs/usage.txt Wed Jan 21 00:50:58 2009
@@ -26,22 +26,21 @@
``management.py`` file for your app, attached to the syncdb signal.
Here is an example::
- from django.db.models import signals, get_app
- from django.core.exceptions import ImproperlyConfigured
+ from django.conf import settings
- try:
- notification = get_app("notification")
+ if "notification" in settings.INSTALLED_APPS:
+ from notification.models import create_notice_type
def create_notice_types(app, created_models, verbosity, **kwargs):
- notification.create_notice_type("friends_invite", "Invitation
Received", "you have received an invitation")
- notification.create_notice_type("friends_accept", "Acceptance
Received", "an invitation you sent has been accepted")
+ create_notice_type("friends_invite", "Invitation
Received", "you have received an invitation")
+ create_notice_type("friends_accept", "Acceptance
Received", "an invitation you sent has been accepted")
signals.post_syncdb.connect(create_notice_types,
sender=notification)
- except ImproperlyConfigured:
+ else:
print "Skipping creation of NoticeTypes as notification app not
found"
-Notice that the code is wrapped in a try clause so if django-notification
is
-not installed, your app will proceed anyway.
+Notice that the code is wrapped in a conditional claus so if
+django-notification is not installed, your app will proceed anyway.
Notification templates
@@ -130,17 +129,17 @@
Optional notification support
-----------------------------
-To allow your app to still function without notification, you can wrap your
-import in a try clause and test that the module has been loaded before
sending
-a notice.
+In case you want to use django-notification in your reusable app, you can
+wrap the import of django-notification in a conditional clause that tests
+if it's installed before sending a notice. As a result your app or
+project still functions without notification.
For example::
- from django.db.models import get_app
- from django.core.exceptions import ImproperlyConfigured
+ from django.conf import settings
- try:
- notification = get_app('notification')
+ if "notification" in settings.INSTALLED_APPS:
+ from notification import models as notification
except ImproperlyConfigured:
notification = None
Modified: trunk/notification/models.py
==============================================================================
--- trunk/notification/models.py (original)
+++ trunk/notification/models.py Wed Jan 21 00:50:58 2009
@@ -25,10 +25,9 @@
from django.utils.translation import ugettext, get_language, activate
# favour django-mailer but fall back to django.core.mail
-try:
- mailer = models.get_app("mailer")
+if 'mailer' in settings.INSTALLED_APPS
from mailer import send_mail
-except ImproperlyConfigured:
+else:
from django.core.mail import send_mail
QUEUE_ALL = getattr(settings, "NOTIFICATION_QUEUE_ALL", False)
@@ -159,9 +158,9 @@
verbose_name = _("notice")
verbose_name_plural = _("notices")
- @models.permalink
def get_absolute_url(self):
return ("notification_notice", [str(self.pk)])
+ get_absolute_url = models.permalink(get_absolute_url)
class NoticeQueueBatch(models.Model):
"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---