如何在视图中配置django-notifications

时间:2012-05-13 16:35:10

标签: django django-views

我有一个应用程序,员工可以在其中发布支持团队的工作请求订单。我正在尝试配置保存请求表单的位置,并向支持团队的代表发送通知。使用django-notifications,我创建了manage.py文件......

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("post_request", _("Post Request Received"), _("you have received a Post Request"))

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

但是,我在view函数中遇到了正确的语法问题。正如其写的:

def create_record(request):
    if request.method == 'POST':
        form = PostRequestForm(request.POST)
        user = User.objects.filter(username="targetuser")
        if form.is_valid():  
            form.save()
            if notification:
                notification.send([user], "post_request", {"user": user})
                return HttpResponseRedirect('/create/')
    else:
        form = PostRequestForm()
    return render(request, 'createpostrequest.html', {
        'form': form,
})

但它会抛出错误“NoticeType匹配查询不存在”。如果我用特定的用户名替换“user”,我会得到全局名称未定义的错误。我做错了什么?

0 个答案:

没有答案