report post
This commit is contained in:
parent
d14464fdfd
commit
638ae328ea
5 changed files with 42 additions and 7 deletions
|
@ -2,6 +2,7 @@ import json
|
|||
import base64
|
||||
|
||||
from core.models import Berichtsheft
|
||||
from core.report_templates import ReportTemplates
|
||||
|
||||
|
||||
class AzureUser:
|
||||
|
@ -33,3 +34,7 @@ class AzureUser:
|
|||
|
||||
def reports(self):
|
||||
return Berichtsheft.objects.filter(user=self.id)
|
||||
|
||||
def get_report_template(self):
|
||||
# TODO : Implement
|
||||
return ReportTemplates.get_template("weekly")
|
||||
|
|
5
core/forms.py
Executable file
5
core/forms.py
Executable file
|
@ -0,0 +1,5 @@
|
|||
def extract_post_values(post, vars) -> dict:
|
||||
res = {}
|
||||
for var in vars:
|
||||
res[var["name"]] = post.get(var["name"], "")
|
||||
return res
|
|
@ -31,9 +31,7 @@ class Berichtsheft(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
f"Berichtsheft: {self.user.username}, Year: {self.year}, Week: {self.week}"
|
||||
)
|
||||
return f"Berichtsheft: {self.user}, Year: {self.year}, Week: {self.week}"
|
||||
|
||||
|
||||
class Approval:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.shortcuts import render
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from core.forms import extract_post_values
|
||||
from core.report_templates import ReportTemplates
|
||||
from core.util import get_week_range, next_date
|
||||
from .azure_auth import AzureUser
|
||||
|
@ -10,10 +11,36 @@ import datetime
|
|||
|
||||
|
||||
def write_new_report(request):
|
||||
if request.method == "POST":
|
||||
return write_new_report_post(request)
|
||||
else:
|
||||
return write_new_report_get(request)
|
||||
|
||||
|
||||
def write_new_report_post(request):
|
||||
user = AzureUser(request)
|
||||
|
||||
# TODO : Get template for user
|
||||
definition = ReportTemplates.get_template("weekly")
|
||||
definition = user.get_report_template()
|
||||
|
||||
values = extract_post_values(request.POST, definition["vars"])
|
||||
|
||||
# TODO : Input Validation
|
||||
|
||||
report = Berichtsheft(
|
||||
user=user.id,
|
||||
num=int(values.pop("num_doc", "")),
|
||||
year=int(values.pop("year", "")),
|
||||
week=int(values.pop("week", "")),
|
||||
content=values,
|
||||
)
|
||||
report.save()
|
||||
return redirect("/")
|
||||
|
||||
|
||||
def write_new_report_get(request):
|
||||
user = AzureUser(request)
|
||||
|
||||
definition = user.get_report_template()
|
||||
|
||||
# Get the latest year and week
|
||||
latest = user.reports().order_by("-year", "-week").first()
|
||||
|
|
Loading…
Add table
Reference in a new issue