From 583a70b2c8a057d90cfc63be13a5f31509958efc Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 27 May 2024 17:58:37 +0200 Subject: [PATCH] refactor(feedback): get party info from pages --- shiftregister/feedback/templates/feedback.html | 16 +++++++--------- shiftregister/feedback/views.py | 7 ++++++- shiftregister/pages/default_content/party.html | 9 +++++++++ .../pages/management/commands/importhtml.py | 16 +++++++++++++--- 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 shiftregister/pages/default_content/party.html diff --git a/shiftregister/feedback/templates/feedback.html b/shiftregister/feedback/templates/feedback.html index 28c936e..47050c7 100644 --- a/shiftregister/feedback/templates/feedback.html +++ b/shiftregister/feedback/templates/feedback.html @@ -3,17 +3,15 @@ {% block title %}Danke :){% endblock %} {% block content %} -
-

Randdaten zum Helfer*innen-Fest

- -
+{% if party_info %} +{% autoescape off %} +{{ party_info }} +{% endautoescape %}
+{% endif %}
- Bitte teil uns hierüber mit, ob du kommst. Vergiss nicht, deine Angaben mit dem Speichern-Button unten abzuschicken. + Bitte teil uns hierüber mit, ob du zum Helfer*innen-Fest kommst. + Vergiss nicht, deine Angaben mit dem Speichern-Button unten abzuschicken.
{% csrf_token %} diff --git a/shiftregister/feedback/views.py b/shiftregister/feedback/views.py index 6f95479..0cb62dd 100644 --- a/shiftregister/feedback/views.py +++ b/shiftregister/feedback/views.py @@ -3,6 +3,7 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import get_object_or_404, render from shiftregister.app.models import LoginToken +from shiftregister.pages.models import Page from .forms import FeedbackForm from .models import Feedback, ShareToken @@ -31,7 +32,11 @@ def feedback(request, token): "Deine Angaben wurden gespeichert.", ) - return render(request, "feedback.html", {"form": form}) + party_info = None + if p := Page.objects.filter(title__iexact="party", kind=Page.REGULAR).first(): + party_info = p.content + + return render(request, "feedback.html", {"form": form, "party_info": party_info}) @login_required diff --git a/shiftregister/pages/default_content/party.html b/shiftregister/pages/default_content/party.html new file mode 100644 index 0000000..5f0b436 --- /dev/null +++ b/shiftregister/pages/default_content/party.html @@ -0,0 +1,9 @@ + +
+

Randdaten zum Helfer*innen-Fest

+
    +
  • Wo? Auf dem Festivalgelände
  • +
  • Wann? Samstag, TBD um 17 Uhr
  • +
  • Was? Fleischfreies Grillen (Alle bringen was mit), Getränke gehen auf uns und Musik haben wir
  • +
+
diff --git a/shiftregister/pages/management/commands/importhtml.py b/shiftregister/pages/management/commands/importhtml.py index e530db4..e8f788c 100644 --- a/shiftregister/pages/management/commands/importhtml.py +++ b/shiftregister/pages/management/commands/importhtml.py @@ -11,25 +11,35 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "--force", - action="store_true", - help="Always overwrite content", + "-f", "--force", action="store_true", help="Always overwrite content" ) + parser.add_argument("pages", help="Specify which pages to import", nargs="*") def handle(self, *args, **options): content_path = Path(__file__).resolve().parent.parent.parent / "default_content" for file in content_path.iterdir(): + if (pages := options["pages"]) and file.stem not in pages: + continue + slug = file.stem p, created = Page.objects.get_or_create(url=slug) if (not created) and (not options["force"]): continue soup = BeautifulSoup(file.read_text(), "html.parser") + if soup.title: p.title = soup.title.string soup.title.decompose() else: p.title = slug.title() + + if visible := soup.find("meta", attrs={"name": "visible"}): + p.visible = "content" not in visible.attrs or visible.attrs[ + "content" + ].lower() in ("1", "true", "yes") + visible.decompose() + p.content = str(soup).strip() p.save() print(f'created new page "{p.title}" for slug {slug}')