azube/core/reports.py

197 lines
6 KiB
Python
Raw Permalink Normal View History

2024-12-04 09:37:01 +01:00
from django import forms
2024-12-06 12:10:30 +01:00
from core.styles import label_span, STYLE
2024-12-04 16:36:57 +01:00
2024-12-04 09:37:01 +01:00
class WeeklyReport(forms.Form):
2024-12-04 16:36:57 +01:00
department = forms.CharField(
label=label_span("Abteilung"),
max_length=150,
widget=forms.TextInput(
attrs={
"placeholder": "Abteilung",
2024-12-06 12:10:30 +01:00
"class": STYLE["text-input"],
2024-12-04 16:36:57 +01:00
}
),
)
company_text = forms.CharField(
label=label_span("Betriebliche Tätigkeiten"),
max_length=300,
widget=forms.Textarea(
attrs={
2024-12-06 12:10:30 +01:00
"class": STYLE["text-input"],
2024-12-05 13:45:51 +01:00
"rows": 5,
2024-12-04 16:36:57 +01:00
"placeholder": "Betriebliche Tätigkeiten",
}
),
)
week_topic = forms.CharField(
label=label_span("Thema der Woche"),
max_length=600,
widget=forms.Textarea(
attrs={
2024-12-06 12:10:30 +01:00
"class": STYLE["text-input"],
2024-12-05 13:45:51 +01:00
"rows": 10,
2024-12-04 16:36:57 +01:00
"placeholder": "Thema der Woche",
}
),
)
school_text = forms.CharField(
label=label_span("Berufsschule"),
max_length=300,
widget=forms.Textarea(
attrs={
2024-12-06 12:10:30 +01:00
"class": STYLE["text-input"],
2024-12-04 16:36:57 +01:00
"rows": 5,
"placeholder": "Berufsschule",
}
),
)
2024-12-06 12:10:30 +01:00
img = forms.ImageField(
label=label_span("Bild"),
required=False,
widget=forms.ClearableFileInput(
attrs={
"class": "block w-full p-2 text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400",
"accept": "image/*",
}
),
)
@property
def display_names(self):
return {
"department": self.fields["department"].label,
"company_text": self.fields["company_text"].label,
"week_topic": self.fields["week_topic"].label,
"school_text": self.fields["school_text"].label,
}
2024-12-04 09:37:01 +01:00
def content_values(self) -> dict:
if self.is_valid():
return {
"company_text": self.cleaned_data["company_text"],
"week_topic": self.cleaned_data["week_topic"],
"school_text": self.cleaned_data["school_text"],
}
2024-12-06 12:10:30 +01:00
class DailyReport(forms.Form):
department = forms.CharField(
label=label_span("Abteilung"),
max_length=150,
widget=forms.TextInput(
attrs={
"placeholder": "Abteilung",
"class": STYLE["text-input"],
}
),
)
week_topic = forms.CharField(
label=label_span("Thema der Woche"),
max_length=600,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Thema der Woche",
}
),
)
monday_text = forms.CharField(
label=label_span("Montag"),
max_length=300,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Montag",
}
),
)
tuesday_text = forms.CharField(
label=label_span("Dienstag"),
max_length=300,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Dienstag",
}
),
)
wednesday_text = forms.CharField(
label=label_span("Mittwoch"),
max_length=300,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Mittwoch,",
}
),
)
thursday_text = forms.CharField(
label=label_span("Donnerstag"),
max_length=300,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Donnerstag",
}
),
)
friday_text = forms.CharField(
label=label_span("Freitag"),
max_length=300,
widget=forms.Textarea(
attrs={
"class": STYLE["text-input"],
"rows": 5,
"placeholder": "Freitag",
}
),
)
img = forms.ImageField(
label=label_span("Bild"),
required=False,
widget=forms.ClearableFileInput(
attrs={
"class": "block w-full p-2 text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400",
"accept": "image/*",
}
),
)
@property
def display_names(self) -> dict:
return {
"department": self.fields["department"].label,
"week_topic": self.fields["week_topic"].label,
"monday_text": self.fields["monday_text"].label,
"tuesday_text": self.fields["tuesday_text"].label,
"wednesday_text": self.fields["wednesday_text"].label,
"thursday_text": self.fields["thursday_text"].label,
"friday_text": self.fields["friday_text"].label,
}
def content_values(self) -> dict:
if self.is_valid():
return {
"week_topic": self.cleaned_data["week_topic"],
"monday_text": self.cleaned_data["monday_text"],
"tuesday_text": self.cleaned_data["tuesday_text"],
"wednesday_text": self.cleaned_data["wednesday_text"],
"thursday_text": self.cleaned_data["thursday_text"],
"friday_text": self.cleaned_data["friday_text"],
}
def choose_report_kind(kind, request=None, files=None):
match kind:
case "weekly":
return WeeklyReport(request, files)
case "daily":
return DailyReport(request, files)