2012-08-15 29 views
0

我使用的django-notificationdjango-messages項目組合在一起,並採取內置於Django的消息,其違約通知類型收到短信時的Django的通知整合的優勢,回覆等在syncdb中,django-messages是如何創建通知類型的?

然而,我無法確定如何創建這些默認的NoticeType對象。 Django通知文檔建議在management.py文件中使用post_syncdb信號,這是我爲自己的自定義通知所做的。我無法在這些通知類型定義的任何代碼中找到任何地方。然而,每當我在新數據庫上運行syncdb時,它們都會奇蹟般地出現。

正在由Django的消息的應用程序所創建的通知類型的 「標記」 屬性如下:

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

回答

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信號。

+0

嗯,我現在覺得很愚蠢。我一直在Eclipse/PyDev中查看這個,它隱藏了.pyc文件。出於某種原因,management.py不存在,但management.pyc是。這正是我所尋找的,但只是不夠努力......:( – gravelpot 2012-08-15 19:56:36

+3

現在已經很晚了,趕上一杯啤酒吧! – 2012-08-15 19:58:15