Guest User

Untitled

a guest
Apr 7th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class UserDBConnection(object):
  2. """If the user is logged in (assumed if their password is in the
  3. session!), the global connection object is updated to use their
  4. connection credentials instead of the default Django ones."""
  5. def process_request(self, request):
  6. if 'password' in request.session:
  7. from django import db
  8. from django.conf import settings
  9. username = request.user.username
  10. password = request.session['password']
  11.  
  12. db.connection.settings_dict['DATABASE_USER'] = username
  13. db.connection.settings_dict['DATABASE_PASSWORD'] = password
  14. return None
Add Comment
Please, Sign In to add comment