From 3d8519154bfeff4490b4c4048f99aae46a16f79c Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 16 Aug 2022 08:58:35 +0100 Subject: [PATCH] Begin implementing content permissions --- core/models.py | 14 ++++++++++++++ core/views/helpers.py | 10 ++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/models.py b/core/models.py index 603b1f8..fbef7a1 100644 --- a/core/models.py +++ b/core/models.py @@ -102,3 +102,17 @@ class ContentBlock(models.Model): self.image3 = None super().save(*args, **kwargs) + + +class Role(models.Model): + name = models.CharField(max_length=255, unique=True) + description = models.CharField(max_length=1024, null=True, blank=True) + permission = models.CharField(max_length=255) + + def __str__(self): + return self.name + + +class ContentPermission(models.Model): + inherit = models.ForeignKey("self", null=True, blank=True, on_delete=models.PROTECT) + roles = models.ManyToManyField(Role, blank=True) diff --git a/core/views/helpers.py b/core/views/helpers.py index 7bf88e9..a7aeb3c 100644 --- a/core/views/helpers.py +++ b/core/views/helpers.py @@ -21,19 +21,17 @@ def dedup_list(data, check_keys): return out - - - # from random import randint # from timeit import timeit # entries = 10000 # a = [ -# {'ts': "sss", 'msg': randint(1, 2), str(randint(1, 2)): randint(1, 2)} for x in range(entries) +# {'ts': "sss", 'msg': randint(1, 2), str(randint(1, 2)): \ +# randint(1, 2)} for x in range(entries) # ] # kk = ["msg", "nick"] # call = lambda: dedup_list(a, kk) # #print(timeit(call, number=10)) # print(dedup_list(a, kk)) -# # sh-5.1$ python helpers.py -# # 1.0805372429895215 \ No newline at end of file +# # sh-5.1$ python helpers.py +# # 1.0805372429895215