Login

Django substitution user

Author:
TA
Posted:
December 23, 2015
Language:
Python
Version:
Not specified
Score:
0 (after 0 ratings)

django-substitution-user is a project that makes it possible to substitute user, if you logged in as superuser

https://github.com/torchingloom/django-substitution-user

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# settings.py
INSTALLED_APPS = (
    # ...
    'substitution_user',
)
MIDDLEWARE_CLASSES = (
    # ...
    'substitution_user.middleware.SubstitutionUserMiddleware',
)

# urls.py
urlpatterns = patterns('',
    # ...
    url(r'^substitution_user/', include('substitution_user.urls')),
)

# someapp/admin.py
# ...
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin as UserAdminBase
from substitution_user.admin import SubstitutionUserAdminMixin
# ...
@admin.register(get_user_model())
class UserAdmin(SubstitutionUserAdminMixin, UserAdminBase):
    pass

# template
{% load substitution_user %}
{% substitution_user_get_real_user as real_user %}
{% if real_user != request.user %}
    <a href="{% url 'substitution_user_turn_off' %}">{{ request.user.username }} [{{ real_user.username }}]</a>
{% else %}
    <a href="{% url 'logout' %}">{{ request.user.username }}</a>
{% endif %}

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 months ago

Comments

Please login first before commenting.