/usr/lib/python2.7/dist-packages/hijack/admin.py is in python-django-hijack 2.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 35 36 37 38 39 40 41 42 43 44 45 | # -*- coding: utf-8 -*-
from compat import get_user_model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.core.urlresolvers import reverse
from django.template import Context
from django.template.loader import get_template
from django.utils.translation import ugettext as _
from hijack import settings as hijack_settings
class HijackUserAdminMixin(object):
def hijack_field(self, obj):
hijack_attributes = hijack_settings.HIJACK_URL_ALLOWED_ATTRIBUTES
if 'user_id' in hijack_attributes:
hijack_url = reverse('login_with_id', args=(obj.pk, ))
elif 'email' in hijack_attributes:
hijack_url = reverse('login_with_email', args=(obj.email, ))
else:
hijack_url = reverse('login_with_username', args=(obj.username, ))
button_template = get_template('hijack/admin_button.html')
button_context = Context({
'hijack_url': hijack_url,
'username': str(obj),
})
return button_template.render(button_context)
hijack_field.allow_tags = True
hijack_field.short_description = _('Hijack user')
class HijackUserAdmin(HijackUserAdminMixin, UserAdmin):
list_display = ('username', 'email', 'first_name', 'last_name',
'last_login', 'date_joined', 'is_staff', 'hijack_field', )
list_filter = ('is_staff', 'is_superuser')
search_fields = ('username', 'first_name', 'last_name', 'email', )
# By default show a Hijack button in the admin panel for the User model.
if hijack_settings.HIJACK_DISPLAY_ADMIN_BUTTON:
UserModel = get_user_model()
admin.site.unregister(UserModel)
admin.site.register(UserModel, HijackUserAdmin)
|