Author: leidel
Date: Wed Jan 21 01:27:18 2009
New Revision: 90
Modified:
trunk/messages/forms.py
trunk/messages/management.py
trunk/messages/models.py
trunk/messages/utils.py
trunk/messages/views.py
Log:
Prevent probable circular imports when using Django's app cache
Modified: trunk/messages/forms.py
==============================================================================
--- trunk/messages/forms.py (original)
+++ trunk/messages/forms.py Wed Jan 21 01:27:18 2009
@@ -3,15 +3,12 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_noop
-from django.db.models import get_app
-from django.core.exceptions import ImproperlyConfigured
from django.contrib.auth.models import User
-try:
- notification = get_app('notification')
-except ImproperlyConfigured:
+if "notification" in settings.INSTALLED_APPS:
+ from notification import models as notification
+else:
notification = None
-
from messages.models import Message
from messages.fields import CommaSeparatedUserField
Modified: trunk/messages/management.py
==============================================================================
--- trunk/messages/management.py (original)
+++ trunk/messages/management.py Wed Jan 21 01:27:18 2009
@@ -1,11 +1,10 @@
-from django.db.models import get_models, signals, get_app
+from django.db.models import get_models, signals
from django.conf import settings
from django.utils.translation import ugettext_noop as _
-from django.core.exceptions import ImproperlyConfigured
-try:
- notification = get_app('notification')
-
+if "notification" in settings.INSTALLED_APPS:
+ from notification import models as notification
+
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("messages_received", _("Message
Received"), _("you have received a message"), default=2)
notification.create_notice_type("messages_sent", _("Message
Sent"), _("you have sent a message"), default=1)
@@ -13,7 +12,7 @@
notification.create_notice_type("messages_reply_received",
_("Reply Received"), _("you have received a reply to a message"), default=2)
notification.create_notice_type("messages_deleted", _("Message
Deleted"), _("you have deleted a message"), default=1)
notification.create_notice_type("messages_recovered", _("Message
Recovered"), _("you have undelete a message"), default=1)
-
+
signals.post_syncdb.connect(create_notice_types, sender=notification)
-except ImproperlyConfigured:
+else:
print "Skipping creation of NoticeTypes as notification app not found"
Modified: trunk/messages/models.py
==============================================================================
--- trunk/messages/models.py (original)
+++ trunk/messages/models.py Wed Jan 21 01:27:18 2009
@@ -1,9 +1,8 @@
import datetime
from django.db import models
from django.conf import settings
-from django.db.models import signals, get_app
+from django.db.models import signals
from django.db.models.query import QuerySet
-from django.core.exceptions import ImproperlyConfigured
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
@@ -97,8 +96,6 @@
return Message.objects.filter(recipient=user, read_at__isnull=True,
recipient_deleted_at__isnull=True).count()
# fallback for email notification if django-notification could not be found
-try:
- notification = get_app('notification')
-except ImproperlyConfigured:
+if "notification" not in settings.INSTALLED_APPS:
from messages.utils import new_message_email
signals.post_save.connect(new_message_email, sender=Message)
Modified: trunk/messages/utils.py
==============================================================================
--- trunk/messages/utils.py (original)
+++ trunk/messages/utils.py Wed Jan 21 01:27:18 2009
@@ -4,14 +4,12 @@
from django.template import Context, loader
from django.template.loader import render_to_string
from django.conf import settings
-from django.db.models import get_app
-from django.core.exceptions import ImproperlyConfigured
# favour django-mailer but fall back to django.core.mail
-try:
- mailer = get_app("mailer")
+
+if "mailer" in settings.INSTALLED_APPS:
from mailer import send_mail
-except ImproperlyConfigured:
+else:
from django.core.mail import send_mail
def format_quote(text):
Modified: trunk/messages/views.py
==============================================================================
--- trunk/messages/views.py (original)
+++ trunk/messages/views.py Wed Jan 21 01:27:18 2009
@@ -7,18 +7,16 @@
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_noop
from django.core.urlresolvers import reverse
-from django.core.exceptions import ImproperlyConfigured
-from django.db.models import get_app
+from django.conf import settings
from messages.models import Message
from messages.forms import ComposeForm
from messages.utils import format_quote
-try:
- notification = get_app('notification')
-except ImproperlyConfigured:
+if "notification" in settings.INSTALLED_APPS:
+ from notification import models as notification
+else:
notification = None
-
def inbox(request, template_name='messages/inbox.html'):
"""
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---