Пример #1
0
 def __init__(self, *args, **kwargs):
     DjangoUserAdmin.__init__(self, *args, **kwargs)
     # remove default permissions forms
     for label, fieldset in self.fieldsets:
         fieldset["fields"] = [
             x for x in fieldset["fields"] if x not in ["user_permissions"]
         ]
Пример #2
0
 def test_submit_row(self):
     """
     submit_row template tag should pass whole context.
     """
     request = self.request_factory.get(reverse('admin:auth_user_change', args=[self.superuser.pk]))
     request.user = self.superuser
     admin = UserAdmin(User, site)
     extra_context = {'extra': True}
     response = admin.change_view(request, str(self.superuser.pk), extra_context=extra_context)
     template_context = submit_row(response.context_data)
     self.assertIs(template_context['extra'], True)
     self.assertIs(template_context['show_save'], True)
Пример #3
0
 def change_view(self, request, *args, **kwargs):
     # for non-superuser
     if not request.user.is_superuser:
         try:
             self.fieldsets = self.staff_fieldsets
             response = UserAdmin.change_view(self, request, *args, **kwargs)
         finally:
             # Reset fieldsets to its original value
             self.fieldsets = UserAdmin.fieldsets
         return response
     else:
         return UserAdmin.change_view(self, request, *args, **kwargs)
Пример #4
0
 def test_submit_row(self):
     """
     submit_row template tag should pass whole context.
     """
     request = self.request_factory.get(reverse('admin:auth_user_change', args=[self.superuser.pk]))
     request.user = self.superuser
     admin = UserAdmin(User, site)
     extra_context = {'extra': True}
     response = admin.change_view(request, str(self.superuser.pk), extra_context=extra_context)
     template_context = submit_row(response.context_data)
     self.assertIs(template_context['extra'], True)
     self.assertIs(template_context['show_save'], True)
Пример #5
0
 def change_view(self, request, *args, **kwargs):
     # for non-superuser
     if not request.user.is_superuser:
         try:
             self.fieldsets = self.staff_fieldsets
             response = UserAdmin.change_view(self, request, *args, **kwargs)
         finally:
             # Reset fieldsets to its original value
             self.fieldsets = UserAdmin.fieldsets
         return response
     else:
         return UserAdmin.change_view(self, request, *args, **kwargs)
Пример #6
0
 def test_override_show_save_and_add_another(self):
     request = self.request_factory.get(
         reverse('admin:auth_user_change', args=[self.superuser.pk]),
     )
     request.user = self.superuser
     admin = UserAdmin(User, site)
     for extra_context, expected_flag in (
         ({}, True),  # Default.
         ({'show_save_and_add_another': False}, False),
     ):
         with self.subTest(show_save_and_add_another=expected_flag):
             response = admin.change_view(
                 request,
                 str(self.superuser.pk),
                 extra_context=extra_context,
             )
             template_context = submit_row(response.context_data)
             self.assertIs(template_context['show_save_and_add_another'], expected_flag)
Пример #7
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     """
     Override password field to allow AMO's longer hashed passwords.
     """
     f = DjangoUserAdmin.formfield_for_dbfield(self, db_field, **kwargs)
     if db_field.name == 'password':
         f.max_length = 255
         f.validators = [MaxLengthValidator(255)]
         db_field.validators = [MaxLengthValidator(255)]
     return f
Пример #8
0
 def change_view(self, request, *args, **kwargs):
     # for superuser
     try:
         if request.user.is_superuser:
             self.fieldsets = self.standard_fieldsets + self.superuser_fieldsets
         else:
             self.fieldsets = self.standard_fieldsets + self.staff_fieldsets
         response = UserAdmin.change_view(self, request, *args, **kwargs)
     finally:
         # Reset fieldsets to its original value
         self.fieldsets = self.standard_fieldsets
     return response
Пример #9
0
    def change_view(self, request, *args, **kwargs):
        # for superuser
        try:
            if request.user.is_superuser:
                self.fieldsets = self.standard_fieldsets + self.superuser_fieldsets
            else:
                self.fieldsets = self.standard_fieldsets + self.staff_fieldsets

            response = UserAdmin.change_view(self, request, *args, **kwargs)
        finally:
            # Reset fieldsets to its original value
            self.fieldsets = self.standard_fieldsets

        return response
Пример #10
0
    def change_view(self, request, *args, **kwargs):
        try:
            group, created = Group.objects.get_or_create(name = 'Admissions')
            user_perm_list = UserPermissionList.objects.get(
                user=request.user
                )
        except UserPermissionList.DoesNotExist:
            groups = list()

	
        self.form = MyUserAdminForm

        # for non-superuser
        if not request.user.is_superuser and request.user.has_perm('auth.change_users') and group.id in user_perm_list.group_fk_list:
            self.form = AdmissionsAdminForm
            try:
                self.fieldsets = self.staff_fieldsets
                response = UserAdmin.change_view(self, request, *args, **kwargs)
            finally:
                # Reset fieldsets to its original value
                self.fieldsets = UserAdmin.fieldsets
                return response
        else:
            return UserAdmin.change_view(self, request, *args, **kwargs)
Пример #11
0
    def change_view(self, request, *args, **kwargs):
        try:
            group, created = Group.objects.get_or_create(name='Admissions')
            user_perm_list = UserPermissionList.objects.get(user=request.user)
        except UserPermissionList.DoesNotExist:
            groups = list()

        self.form = MyUserAdminForm

        # for non-superuser
        if not request.user.is_superuser and request.user.has_perm(
                'auth.change_users'
        ) and group.id in user_perm_list.group_fk_list:
            self.form = AdmissionsAdminForm
            try:
                self.fieldsets = self.staff_fieldsets
                response = UserAdmin.change_view(self, request, *args,
                                                 **kwargs)
            finally:
                # Reset fieldsets to its original value
                self.fieldsets = UserAdmin.fieldsets
                return response
        else:
            return UserAdmin.change_view(self, request, *args, **kwargs)
Пример #12
0
 def get_urls(self):
     useradmin = UserAdmin(DatabaseUser, self.admin_site)
     return [
         url(r'^(\d+)/password/$',
             self.admin_site.admin_view(useradmin.user_change_password))
     ] + super(DatabaseUserAdmin, self).get_urls()
Пример #13
0
 def user_change_password(self, request, id, from_url=""):
     user = self.get_object(request, unquote(id))
     operator = request.user
     if user.is_superuser and user.id != operator.id:
         raise PermissionDenied
     return UserAdmin.user_change_password(self, request, id)