1

I’m trying to send email using django-notification. I have followed the documentation and created all the notice types, templates and management.py. However, when I attempt to send an email, I’m shown this debug page with the error: NoticeType matching query does not exist. Here’s some of the code.

In my management.py file:

from django.conf import settings
from django.db.models import signals
from django.utils.translation import ugettext_noop as _

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def create_notice_types(app, created_models, verbosity, **kwargs):
        notification.NoticeType.create("create_model", _("Model Creation"), _("An entry has been created"))
        notification.NoticeType.create("delete_model", _("Model Deletion"), _("An entry has been deleted"))
        notification.NoticeType.create("edit_model", _("Model Change"), _("An entry has been changed."))
    signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
    print "Skipping creation of NoticeTypes as notification app not found"

In my settings.py file:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'departments',
    'notification'
)

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = #not shown
EMAIL_PORT = 587
NOTIFICATION_BACKENDS = [("[email protected]", "notification.backends.email.EmailBackend"),]
#other code....

In my models.py file:

def model_create_edit(sender, **kwargs):
      instance = kwargs.get('instance')
      user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name
      if kwargs['created']:
            notification.send([user], "create_email", {'user':user, 'first':first_name, 'last':last_name})

      else:
            notification.send([user], "edit_email", {'user':user, 'first':first_name, last':last_name})           

def model_deletion(sender, **kwargs):
      instance = kwargs.get('instance')
      user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name
      notification.send([user], "delete_email", {'user':user, 'first':first_name, 'last':last_name})

Sorry for overloading the page with code. That said, is there something I’m doing wrong? Anything missing? Any insight would be greatly appreciated!