First commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
def header_for_table(model):
|
||||
|
||||
headers = model.objects.headers()
|
||||
|
||||
return [
|
||||
{
|
||||
"text": value,
|
||||
"value": key,
|
||||
}
|
||||
for key, value in headers.items()
|
||||
] + [
|
||||
{
|
||||
"text": "Actions",
|
||||
"value": "actions",
|
||||
"sortable": False,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def encrypted_fields(model):
|
||||
return model.Encryption.fields
|
||||
@@ -0,0 +1,37 @@
|
||||
from django.conf import settings
|
||||
from django.apps import apps
|
||||
|
||||
|
||||
from users.models import UserSettings
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def extra_context(request):
|
||||
|
||||
if not request.user.is_anonymous:
|
||||
user_settings, __ = UserSettings.objects.get_or_create(user=request.user)
|
||||
|
||||
else:
|
||||
user_settings = None
|
||||
|
||||
components = []
|
||||
for app in apps.get_app_configs():
|
||||
p = Path(settings.BASE_DIR) / app.name / "templates/components/"
|
||||
if p.exists():
|
||||
for path in p.iterdir():
|
||||
components.append(path.name)
|
||||
|
||||
return {
|
||||
"user_settings": user_settings,
|
||||
"templates": {
|
||||
component: f"components/{component}/template.html"
|
||||
for component in components
|
||||
},
|
||||
"components": {
|
||||
component: {
|
||||
"path": f"components/{component}/vue.js",
|
||||
"flat_name": component.replace("-", "_").lower(),
|
||||
}
|
||||
for component in components
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.db.models.fields.related import RelatedField
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class BaseQuerySet(models.QuerySet):
|
||||
def headers(self):
|
||||
"""Return the list of header for a list."""
|
||||
|
||||
fields = {}
|
||||
for field in self.model._meta.fields:
|
||||
if field.name in self.model.Serialization.excluded_fields:
|
||||
continue
|
||||
|
||||
# if isinstance(field, RelatedField):
|
||||
# fields[f"{field.name}__name"] = field.verbose_name.capitalize()
|
||||
|
||||
fields[field.name] = field.verbose_name.capitalize()
|
||||
|
||||
return fields
|
||||
|
||||
def serialize(self):
|
||||
"""Serialize a queryset."""
|
||||
|
||||
fields = []
|
||||
for field_name, _ in self.headers().items():
|
||||
fields.append(field_name)
|
||||
|
||||
return self.values(*fields)
|
||||
|
||||
|
||||
class BaseManager(models.Manager.from_queryset(BaseQuerySet)):
|
||||
pass
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class Serialization:
|
||||
# Exclude fields from serialization
|
||||
excluded_fields = []
|
||||
excluded_fields_edit = ["id", "created_at", "last_modified_at"]
|
||||
|
||||
class Encryption:
|
||||
fields = ["name", "description", "custom_identifier"]
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
|
||||
name = models.TextField(max_length=2048)
|
||||
description = models.TextField(max_length=2048)
|
||||
|
||||
custom_identifier = models.TextField(max_length=2048, null=True)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
last_modified_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
objects = BaseManager()
|
||||
Reference in New Issue
Block a user