2

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 executed, 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).

gravelpot
  • 1,677
  • 1
  • 14
  • 20
kmh
  • 391
  • 3
  • 13
  • @Daniel-Roseman Thanks - I've added some code now, I hope this helps – kmh Sep 12 '11 at 15:48
  • Cannot answer the question myself, but using a different branch (theatlantic) resolved the issue. – kmh Sep 12 '11 at 16:16

1 Answers1

1

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()
Ted Kaplan
  • 464
  • 2
  • 8
  • Thanks, that makes sense. Is there a general idea no which branch of django-notification one should use? It seems to me that there are dozens of competing branches with no clear suggestion as to which one is the best one (most stable) to use ... – kmh Sep 12 '11 at 17:13