Ask Your Question

How does system to user messaging system works in Askbot?

asked 2019-06-30 14:05:52 -0500

martin-bts's avatar

updated 2019-07-01 09:48:47 -0500

Evgeny's avatar

In the context processors used for Askbot messages, i.e. askbot.user_messages.context_processors.user_messages messages get added to the context using get_and_delete_messages(). As the name foreshadows, this deletes messages from the session/the database.

If there are pending messages and there is an ajax request, for instance a user casts a vote, the context processor is run and the messages get fetched and deleted. I can't tell if the messages get returned with the ajax response, but I think they aren't. This means the messages are lost and won't be shown to the user. Is that correct? Or is there some facility that returns messages to the user and then the javascript on the client side takes care of rendering the messages?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-30 14:44:16 -0500

Evgeny's avatar

updated 2019-06-30 19:55:53 -0500

Those are session-based messages that are displayed on screen by the system, not to be confused with the django db messages, also not to be confused with user-to-user private messages.

The reason why the session messages are used is that anonymous users don't have the db record in the auth_user table therefore it will be impossible AFAIK to use the standard django messages for this purpase.

Please have a look at middleware/ - that initializes the user messages api. It has the API identical to the Django ORM, but in reality has nothing to do with that.

The idea was to be able to do do this for examlpe:

request.user.SEND_MESSAGE('Sorry, but to do this you need to register first.') #SEND_MESSAGE is a fictional function

As of time of this answer we do this:

request.user.message_set.create(message='Sorry, but to do this you need to register first.')

Note that it works when request.user.is_anonymous() == True

When user is authenticated we are storing message into This model is hooked up to the User model via the .add_to_class call.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-06-30 14:05:52 -0500

Seen: 8,533 times

Last updated: Jul 01 '19