django-sessions

different values of a django session variable in different tabs

。_饼干妹妹 提交于 2019-12-06 11:06:28
Consider the following scenario: User searches for something and a list (request.session['List']) is created User can filter this list via an ajax call Now the user opens up a new tab, does another search, so now the session variable List is set to the new list for the other search User goes back to the first tab and filters the results again. This time, the filter results come from the new list in the other tab as the session variable has changed Is there a way to set different values for a session variable for different tabs? or any other solution for this problem? maulik13 There is no easy

Django: determine which user is deleting when using post_delete signal

杀马特。学长 韩版系。学妹 提交于 2019-12-06 02:03:49
问题 I want admins to be notified when certain objects are deleted but I also want to determine which user is performing the delete. Is it possible? This is the code: # models.py # signal to notify admins when nodes are deleted from django.db.models.signals import post_delete from settings import DEBUG def notify_on_delete(sender, instance, using, **kwargs): ''' Notify admins when nodes are deleted. Only for production use ''' if DEBUG: #return False pass # prepare context context = { 'node':

Django, how to see session data in the admin interface

懵懂的女人 提交于 2019-12-05 12:05:43
问题 I'm using Django sessions and I would like a way of seeing the session data in the admin interface. Is this possible? I.e. for each session I want to see the data stored in the session database (which is essentially a dictionary as far as I can gather). Currently I can just see a hash in the Session data field, such as: gAJ9cQEoVQ5zb3J0aW5nX2Nob2ljZXECVQJQT3EDVQxnYW1lc19wbGF5ZWRxBH1xBVgLAAAAcG9z dG1hbi1wYXRxBksDc1UKaXBfYWRkcmVzc3EHVQkxMjcuMC4wLjFxCFUKdGVzdGNvb2tpZXEJVQZ3

Django Session Persistent but Losing Data

拜拜、爱过 提交于 2019-12-05 09:47:16
I have been working for hours trying to understand the following problem: I have a user send an Ajax request to dynamically send a form and record that the number of forms to read on submission has increased. Toward this end I use request.session['editing_foo'] = { 'prefix_of_form_elements' : pkey } so that I can associate them with the database for saving and loading (-1 is for new forms that haven't been saved yet). However, when I use the following code (see bottom) I get the following bizarre output: 1st Click: {} foousername next_key 1 1 {u'1-foo': -1} 2nd Click: {} foousername next_key 1

In django : how to renew expiry date for current session?

坚强是说给别人听的谎言 提交于 2019-12-05 01:25:48
问题 I have a user logged in. How can i extend/renew expiry date of session received from the request ? Thanks in advance! 回答1: It's not necessary to make a custom middleware for this. Setting SESSION_SAVE_EVERY_REQUEST = True will cause Django's existing SessionMiddleware to do exactly what you want. It has this code: if modified or settings.SESSION_SAVE_EVERY_REQUEST: if request.session.get_expire_at_browser_close(): max_age = None expires = None else: max_age = request.session.get_expiry_age()

Modify session data of different Django user

ε祈祈猫儿з 提交于 2019-12-04 18:06:28
This may not be possible, but when certain conditions happen, I'd like to modify the session data of certain logged in users (flagging that some extra logic needs to run the next time they load a page). Is there a way to access the session of a user by their ID? tldr; Query Session model, then modify matching sessions via SessionStore . Your question is twofold, how to get session of a user, and how to modify data of arbitrary sessions (possibly outside of view). Get all logged in user sessions Since the session data is stored in an encoded form, I suggest getting all non-expired sessions,

Django: determine which user is deleting when using post_delete signal

穿精又带淫゛_ 提交于 2019-12-04 06:51:24
I want admins to be notified when certain objects are deleted but I also want to determine which user is performing the delete. Is it possible? This is the code: # models.py # signal to notify admins when nodes are deleted from django.db.models.signals import post_delete from settings import DEBUG def notify_on_delete(sender, instance, using, **kwargs): ''' Notify admins when nodes are deleted. Only for production use ''' if DEBUG: #return False pass # prepare context context = { 'node': instance, 'site': SITE } # notify admins that want to receive notifications notify_admins(instance, 'email

Most optimized way to delete all sessions for a specific user in Django?

喜欢而已 提交于 2019-12-03 07:03:56
问题 I'm running Django 1.3, using Sessions Middleware and Auth Middleware: # settings.py SESSION_ENGINE = django.contrib.sessions.backends.db # Persist sessions to DB SESSION_COOKIE_AGE = 1209600 # Cookies last 2 weeks Each time a user logs in from a different location (different computer/browser), a new Session() is created and saved with a unique session_id . This can result in multiple database entries for the same user. Their login persists on that node until the cookie is deleted or session

Django: session database table cleanup

元气小坏坏 提交于 2019-12-03 04:25:50
Does this table need to be purged or is it taken care automatically by Django? Abid A Django does NOT provide automatic purging. There is however a handy command available to help you do it manually: https://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-store python manage.py clearsessions Django 1.6 or Above python manage.py clearsessions Django 1.5 or lower python manage.py cleanup From Django Shell from django.contrib.sessions.models import Session Session.objects.all().delete() django-session-cleanup cornJob On my development server , I prefer a database command