Login

Mixin to enable admin permissions without using PermissionsMixin and models

Author:
thnee
Posted:
November 16, 2016
Language:
Python
Version:
Not specified
Score:
1 (after 1 ratings)

Implements necessary permission checks on a user model to be compatible with django admin, but just return true on all permissions without actually checking it against anything. Useful when you have a user model that should always be allowed to use django admin, and you don't care about using django's own PermissionsMixin and don't want to have those models added to your database.

 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
class FakeAdminPermissionsMixin(object):
    """
    Implements necessary parts of a User to work with the django admin.
    Simply returns true on all permission and superuser questions.
    Not intended to be a fully compatible PermissionsMixin,
    that would implement all parts of the API,
    only implements just enough to make django admin happy.
    Don't use this if you actually want to use permissions.
    """

    def has_perm(self, *args, **kwargs):
        return True

    def has_module_perms(self, *args, **kwargs):
        return True

    @property
    def is_staff(self):
        return True

    @is_staff.setter
    def is_staff(self, value):
        pass

    @property
    def is_superuser(self):
        return True

    @is_superuser.setter
    def is_superuser(self, value):
        pass

More like this

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

Comments

AliYmn (on November 22, 2016):

good!

#

Please login first before commenting.