First time here? Check out the FAQ!
1

How does system to user messaging system works in Askbot?

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?

martin-bts's avatar
78
martin-bts
asked 2019-06-30 14:05:52 -0500
Evgeny's avatar
13.2k
Evgeny
updated 2019-07-01 09:48:47 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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/anon_user.py - 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 askbot.models.message.py:Message. This model is hooked up to the User model via the .add_to_class call.

Evgeny's avatar
13.2k
Evgeny
answered 2019-06-30 14:44:16 -0500, updated 2019-06-30 19:55:53 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments