Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Fixes signal configuration; Handles non-custom user model in Django 1…
Browse files Browse the repository at this point in the history
….4; Handles 1.7 changes to model configuration via the AppConfig class. Bumps multimail version to 0.1.4
  • Loading branch information
Scott Bradley committed Dec 1, 2014
1 parent 9d2aa5a commit c220d0f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
4 changes: 3 additions & 1 deletion multimail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
.. moduleauthor:: Scott B. Bradley <scott@scott2b.com>, Twitter <@scott2b>
"""
__version__ = '0.1.3'
__version__ = '0.1.4'
__license__ = 'OSI Approved :: MIT License'

__author__ = 'scott2b <Scott B. Bradley>'
__email__ = 'scott@scott2b.com'
__url__ = 'http://django-multimail.com'

default_app_config = 'multimail.models.MultimailConfig'
38 changes: 31 additions & 7 deletions multimail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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())

0 comments on commit c220d0f

Please sign in to comment.