Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean up Django login message from framework

Tags:

python

django

There is a project setup with Django 1.6 and Django allauth. when user logged in django saves a login message to users session and its stack in there. While user reached to any page included messages framework, login message shows up with other message.

Because of this reason, I want to remove login message from message queue after user logged in.

I tried remove login message in django's and allauth's user_logged_in signal, but I discovered the message is not created there.

The example of the message removal code is below:

# from allauth.account.signals import user_logged_in
# First I tried allauth signal above.
from django.contrib.auth.signals import user_logged_in

@receiver(user_logged_in)
def user_logged_in_(request, **kwargs):
    storage = messages.get_messages(request)
    storage.used = True

Edit: The workaround below is working. But I feel it is not right way to do.

After this, I decided to make a workaround. After user logged in, user redirected to index view. I removed signal and append storage.used = True method in index view. Also It is not worked too.

def clear_messages(request):
    storage = messages.get_messages(request)
    storage.used = True


def index(request):
    clear_messages(request)
    return render_to_response('website/index.html', {}, context_instance=RequestContext(request, {}))

like image 443
Sencer H. Avatar asked Sep 09 '14 12:09

Sencer H.


1 Answers

From django-allauth's documentation:

All messages (as in django.contrib.messages) are configurable by overriding their respective template. If you want to disable a message simply override the message template with a blank one.

like image 104
Paulo Almeida Avatar answered Oct 11 '22 22:10

Paulo Almeida