work+htmx
This commit is contained in:
parent
34f3367a08
commit
d248c99242
11 changed files with 111 additions and 29 deletions
|
@ -1,8 +1,10 @@
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from core.models import Berichtsheft
|
from core.models import Berichtsheft
|
||||||
from core.reports import DailyReport, WeeklyReport
|
from core.reports import DailyReport, WeeklyReport
|
||||||
|
import core.util
|
||||||
|
|
||||||
|
|
||||||
class AzureUser:
|
class AzureUser:
|
||||||
|
@ -33,7 +35,7 @@ class AzureUser:
|
||||||
self.id = "anon"
|
self.id = "anon"
|
||||||
|
|
||||||
def reports(self):
|
def reports(self):
|
||||||
return Berichtsheft.objects.filter(user=self.id)
|
return Berichtsheft.objects.filter(user=self.id).order_by("-year", "-week")
|
||||||
|
|
||||||
def get_report_kind(self):
|
def get_report_kind(self):
|
||||||
# TODO : Implement
|
# TODO : Implement
|
||||||
|
@ -45,3 +47,19 @@ class AzureUser:
|
||||||
return WeeklyReport(request)
|
return WeeklyReport(request)
|
||||||
case "daily":
|
case "daily":
|
||||||
return DailyReport(request)
|
return DailyReport(request)
|
||||||
|
|
||||||
|
def latest_report(self):
|
||||||
|
return self.reports().order_by("-year", "-week").first()
|
||||||
|
|
||||||
|
def late_reports(self) -> int:
|
||||||
|
year_now, week_now, _ = datetime.datetime.today().isocalendar()
|
||||||
|
count = 0
|
||||||
|
latest = self.latest_report()
|
||||||
|
|
||||||
|
new_year, new_week = (latest.year, latest.week)
|
||||||
|
|
||||||
|
while week_now != new_week or (week_now == new_week and year_now != new_year):
|
||||||
|
count += 1
|
||||||
|
new_year, new_week = core.util.next_date(new_year, new_week)
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Berichtsheft(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Berichtsheft: {self.user}, Year: {self.year}, Week: {self.week}"
|
return f"Berichtsheft: {self.user}, Year: {self.year}, Week: {self.week}"
|
||||||
|
|
||||||
|
@property
|
||||||
def is_approved(self):
|
def is_approved(self):
|
||||||
approvals = Approval.objects.filter(report=self.id)
|
approvals = Approval.objects.filter(report=self.id)
|
||||||
return len(approvals) >= 2
|
return len(approvals) >= 2
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
STYLE = {
|
STYLE = {
|
||||||
"red_btn": "text-white bg-red-700 hover:bg-red-800 focus:outline-none focus:ring-4 focus:ring-red-300 font-medium rounded-full text-sm px-5 py-2.5 text-center me-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900",
|
"red_btn": "text-white bg-red-700 hover:bg-red-800 focus:outline-none focus:ring-4 focus:ring-red-300 font-medium rounded-full text-sm px-5 py-2.5 text-center me-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 dark:focus:ring-red-900",
|
||||||
"card": "bg-white drop-shadow-md p-6 mx-auto my-10 aspect-[2/3] hover:drop-shadow-xl hover:scale-[0.95] scale-[0.9] transition-all duration-50 transform ease-in-out",
|
"card": "bg-white drop-shadow-md p-6 mx-auto my-10 aspect-[2/3] hover:drop-shadow-xl hover:scale-[0.95] scale-[0.9] transition-all duration-50 transform ease-in-out w-80",
|
||||||
}
|
}
|
||||||
|
|
9
core/templates/component/report.html
Executable file
9
core/templates/component/report.html
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
<a href="/report/{{ report.id }}" class="{{ style.card }}">
|
||||||
|
{% if report.is_approved %}
|
||||||
|
<div
|
||||||
|
class="absolute top-0 right-0 translate-y-3 -translate-x-3 bg-green-500 text-white rounded-full w-6 h-6 flex items-center justify-center scale-[1.5]"
|
||||||
|
>
|
||||||
|
✓
|
||||||
|
</div>
|
||||||
|
{% endif %} {{ report }}
|
||||||
|
</a>
|
2
core/templates/head.html
Executable file
2
core/templates/head.html
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<script src="https://unpkg.com/htmx.org@2.0.3" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous"></script>
|
12
core/templates/htmx/reports.html
Executable file
12
core/templates/htmx/reports.html
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
{% if reports|length != 0 %}
|
||||||
|
{% for report in reports %}
|
||||||
|
|
||||||
|
{% include 'component/report.html' with report=report %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div hx-get="/reports?page={{ next }}"
|
||||||
|
hx-trigger="revealed"
|
||||||
|
hx-swap="outerHTML">
|
||||||
|
|
||||||
|
{% endif %}
|
|
@ -1,43 +1,50 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Azube</title>
|
<title>Azube</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
{% include 'head.html' %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{ user.display_name }}
|
<div class="bg-gray-100 min-h-screen">
|
||||||
|
|
||||||
<div class="bg-gray-100">
|
|
||||||
<h1 class="text-2xl justify-center flex pt-5">Deine Berichtshefte</h1>
|
<h1 class="text-2xl justify-center flex pt-5">Deine Berichtshefte</h1>
|
||||||
|
|
||||||
|
{% if late_reports > 1 %}
|
||||||
|
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 mr-10 ml-10 mt-6" role="alert">
|
||||||
|
<p class="font-bold"> Du bist nicht aktuell! </p>
|
||||||
|
<p> Du hast noch {{ late_reports }} Berichtshefte nachzuschreiben. </p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if reports|length == 0 %}
|
{% if reports|length == 0 %}
|
||||||
|
|
||||||
<h3>wau, such empty!</h3>
|
<h3 class="text-xl justify-center flex m-10 p-5">wau, such empty!</h3>
|
||||||
|
|
||||||
<button onclick="location = '/write'" class="{{ style.red_btn }}">
|
<button onclick="location = '/write'" class="{{ style.red_btn }} justify-center">
|
||||||
Füge dein erstes Berichtsheft hinzu!
|
Füge dein erstes Berichtsheft hinzu!
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="min-h-screen flex items-center justify-center grid grid-cols-5"
|
class="mb-5 flex items-center justify-center grid lg:grid-cols-6 md:grid-cols-3"
|
||||||
>
|
>
|
||||||
{% for report in reports %}
|
{% for report in reports %}
|
||||||
|
|
||||||
<a href="/report/{{ report.id }}" class="{{ style.card }}">
|
{% if forloop.first %} {% if report.week != week_now %}
|
||||||
{% if approved %}
|
<a href="/write" class="{{ style.card }} flex items-center justify-center" title="Neues Berichtsheft">
|
||||||
<div
|
<span class="text-9xl font-bold"> + </span>
|
||||||
class="absolute top-0 right-0 translate-y-3 -translate-x-3 bg-green-500 text-white rounded-full w-6 h-6 flex items-center justify-center scale-[1.5]"
|
|
||||||
>
|
|
||||||
✓
|
|
||||||
</div>
|
|
||||||
{% endif %} {{ report }}
|
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %} {% endif %}
|
||||||
|
|
||||||
|
{% include 'component/report.html' with report=report %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<div hx-get="/reports?page=2"
|
||||||
|
hx-trigger="revealed"
|
||||||
|
hx-swap="outerHTML">
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if forloop.last %} {% if report.week != week_now %}
|
|
||||||
<button onclick="location = '/write'" class="{{ style.red_btn }}">
|
|
||||||
Berichtsheft schreiben
|
|
||||||
</button>
|
|
||||||
{% endif %} {% endif %} {% endfor %} {% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title> Berichtsheft {{ report.num }} </title>
|
<title> Berichtsheft {{ report.num }} </title>
|
||||||
|
{% include 'head.html' %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1> Berichtsheft {{ report.num }} </h1>
|
<h1> Berichtsheft {{ report.num }} </h1>
|
||||||
|
|
||||||
<p> Berichtsheft {{ report.year }} / {{ report.week }} </p>
|
<p> Berichtsheft {{ report.year }} / {{ report.week }} </p>
|
||||||
|
|
||||||
<p> Is Approved ? {{ approved }} </p>
|
<p> Is Approved ? {{ report.is_approved }} </p>
|
||||||
|
|
||||||
{% for key, value in report.content.items %}
|
{% for key, value in report.content.items %}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Neues Berichtsheft</title>
|
<title>Neues Berichtsheft</title>
|
||||||
|
{% include 'head.html' %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Neues Berichtsheft</h1>
|
<h1>Neues Berichtsheft</h1>
|
||||||
|
|
|
@ -5,4 +5,5 @@ 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("report/<int:report_id>", views.report_detail_page, name="report_detail"),
|
path("report/<int:report_id>", views.report_detail_page, name="report_detail"),
|
||||||
|
path("reports", views.reports_list, name="reports_list"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from core.util import get_week_range, next_date
|
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
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from core.styles import STYLE
|
from core.styles import STYLE
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
@ -22,6 +23,9 @@ def write_new_report_post(request):
|
||||||
|
|
||||||
report_form = user.get_report_kind_form(request.POST)
|
report_form = user.get_report_kind_form(request.POST)
|
||||||
|
|
||||||
|
if not report_form.is_valid():
|
||||||
|
return HttpResponse("Bad Request", status=400)
|
||||||
|
|
||||||
# TODO : Implement values
|
# TODO : Implement values
|
||||||
|
|
||||||
current_year, current_week, _, _, current_num = get_current_report_values(
|
current_year, current_week, _, _, current_num = get_current_report_values(
|
||||||
|
@ -65,7 +69,7 @@ def write_new_report_get(request):
|
||||||
report_kind = user.get_report_kind()
|
report_kind = user.get_report_kind()
|
||||||
|
|
||||||
# Get the latest year and week
|
# Get the latest year and week
|
||||||
latest = user.reports().order_by("-year", "-week").first()
|
latest = user.latest_report()
|
||||||
|
|
||||||
year_now, week_now, _ = datetime.datetime.today().isocalendar()
|
year_now, week_now, _ = datetime.datetime.today().isocalendar()
|
||||||
|
|
||||||
|
@ -102,14 +106,42 @@ def index(request):
|
||||||
user = AzureUser(request)
|
user = AzureUser(request)
|
||||||
|
|
||||||
# Get all berichtshefte
|
# Get all berichtshefte
|
||||||
all_reports = user.reports()
|
reports = Paginator(user.reports(), 30).get_page(1)
|
||||||
|
|
||||||
year_now, week_now, _ = datetime.datetime.today().isocalendar()
|
year_now, week_now, _ = datetime.datetime.today().isocalendar()
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"index.html",
|
"index.html",
|
||||||
{"user": user, "reports": all_reports, "week_now": week_now, "style": STYLE},
|
{
|
||||||
|
"user": user,
|
||||||
|
"reports": reports,
|
||||||
|
"week_now": week_now,
|
||||||
|
"late_reports": user.late_reports(),
|
||||||
|
"style": STYLE,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def reports_list(request):
|
||||||
|
user = AzureUser(request)
|
||||||
|
|
||||||
|
p = Paginator(user.reports(), 30)
|
||||||
|
|
||||||
|
try:
|
||||||
|
page_num = int(request.GET.get("page"))
|
||||||
|
except:
|
||||||
|
return HttpResponse("Page should be a number", 400)
|
||||||
|
|
||||||
|
if p.num_pages >= page_num:
|
||||||
|
objs = p.get_page(page_num)
|
||||||
|
else:
|
||||||
|
objs = []
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
"htmx/reports.html",
|
||||||
|
{"reports": objs, "next": page_num + 1, "style": STYLE},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +153,4 @@ def report_detail_page(request, report_id):
|
||||||
if report.user != user.id:
|
if report.user != user.id:
|
||||||
return HttpResponse("Nah", status=401)
|
return HttpResponse("Nah", status=401)
|
||||||
|
|
||||||
return render(
|
return render(request, "report.html", {"report": report})
|
||||||
request, "report.html", {"report": report, "approved": report.is_approved()}
|
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue