0

我正在一起使用django-notificationdjango-messages项目,并利用 django-messages 内置的 django-notifications 集成及其默认通知类型,用于接收、回复等消息。

但是,我无法确定这些默认的 NoticeType 对象是如何创建的。django-notification 文档建议在 management.py 文件中使用 post_syncdb 信号,这是我为自己的自定义通知所做的。我在任何代码中都找不到定义这些通知类型的任何地方。然而,每次我在新数据库上运行 syncdb 时,它们都会神奇地出现。

由 django-messages 应用程序创建的通知类型的“标签”属性如下:

  • messages_received
  • messages_sent
  • messages_replied
  • messages_reply_received
  • messages_deleted
  • messages_recovered
4

1 回答 1

0

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

这些类型在此处定义并连接到 post_syncdb 信号。

于 2012-08-15T19:49:57.100 回答