-
-
Save owais/994e3d2826f225142304 to your computer and use it in GitHub Desktop.
Groups and perms monkey patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extend_django_model(sender, **kwargs): | |
""" | |
Add a kind small positive integer field to Group model. | |
""" | |
if sender.__name__ == "Group": | |
Group = sender | |
Group.DEFAULT_USER = 1 | |
Group.DEFAULT_ADMIN = 2 | |
Group.PERMISSIONS = ( | |
('admin', 'Admin rights', None, True), | |
) | |
kind = PositiveSmallIntegerField('kind', default=None, null=True, | |
blank=True) | |
kind.contribute_to_class(sender, "kind") | |
vendor = ForeignKey('vendors.Vendor', null=True, blank=True, | |
related_name='groups') | |
vendor.contribute_to_class(sender, 'vendor') | |
display_name = CharField('Role Name', max_length=67, default='', | |
null=True) | |
display_name.contribute_to_class(sender, "display_name") | |
Group._meta.unique_together += (('vendor', 'kind',),) | |
if sender.__name__ == "Permission": | |
Permission = sender | |
Permission.CLIENT = 1 | |
Permission.VENDOR = 2 | |
Permission.ALL = 3 | |
Permission.VISIBILITY_CHOICES = ( | |
(Permission.CLIENT, 'Client'), | |
(Permission.VENDOR, 'Vendor'), | |
(Permission.ALL, 'All'), | |
) | |
field = PositiveSmallIntegerField("visibility", null=True, blank=True, | |
choices=Permission.VISIBILITY_CHOICES) | |
field.contribute_to_class(sender, "visibility") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment