First commit

This commit is contained in:
2024-09-26 23:59:03 +02:00
commit f3116a6876
53 changed files with 1822 additions and 0 deletions
View File
+16
View File
@@ -0,0 +1,16 @@
"""
ASGI config for k356 project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
application = get_asgi_application()
+154
View File
@@ -0,0 +1,154 @@
"""
Django settings for k356 project.
Generated by 'django-admin startproject' using Django 5.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
from pathlib import Path
from django.utils.module_loading import import_module
import os
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-$440wv7cqb$-umfo-x%w_@p3g5kuuk1(!rv#=7*gzndx4_h4ds'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'users',
'items',
'django_js_reverse',
]
STATIC_URL = "/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static_source"),)
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# "djangobower.finders.BowerFinder",
# "compressor.finders.CompressorFinder",
)
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STORAGES = {
"staticfiles": {
# "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
}
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, "templates"),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app.utils.extra_context.extra_context',
],
},
},
]
WSGI_APPLICATION = 'app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = {}
# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
from app.settingsLocal import *
for extra_app in EXTRA_APPS:
INSTALLED_APPS.append(extra_app)
tmp_app = import_module(extra_app)
+28
View File
@@ -0,0 +1,28 @@
"""
URL configuration for k356 project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django_js_reverse.views import urls_js
urlpatterns = [
path("", include("main.urls")),
path("items/", include("items.urls")),
path("users/", include("users.urls")),
path("admin/", admin.site.urls),
path('reverse.js', urls_js, name='reverse_js'),
]
View File
View File
+21
View File
@@ -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
+37
View File
@@ -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
}
}
+62
View File
@@ -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()
+16
View File
@@ -0,0 +1,16 @@
"""
WSGI config for k356 project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
application = get_wsgi_application()