How is django-messages creating notification types during syncdb?

793 views Asked by At

I am using the django-notification and django-messages projects together, and taking advantage of the django-notifications integration built in to django-messages with its default notice types for when messages are received, replied to, etc.

However, I cannot determine how these default NoticeType objects are being created. The django-notification docs suggest using post_syncdb signal in a management.py file, which is what I'm doing for my own custom notifications. I cannot find anywhere in any of the code that these notice types are defined. Yet everytime I run syncdb on a fresh database, they magically appear.

The "label" property of the notice types that are being created by the django-messages app are as follows:

  • messages_received
  • messages_sent
  • messages_replied
  • messages_reply_received
  • messages_deleted
  • messages_recovered
1

There are 1 answers

2
Casey Kinsey On BEST ANSWER

django_messages/management.py:

from django.db.models import get_models, signals
from django.conf import settings
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.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)
        notification.create_notice_type("messages_replied", _("Message Replied"), _("you have replied to a message"), default=1)
        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 undeleted a message"), default=1)

    signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
    print "Skipping creation of NoticeTypes as notification app not found"

https://github.com/arneb/django-messages/blob/master/django_messages/management.py

The types are defined here and hooked to a post_syncdb signal.