added first public views - no check for access rights at the moment

This commit is contained in:
Holger Sielaff
2024-07-12 17:22:17 +02:00
parent 7d53df6ea5
commit 3640ab759d
22 changed files with 386 additions and 69 deletions

View File

View File

@@ -0,0 +1,31 @@
from functools import cached_property
from django.contrib.auth.models import User
from django.db import models
from lib.core.db.models.mixins import DateAware
class SharedPermissionBase(DateAware, models.Model):
class Meta:
abstract = True
user = models.ForeignKey(User, on_delete=models.CASCADE)
view = models.BooleanField(default=True)
change = models.BooleanField(default=False)
delete = models.BooleanField(default=False)
add = models.BooleanField(default=False)
# item = models.IntegerField(default=NotImplementedError('Must be defined in inheriting class'))
@cached_property
def perms(self):
perms = filter(None, [
'read' if self.view else False,
'change' if self.change else False,
'delete' if self.delete else False,
'add' if self.add else False,
])
return list(perms)
def __str__(self):
return f'{self.user.username} ({", ".join(self.perms)})'

View File

@@ -0,0 +1,35 @@
from django.contrib.auth.models import User
from django.db import models
from lib.middleware.current_user import get_current_user
class DateAware(models.Model):
class Meta:
abstract = True
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class AuthorAware(models.Model):
class Meta:
abstract = True
author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, default=get_current_user)
class DescriptionAware(models.Model):
class Meta:
abstract = True
description = models.TextField(null=True, blank=True)
class NameAware(models.Model):
class Meta:
abstract = True
name = models.CharField(max_length=100, unique=True, db_index=True)