diff --git a/multimail/__init__.py b/multimail/__init__.py index 20300c7..f91cddb 100644 --- a/multimail/__init__.py +++ b/multimail/__init__.py @@ -2,9 +2,11 @@ .. moduleauthor:: Scott B. Bradley , Twitter <@scott2b> """ -__version__ = '0.1.3' +__version__ = '0.1.4' __license__ = 'OSI Approved :: MIT License' __author__ = 'scott2b ' __email__ = 'scott@scott2b.com' __url__ = 'http://django-multimail.com' + +default_app_config = 'multimail.models.MultimailConfig' diff --git a/multimail/models.py b/multimail/models.py index 0f40b0b..8177d95 100644 --- a/multimail/models.py +++ b/multimail/models.py @@ -10,11 +10,11 @@ from django.template.loader import get_template from multimail.settings import MM from multimail.util import build_context_dict + try: - USER_MODEL = settings.AUTH_USER_MODEL + USER_MODEL_STRING = settings.AUTH_USER_MODEL except AttributeError: # handle Django 1.4 - from django.contrib.auth.models import User - USER_MODEL = User + USER_MODEL_STRING = 'auth.User' try: from django.utils import timezone @@ -23,13 +23,14 @@ import datetime now = lambda: datetime.datetime.now() + class EmailAddress(models.Model): """An e-mail address for a Django User. Users may have more than one e-mail address. The address that is on the user object itself as the email property is considered to be the primary address, for which there should also be an EmailAddress object associated with the user. """ - user = models.ForeignKey(USER_MODEL) + user = models.ForeignKey(USER_MODEL_STRING) email = models.EmailField(max_length=100, unique=True) created_at = models.DateTimeField(auto_now_add=True) verif_key = models.CharField(max_length=40) @@ -183,7 +184,6 @@ def email_address_handler(sender, **kwargs): subj = "Failed attempt to create Multimail email address." if MM.EMAIL_ADMINS: mail_admins(subj, msg) -post_save.connect(email_address_handler, sender=USER_MODEL) def user_deactivation_handler(sender, **kwargs): @@ -196,5 +196,29 @@ def user_deactivation_handler(sender, **kwargs): if not email.is_verified(): email.delete() -if MM.USER_DEACTIVATION_HANDLER_ON: - post_save.connect(user_deactivation_handler, sender=USER_MODEL) + +def setup_signals(user_model): + post_save.connect(email_address_handler, sender=user_model) + if MM.USER_DEACTIVATION_HANDLER_ON: + post_save.connect(user_deactivation_handler, sender=user_model) + +try: + from django.apps import AppConfig +except ImportError: # Handle Django < 1.7 + AppConfig = object + try: + from django.contrib.auth import get_user_model + setup_signals(get_user_model()) + except ImportError: # Handle Django 1.4 + from django.contrib.auth.models import User + setup_signals(User) + + +class MultimailConfig(AppConfig): + """For Django 1.7, set the ready callback for handling User object + signal configuration.""" + name = 'multimail' + + def ready(self): + from django.contrib.auth import get_user_model + setup_signals(get_user_model())