1

:)

我正在尝试在同一个项目上部署 django-notification 和 django-avatar,但是,当我运行 python2 manage.py syncdb 时,我收到了这个异常:

(dispersion)jorge [~/coders/desarrollo/dispersion] ~> python2 manage.py validate
python2 manage.py validate
0 errors found
(dispersion)jorge [~/coders/desarrollo/dispersion] ~> python2 manage.py syncdb
python2 manage.py syncdb
Creating tables ...
Creating table django_comments
Creating table django_comment_flags
Creating table threadedcomments_threadedcomment
Creating table threadedcomments_freethreadedcomment
Creating table threadedcomments_testmodel
Creating table notification_noticetype
Creating table notification_noticesetting
Creating table notification_noticequeuebatch
Creating table announcements_announcement
Creating table announcements_dismissal
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/commands/syncdb.py", line 110, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/sql.py", line 189, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/jorge/coders/desarrollo/dispersion/lib/python2.7/site-packages/django_avatar-1.0.5-py2.7.egg/avatar/management/__init__.py", line 9, in create_notice_types
    notification.create_notice_type("avatar_updated", _("Avatar Updated"), _("avatar have been updated"))
AttributeError: 'module' object has no attribute 'create_notice_type'
(dispersion)jorge [~/coders/desarrollo/dispersion] ~> 

诡异的!嗯?我什至不知道为什么会发生这个错误。有什么帮助吗?

4

2 回答 2

2

对,create_notice_type 已被删除。只需创建一个 NoticeType 的实例,如下所示:

# static block:
try:
    notification = get_app( 'notification' )
except ImproperlyConfigured:
    notification = None
..

# in your method:
if notification is not None and "notification" in settings.INSTALLED_APPS:
from django.utils.translation import ugettext_noop as _

message = {

    'user':     settings.DEFAULT_FROM_EMAIL, 
    'comment':  'no comment', 
    'type':     'welcome', 
    'descr':    'my description',
    # ..
}
try:

    notification.send([to_user], "welcome", message)
except NoticeType.DoesNotExist:
    NoticeType.create("welcome", _("Bla Bla"), _("How nice of you to visit our site"))
    notification.send([to_user], "welcome", message)
于 2013-05-28T14:38:27.597 回答
1

这是因为最新版本的 django-notification(版本 1.0 位于此处)被重构并从 models.py 中删除了 create_notice_type ....

这很麻烦,因为当前版本的 django-avatar 和 django-postman 依赖于 create_notice_type...

所以要解决这个问题,我必须通过以下方式安装先前版本的 django 通知:

pip install django-notification==0.2
于 2013-02-12T18:52:44.643 回答