work
This commit is contained in:
parent
02341dccee
commit
d14464fdfd
21 changed files with 445 additions and 190 deletions
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'azube.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azube.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
|
|
|
@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure--nw#rw&yl=j$7c3xdg3dh&p=9o=4hngx6+px7s^py6-r6%c#6*'
|
SECRET_KEY = "django-insecure--nw#rw&yl=j$7c3xdg3dh&p=9o=4hngx6+px7s^py6-r6%c#6*"
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
@ -31,53 +31,53 @@ ALLOWED_HOSTS = []
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
"core"
|
"core",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
"django.middleware.security.SecurityMiddleware",
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'azube.urls'
|
ROOT_URLCONF = "azube.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [],
|
"DIRS": [],
|
||||||
'APP_DIRS': True,
|
"APP_DIRS": True,
|
||||||
'OPTIONS': {
|
"OPTIONS": {
|
||||||
'context_processors': [
|
"context_processors": [
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.request',
|
"django.template.context_processors.request",
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.messages.context_processors.messages',
|
"django.contrib.messages.context_processors.messages",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'azube.wsgi.application'
|
WSGI_APPLICATION = "azube.wsgi.application"
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
"default": {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
"NAME": BASE_DIR / "db.sqlite3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,16 +87,16 @@ DATABASES = {
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = "en-us"
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = "UTC"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
@ -116,9 +116,9 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = "static/"
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
|
|
|
@ -14,10 +14,8 @@ Including another URLconf
|
||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [path("admin/", admin.site.urls), path("", include("core.urls"))]
|
||||||
path('admin/', admin.site.urls),
|
|
||||||
path('', include('core.urls'))
|
|
||||||
]
|
|
||||||
|
|
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'azube.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azube.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class MainAppConfig(AppConfig):
|
class MainAppConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = 'core'
|
name = "core"
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
from core.models import Berichtsheft
|
||||||
|
|
||||||
|
|
||||||
class AzureUser:
|
class AzureUser:
|
||||||
display_name: str
|
display_name: str
|
||||||
id: str
|
id: str
|
||||||
|
@ -15,7 +18,9 @@ class AzureUser:
|
||||||
self.id = request.headers["X-MS-CLIENT-PRINCIPAL-NAME"]
|
self.id = request.headers["X-MS-CLIENT-PRINCIPAL-NAME"]
|
||||||
|
|
||||||
# X-MS-CLIENT-PRINCIPAL
|
# X-MS-CLIENT-PRINCIPAL
|
||||||
claims_json = json.loads(base64.decode(request.headers["X-MS-CLIENT-PRINCIPAL"]))
|
claims_json = json.loads(
|
||||||
|
base64.decode(request.headers["X-MS-CLIENT-PRINCIPAL"])
|
||||||
|
)
|
||||||
claims = {}
|
claims = {}
|
||||||
|
|
||||||
for claim in claims_json["claims"]:
|
for claim in claims_json["claims"]:
|
||||||
|
@ -26,3 +31,5 @@ class AzureUser:
|
||||||
self.display_name = "Anon"
|
self.display_name = "Anon"
|
||||||
self.id = "anon"
|
self.id = "anon"
|
||||||
|
|
||||||
|
def reports(self):
|
||||||
|
return Berichtsheft.objects.filter(user=self.id)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def gen_doc(template: str, vars: dict) -> str:
|
def gen_doc(template: str, vars: dict) -> str:
|
||||||
definition = json.loads(open(f"{template}.json").read())
|
definition = json.loads(open(f"{template}.json").read())
|
||||||
content = open(f"{template}.html").read()
|
content = open(f"{template}.html").read()
|
||||||
|
|
|
@ -15,15 +15,30 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Berichtsheft',
|
name="Berichtsheft",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('year', models.PositiveIntegerField()),
|
"id",
|
||||||
('week', models.PositiveSmallIntegerField()),
|
models.BigAutoField(
|
||||||
('content', models.JSONField()),
|
auto_created=True,
|
||||||
('approved_by', models.JSONField()),
|
primary_key=True,
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
serialize=False,
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='berichtshefte', to=settings.AUTH_USER_MODEL)),
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("year", models.PositiveIntegerField()),
|
||||||
|
("week", models.PositiveSmallIntegerField()),
|
||||||
|
("content", models.JSONField()),
|
||||||
|
("approved_by", models.JSONField()),
|
||||||
|
("created", models.DateTimeField(auto_now_add=True)),
|
||||||
|
(
|
||||||
|
"user",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="berichtshefte",
|
||||||
|
to=settings.AUTH_USER_MODEL,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,13 +6,13 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('core', '0001_initial'),
|
("core", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='berichtsheft',
|
model_name="berichtsheft",
|
||||||
name='id',
|
name="id",
|
||||||
field=models.AutoField(primary_key=True, serialize=False),
|
field=models.AutoField(primary_key=True, serialize=False),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,54 +10,137 @@ import django.utils.timezone
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('auth', '0012_alter_user_first_name_max_length'),
|
("auth", "0012_alter_user_first_name_max_length"),
|
||||||
('core', '0002_alter_berichtsheft_id'),
|
("core", "0002_alter_berichtsheft_id"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Group',
|
name="Group",
|
||||||
fields=[
|
fields=[],
|
||||||
],
|
|
||||||
options={
|
options={
|
||||||
'proxy': True,
|
"proxy": True,
|
||||||
'indexes': [],
|
"indexes": [],
|
||||||
'constraints': [],
|
"constraints": [],
|
||||||
},
|
},
|
||||||
bases=('auth.group',),
|
bases=("auth.group",),
|
||||||
managers=[
|
managers=[
|
||||||
('objects', django.contrib.auth.models.GroupManager()),
|
("objects", django.contrib.auth.models.GroupManager()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='AzureUser',
|
name="AzureUser",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
"id",
|
||||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
models.BigAutoField(
|
||||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
auto_created=True,
|
||||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
primary_key=True,
|
||||||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
serialize=False,
|
||||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
verbose_name="ID",
|
||||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
),
|
||||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
),
|
||||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
("password", models.CharField(max_length=128, verbose_name="password")),
|
||||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
(
|
||||||
('groups', models.ManyToManyField(blank=True, related_name='azure_user_groups', to='auth.group')),
|
"last_login",
|
||||||
('user_permissions', models.ManyToManyField(blank=True, related_name='azure_user_permissions', to='auth.permission')),
|
models.DateTimeField(
|
||||||
|
blank=True, null=True, verbose_name="last login"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_superuser",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Designates that this user has all permissions without explicitly assigning them.",
|
||||||
|
verbose_name="superuser status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"username",
|
||||||
|
models.CharField(
|
||||||
|
error_messages={
|
||||||
|
"unique": "A user with that username already exists."
|
||||||
|
},
|
||||||
|
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
||||||
|
max_length=150,
|
||||||
|
unique=True,
|
||||||
|
validators=[
|
||||||
|
django.contrib.auth.validators.UnicodeUsernameValidator()
|
||||||
|
],
|
||||||
|
verbose_name="username",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"first_name",
|
||||||
|
models.CharField(
|
||||||
|
blank=True, max_length=150, verbose_name="first name"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"last_name",
|
||||||
|
models.CharField(
|
||||||
|
blank=True, max_length=150, verbose_name="last name"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"email",
|
||||||
|
models.EmailField(
|
||||||
|
blank=True, max_length=254, verbose_name="email address"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_staff",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Designates whether the user can log into this admin site.",
|
||||||
|
verbose_name="staff status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_active",
|
||||||
|
models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
|
||||||
|
verbose_name="active",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"date_joined",
|
||||||
|
models.DateTimeField(
|
||||||
|
default=django.utils.timezone.now, verbose_name="date joined"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"groups",
|
||||||
|
models.ManyToManyField(
|
||||||
|
blank=True, related_name="azure_user_groups", to="auth.group"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"user_permissions",
|
||||||
|
models.ManyToManyField(
|
||||||
|
blank=True,
|
||||||
|
related_name="azure_user_permissions",
|
||||||
|
to="auth.permission",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'user',
|
"verbose_name": "user",
|
||||||
'verbose_name_plural': 'users',
|
"verbose_name_plural": "users",
|
||||||
'abstract': False,
|
"abstract": False,
|
||||||
},
|
},
|
||||||
managers=[
|
managers=[
|
||||||
('objects', django.contrib.auth.models.UserManager()),
|
("objects", django.contrib.auth.models.UserManager()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='berichtsheft',
|
model_name="berichtsheft",
|
||||||
name='user',
|
name="user",
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='berichtshefte', to='core.azureuser'),
|
field=models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="berichtshefte",
|
||||||
|
to="core.azureuser",
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,12 +6,12 @@ from django.db import migrations
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('core', '0003_group_azureuser_alter_berichtsheft_user'),
|
("core", "0003_group_azureuser_alter_berichtsheft_user"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='berichtsheft',
|
model_name="berichtsheft",
|
||||||
name='approved_by',
|
name="approved_by",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,43 +9,123 @@ import django.utils.timezone
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('auth', '0012_alter_user_first_name_max_length'),
|
("auth", "0012_alter_user_first_name_max_length"),
|
||||||
('core', '0004_remove_berichtsheft_approved_by'),
|
("core", "0004_remove_berichtsheft_approved_by"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='User',
|
name="User",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
"id",
|
||||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
models.BigAutoField(
|
||||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
auto_created=True,
|
||||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
primary_key=True,
|
||||||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
serialize=False,
|
||||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
verbose_name="ID",
|
||||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
),
|
||||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
),
|
||||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
("password", models.CharField(max_length=128, verbose_name="password")),
|
||||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
(
|
||||||
('groups', models.ManyToManyField(blank=True, related_name='user_groups', to='auth.group')),
|
"last_login",
|
||||||
('user_permissions', models.ManyToManyField(blank=True, related_name='user_permissions', to='auth.permission')),
|
models.DateTimeField(
|
||||||
|
blank=True, null=True, verbose_name="last login"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_superuser",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Designates that this user has all permissions without explicitly assigning them.",
|
||||||
|
verbose_name="superuser status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"username",
|
||||||
|
models.CharField(
|
||||||
|
error_messages={
|
||||||
|
"unique": "A user with that username already exists."
|
||||||
|
},
|
||||||
|
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
||||||
|
max_length=150,
|
||||||
|
unique=True,
|
||||||
|
validators=[
|
||||||
|
django.contrib.auth.validators.UnicodeUsernameValidator()
|
||||||
|
],
|
||||||
|
verbose_name="username",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"first_name",
|
||||||
|
models.CharField(
|
||||||
|
blank=True, max_length=150, verbose_name="first name"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"last_name",
|
||||||
|
models.CharField(
|
||||||
|
blank=True, max_length=150, verbose_name="last name"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"email",
|
||||||
|
models.EmailField(
|
||||||
|
blank=True, max_length=254, verbose_name="email address"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_staff",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Designates whether the user can log into this admin site.",
|
||||||
|
verbose_name="staff status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"is_active",
|
||||||
|
models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
|
||||||
|
verbose_name="active",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"date_joined",
|
||||||
|
models.DateTimeField(
|
||||||
|
default=django.utils.timezone.now, verbose_name="date joined"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"groups",
|
||||||
|
models.ManyToManyField(
|
||||||
|
blank=True, related_name="user_groups", to="auth.group"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"user_permissions",
|
||||||
|
models.ManyToManyField(
|
||||||
|
blank=True,
|
||||||
|
related_name="user_permissions",
|
||||||
|
to="auth.permission",
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'user',
|
"verbose_name": "user",
|
||||||
'verbose_name_plural': 'users',
|
"verbose_name_plural": "users",
|
||||||
'abstract': False,
|
"abstract": False,
|
||||||
},
|
},
|
||||||
managers=[
|
managers=[
|
||||||
('objects', django.contrib.auth.models.UserManager()),
|
("objects", django.contrib.auth.models.UserManager()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='berichtsheft',
|
model_name="berichtsheft",
|
||||||
name='user',
|
name="user",
|
||||||
field=models.TextField(),
|
field=models.TextField(),
|
||||||
),
|
),
|
||||||
migrations.DeleteModel(
|
migrations.DeleteModel(
|
||||||
name='AzureUser',
|
name="AzureUser",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
18
core/migrations/0006_berichtsheft_num.py
Executable file
18
core/migrations/0006_berichtsheft_num.py
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.16 on 2024-12-03 09:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("core", "0005_user_alter_berichtsheft_user_delete_azureuser"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="berichtsheft",
|
||||||
|
name="num",
|
||||||
|
field=models.PositiveBigIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2,35 +2,43 @@ from django.db import models
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.contrib.auth.models import Group as BuiltinGroup
|
from django.contrib.auth.models import Group as BuiltinGroup
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
groups = models.ManyToManyField(
|
groups = models.ManyToManyField(
|
||||||
'auth.Group',
|
"auth.Group",
|
||||||
related_name='user_groups',
|
related_name="user_groups",
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
user_permissions = models.ManyToManyField(
|
user_permissions = models.ManyToManyField(
|
||||||
'auth.Permission',
|
"auth.Permission",
|
||||||
related_name='user_permissions',
|
related_name="user_permissions",
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Group(BuiltinGroup):
|
class Group(BuiltinGroup):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
class Berichtsheft(models.Model):
|
class Berichtsheft(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
user = models.TextField()
|
user = models.TextField()
|
||||||
|
num = models.PositiveBigIntegerField(default=0)
|
||||||
year = models.PositiveIntegerField()
|
year = models.PositiveIntegerField()
|
||||||
week = models.PositiveSmallIntegerField()
|
week = models.PositiveSmallIntegerField()
|
||||||
content = models.JSONField()
|
content = models.JSONField()
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Berichtsheft: {self.user.username}, Year: {self.year}, Week: {self.week}"
|
return (
|
||||||
|
f"Berichtsheft: {self.user.username}, Year: {self.year}, Week: {self.week}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Approval:
|
class Approval:
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
user = models.TextField()
|
user = models.TextField()
|
||||||
report = models.ForeignKey(Berichtsheft, on_delete=models.CASCADE, related_name="report")
|
report = models.ForeignKey(
|
||||||
|
Berichtsheft, on_delete=models.CASCADE, related_name="report"
|
||||||
|
)
|
||||||
|
|
29
core/report_templates.py
Executable file
29
core/report_templates.py
Executable file
|
@ -0,0 +1,29 @@
|
||||||
|
class ReportTemplates:
|
||||||
|
report_global = {
|
||||||
|
"vars": [
|
||||||
|
{"name": "name", "display_name": "Name"},
|
||||||
|
{"name": "num_doc", "display_name": "Berichtsheft Nummer"},
|
||||||
|
{"name": "year", "display_name": "Jahr"},
|
||||||
|
{"name": "week", "display_name": "Kalenderwoche"},
|
||||||
|
{"name": "start_date", "display_name": "Von"},
|
||||||
|
{"name": "end_date", "display_name": "bis"},
|
||||||
|
{"name": "department", "display_name": "Abteilung"},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_template(id) -> dict:
|
||||||
|
match id:
|
||||||
|
case "weekly":
|
||||||
|
weekly = {
|
||||||
|
"vars": [
|
||||||
|
{
|
||||||
|
"name": "company_text",
|
||||||
|
"display_name": "Betriebliche Tätigkeiten",
|
||||||
|
},
|
||||||
|
{"name": "week_topic", "display_name": "Thema der Woche"},
|
||||||
|
{"name": "school_text", "display_name": "Berufsschule"},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
weekly["vars"].extend(ReportTemplates.report_global["vars"])
|
||||||
|
return weekly
|
|
@ -21,13 +21,29 @@
|
||||||
value = "{{ year }}"
|
value = "{{ year }}"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if var.name == "start_date" %}
|
||||||
|
value = "{{ start_date|date:"d.m.Y" }}"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if var.name == "end_date" %}
|
||||||
|
value = "{{ end_date|date:"d.m.Y" }}"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if var.name == "num_doc" %}
|
||||||
|
value = "{{ current_num }}"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if var.name == "name" %}
|
||||||
|
value = "{{ user.display_name }}"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<button> Submit </button>
|
<button> Submit </button>
|
||||||
|
|
||||||
|
{% csrf_token %}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path("", views.index, name="index"),
|
||||||
path('write', views.write_new_report, name='write'),
|
path("write", views.write_new_report, name="write"),
|
||||||
path("test", views.test, name="test")
|
path("test", views.test, name="test"),
|
||||||
]
|
]
|
32
core/util.py
Executable file
32
core/util.py
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def next_date(year: int, week: int) -> (int, int):
|
||||||
|
if week >= 52:
|
||||||
|
return (year + 1, 1)
|
||||||
|
else:
|
||||||
|
return (year, week + 1)
|
||||||
|
|
||||||
|
|
||||||
|
def first_day_of_iso_week(year, week):
|
||||||
|
# Create a date object for January 4th of the given year
|
||||||
|
# This date is always in the first week of the year according to ISO 8601
|
||||||
|
jan4 = datetime.datetime(year, 1, 4)
|
||||||
|
|
||||||
|
# Get the ISO week number and the weekday of January 4th
|
||||||
|
start_iso_week, start_iso_day = jan4.isocalendar()[1:3]
|
||||||
|
|
||||||
|
# Calculate the difference in weeks, then adjust for the start of the week
|
||||||
|
weeks_diff = week - start_iso_week
|
||||||
|
days_to_monday = datetime.timedelta(days=(1 - start_iso_day))
|
||||||
|
|
||||||
|
# Calculate the first day of the given ISO week
|
||||||
|
return jan4 + days_to_monday + datetime.timedelta(weeks=weeks_diff)
|
||||||
|
|
||||||
|
|
||||||
|
def get_week_range(p_year, p_week):
|
||||||
|
firstdayofweek = datetime.datetime.strptime(
|
||||||
|
f"{p_year}-W{int(p_week)}-1", "%Y-W%W-%w"
|
||||||
|
).date()
|
||||||
|
lastdayofweek = firstdayofweek + datetime.timedelta(days=6.9)
|
||||||
|
return firstdayofweek, lastdayofweek
|
|
@ -1,47 +1,59 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
from core.report_templates import ReportTemplates
|
||||||
|
from core.util import get_week_range, next_date
|
||||||
from .azure_auth import AzureUser
|
from .azure_auth import AzureUser
|
||||||
from .models import Berichtsheft
|
from .models import Berichtsheft
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
def next_date(year: int, week: int) -> (int, int):
|
|
||||||
if week >= 52:
|
|
||||||
return (year + 1, 1)
|
|
||||||
else:
|
|
||||||
return (year, week + 1)
|
|
||||||
|
|
||||||
def write_new_report(request):
|
def write_new_report(request):
|
||||||
user = AzureUser(request)
|
user = AzureUser(request)
|
||||||
|
|
||||||
# TODO : Get template for user
|
# TODO : Get template for user
|
||||||
definition = json.loads(open("report_weekly.json").read())
|
definition = ReportTemplates.get_template("weekly")
|
||||||
|
|
||||||
# Get the latest year and week
|
# Get the latest year and week
|
||||||
latest = Berichtsheft.objects.filter(user=user).order_by('-year', '-week').first()
|
latest = user.reports().order_by("-year", "-week").first()
|
||||||
if latest is not None:
|
if latest is not None:
|
||||||
current_year, current_week = next_date(latest.year, latest.week)
|
current_year, current_week = next_date(latest.year, latest.week)
|
||||||
else:
|
else:
|
||||||
current_year, current_week, _ = datetime.datetime.today().isocalendar()
|
current_year, current_week, _ = datetime.datetime.today().isocalendar()
|
||||||
|
|
||||||
# Get cookies for persistent saves
|
start_date, end_date = get_week_range(current_year, current_week)
|
||||||
|
|
||||||
|
if latest is not None:
|
||||||
|
current_num = latest.num + 1
|
||||||
|
else:
|
||||||
|
current_num = 1
|
||||||
|
|
||||||
|
# TODO : Cookies for persistent saves
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"write.html",
|
||||||
|
{
|
||||||
|
"user": user,
|
||||||
|
"year": current_year,
|
||||||
|
"week": current_week,
|
||||||
|
"start_date": start_date,
|
||||||
|
"end_date": end_date,
|
||||||
|
"current_num": current_num,
|
||||||
|
"definition": definition,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return render(request, "write.html", {
|
|
||||||
"user": user,
|
|
||||||
"year": current_year,
|
|
||||||
"week": current_week,
|
|
||||||
"definition": definition
|
|
||||||
})
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
user = AzureUser(request)
|
user = AzureUser(request)
|
||||||
|
|
||||||
# Get all berichtshefte
|
# Get all berichtshefte
|
||||||
all_reports = Berichtsheft.objects.filter(user=user)
|
all_reports = user.reports()
|
||||||
|
|
||||||
return render(request, "index.html", {"user": user, "reports": all_reports})
|
return render(request, "index.html", {"user": user, "reports": all_reports})
|
||||||
|
|
||||||
|
|
||||||
def test(request):
|
def test(request):
|
||||||
return render(request, "test.html", {})
|
return render(request, "test.html", {})
|
|
@ -6,7 +6,7 @@ import sys
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'azube.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azube.settings")
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
@ -18,5 +18,5 @@ def main():
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
{
|
|
||||||
"vars": [
|
|
||||||
{
|
|
||||||
"name": "name",
|
|
||||||
"display_name": "Name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "num_doc",
|
|
||||||
"display_name": "Berichtsheft Nummer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "year",
|
|
||||||
"display_name": "Jahr"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "week",
|
|
||||||
"display_name": "Kalenderwoche"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "start_date",
|
|
||||||
"display_name": "Von"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "end_date",
|
|
||||||
"display_name": "bis"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "department",
|
|
||||||
"display_name": "Abteilung"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "company_text",
|
|
||||||
"display_name": "Betriebliche Tätigkeiten"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "week_topic",
|
|
||||||
"display_name": "Thema der Woche"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "school_text",
|
|
||||||
"display_name": "Berufsschule"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue