Login

Mixin to enable admin permissions without using PermissionsMixin and models

Author:
thnee
Posted:
November 16, 2016
Language:
Python
Version:
Not specified
Tags:
admin mixin permissions
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

Comments

AliYmn (on November 22, 2016):
<p>good!</p>

#

Please login first before commenting.