-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmodels.py
94 lines (76 loc) · 3.18 KB
/
models.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Models for Roles, which define things a user can do."""
from uuid import uuid4
from django.db import models
from multiselectfield import MultiSelectField
PERMISSION_CHOICES = (
("AddE", "Add Event"),
("UpdE", "Update Event"),
("DelE", "Delete Event"),
("VerE", "Verify Event"),
("UpdB", "Update Body"),
("Role", "Modify Roles"),
("VerA", "Verify Achievements"),
("AppP", "Moderate Post"),
("ModC", "Moderate Comment"),
)
class BodyRole(models.Model):
"""A role for a bodywhich can be granted to multiple users."""
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
time_of_creation = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=50)
body = models.ForeignKey(
"bodies.Body", on_delete=models.CASCADE, related_name="roles"
)
inheritable = models.BooleanField(default=False)
permissions = MultiSelectField(choices=PERMISSION_CHOICES)
priority = models.IntegerField(default=0)
official_post = models.BooleanField(default=True)
permanent = models.BooleanField(default=False)
class Meta:
verbose_name = "Body Role"
verbose_name_plural = "Body Roles"
ordering = ("body__name", "priority")
def __str__(self):
return self.body.name + " " + self.name
"""
Added Community Role Model : To allow to have various communities in a single body and have different roles for each
community.
Ditched For Now
"""
# class CommunityRole(models.Model):
# """A role for a bodywhich can be granted to multiple users."""
# id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
# time_of_creation = models.DateTimeField(auto_now_add=True)
# name = models.CharField(max_length=50)
# community = models.ForeignKey('community.Community', on_delete=models.CASCADE, related_name='roles')
# inheritable = models.BooleanField(default=False)
# permissions = MultiSelectField(choices=PERMISSION_CHOICES)
# priority = models.IntegerField(default=0)
# official_post = models.BooleanField(default=True)
# permanent = models.BooleanField(default=False)
# class Meta:
# verbose_name = "Community Role"
# verbose_name_plural = "Community Roles"
# ordering = ("community__name", "priority")
# def __str__(self):
# return self.community.name + " " + self.name
INSTITUTE_PERMISSION_CHOICES = (
("AddB", "Add Body"),
("DelB", "Delete Body"),
("BodyChild", "Modify Body-Child Relations"),
("Location", "Full control over locations"),
("Role", "Modify Institute Roles"),
("RoleB", "Modify roles for any body"),
)
class InstituteRole(models.Model):
"""An institute role which can be granted to multiple users."""
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
time_of_creation = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=50)
description = models.CharField(max_length=100, blank=True)
permissions = MultiSelectField(choices=INSTITUTE_PERMISSION_CHOICES)
class Meta:
verbose_name = "Institute Role"
verbose_name_plural = "Institute Roles"
def __str__(self):
return self.name