reusable application for django site wide announcements that displays a message only once per user

孤人 提交于 2019-12-08 11:33:31

问题


I want to show various messages to registered users only once in my django application. I found django-announcements which seemed to do what I want - but I found in testing it marks messages as read by using a session variable, which disappears if the user logs out. This means a message is shown again to a user if they dismiss it when logged in, log out, and then log in again.

I wondered if anyone know of an application that I might be able to use here without re-inventing the wheel.


回答1:


Have a look at django-notification. It is used by pinax, there it seems to work like what you are searching for. At least it saves the status in the db.

edit

Response to the comment

from the docs:

notification.send([to_user], "friends_invite", {"from_user": from_user})

so this should work:

notification.send(Users.objects.all(), "friends_invite", {"from_user": from_user})

and if a queryset isnt right:

notification.send([u for u in Users.objects.all()], "friends_invite", {"from_user": from_user})



回答2:


Have you looked at the Messages Framework in Django 1.3? In Django <=1.2 it was a simple model so you could do:

for user in User.objects.all():
    user.message_set.create(message="some text")

and this would be rendered in the template, and dismissed as soon as the next page is loaded (it's what Django admin uses). It has changed a bit in 1.3, but it might be handy, but not 'dismissable' in the way that maybe you want.



来源:https://stackoverflow.com/questions/1829926/reusable-application-for-django-site-wide-announcements-that-displays-a-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!