Django-Notification - Alternative to Email Backend
I'm building a project with Django, and am currently trying to implement django-notification as a means to keep track of user activity. While I managed to install it and create some notifications, they are only sent via email but not stored in the respective databases so that I could display them in a feed view.
The /notifications/feed/ currently gives me a type error, I'm not sure if that is related?
TypeError at /notifications/feed/ init() takes exactly 3 arguments (1 given)
Any advice would be kindly appreciated. I've looked at how Pinax uses notification, but couldn't figure out how they got beyond the email-only backend.
In settings.py I have 'notification' enabled, as well as the template_context_processor 'notification.context_processors.notification'.
urls.py
url(r'^note/', include('notification.urls')),
app/management.py
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)
signals.post_syncdb.connect(create_notice_types, sender=notification)
app/view.py
...
if notification:
notification.send([user], "messages_received", {'message': message,})
...
notification.send is e开发者_运维百科xecuted, I checked this, but it seems that nothing is stored in the "notice" database ..
I should add, I'm running the Brian Rosner branch of django-notification (https://github.com/brosner/django-notification).
It appears that brosner's fork of django-notifications differs from jtauber's in that send_now()
does not actually add Notice instances to the database, nor does the default EmailBackend
notification backend.
You will have to write your own notification backend class that creates a Notice instance when deliver()
is called, and add it to NOTIIFICATION_BACKENDS
.
An (untested) example replicating jtauber's behavior:
class MyBackend(BaseBackend):
def deliver(self, recepient, sender, notice_type, extra_context):
messages = self.get_formatted_messages(["notice.html"],
notice_type.label, extra_context)
notice = Notice.objects.create(recipient=recepient,
message=messages['notice.html'], notice_type=notice_type,
on_site=on_site, sender=sender)
notice.save()
精彩评论