Skip to content

Commit 3d00c19

Browse files
committed
Save form in UpdateTemplateView
- Fixes image not being passed around correctly - Update list urls to point to root
1 parent 80932a6 commit 3d00c19

File tree

4 files changed

+73
-78
lines changed

4 files changed

+73
-78
lines changed

chords/locale/cs/LC_MESSAGES/django.po

+41-36
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2024-12-27 20:43+0100\n"
11+
"POT-Creation-Date: 2024-12-28 18:50+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -155,48 +155,48 @@ msgstr "Písnička"
155155
msgid "Songs"
156156
msgstr "Písničky"
157157

158-
#: backend/templates/songs/index.html:27
158+
#: backend/templates/songs/index.html:25
159159
msgid "Hide chords"
160160
msgstr "Skrýt akordy"
161161

162-
#: backend/templates/songs/index.html:33
162+
#: backend/templates/songs/index.html:31
163163
msgid "Prevent sleep"
164164
msgstr "Zabránit uspání"
165165

166-
#: backend/templates/songs/index.html:39
166+
#: backend/templates/songs/index.html:37
167167
msgid "Single page"
168168
msgstr "Bez stránek"
169169

170-
#: backend/templates/songs/index.html:64
170+
#: backend/templates/songs/index.html:62
171171
#: category/templates/category/list.html:21
172172
#: pdf/templates/pdf/files/list.html:30
173173
#: pdf/templates/pdf/templates/list.html:36
174174
msgid "Actions"
175175
msgstr "Akce"
176176

177-
#: backend/templates/songs/index.html:69
177+
#: backend/templates/songs/index.html:67
178178
#: category/templates/category/list.html:55
179179
#: pdf/templates/pdf/files/list.html:56
180180
#: pdf/templates/pdf/templates/list.html:73
181181
msgid "Edit"
182182
msgstr "Upravit"
183183

184-
#: backend/templates/songs/index.html:72
184+
#: backend/templates/songs/index.html:70
185185
#: category/templates/category/list.html:74
186186
#: pdf/templates/pdf/files/list.html:71
187187
#: pdf/templates/pdf/templates/list.html:83
188188
msgid "Delete"
189189
msgstr "Smazat"
190190

191-
#: backend/templates/songs/index.html:86
191+
#: backend/templates/songs/index.html:83
192192
msgid "Transpose"
193193
msgstr "Transponovat"
194194

195-
#: backend/templates/songs/index.html:105
195+
#: backend/templates/songs/index.html:101
196196
msgid "Search"
197197
msgstr "Vyhledávání"
198198

199-
#: backend/templates/songs/index.html:107
199+
#: backend/templates/songs/index.html:102
200200
msgid "Number, text or author"
201201
msgstr "Číslo, text nebo autor"
202202

@@ -229,7 +229,7 @@ msgid "Category"
229229
msgstr "Kategorie"
230230

231231
#: category/templates/category/list.html:14
232-
#: frontend/templates/base/index.html:82 pdf/models/__init__.py:54
232+
#: frontend/templates/base/index.html:81 pdf/models/__init__.py:54
233233
msgid "Language"
234234
msgstr "Jazyk"
235235

@@ -332,7 +332,7 @@ msgstr "Zpátky domů"
332332
msgid "URL %(request_path)s does not exist."
333333
msgstr "URL %(request_path)s neexistuje."
334334

335-
#: frontend/templates/base/error.html:8
335+
#: frontend/templates/base/error.html:7
336336
msgid "Not found"
337337
msgstr "Nenalezeno"
338338

@@ -341,27 +341,27 @@ msgstr "Nenalezeno"
341341
msgid "Submit"
342342
msgstr "Odeslat"
343343

344-
#: frontend/templates/base/index.html:38 tenants/models.py:44
344+
#: frontend/templates/base/index.html:37 tenants/models.py:44
345345
msgid "Logo"
346346
msgstr ""
347347

348-
#: frontend/templates/base/index.html:72
348+
#: frontend/templates/base/index.html:71
349349
msgid "Options"
350350
msgstr "Možnosti"
351351

352-
#: frontend/templates/base/index.html:101
352+
#: frontend/templates/base/index.html:100
353353
msgid "Version"
354354
msgstr "Verze"
355355

356-
#: frontend/templates/base/index.html:102
356+
#: frontend/templates/base/index.html:101
357357
msgid "Git"
358358
msgstr ""
359359

360-
#: frontend/templates/base/index.html:110
360+
#: frontend/templates/base/index.html:109
361361
msgid "Logged as"
362362
msgstr "Přihlášen jako"
363363

364-
#: frontend/templates/base/index.html:112
364+
#: frontend/templates/base/index.html:111
365365
msgid "Log in"
366366
msgstr "Přihlásit se"
367367

@@ -383,22 +383,22 @@ msgstr "Ne"
383383
msgid "Yes"
384384
msgstr "Ano"
385385

386-
#: frontend/templates/markdownx/widget.html:8
386+
#: frontend/templates/markdownx/widget.html:10
387+
msgid "Preview"
388+
msgstr "Náhled"
389+
390+
#: frontend/templates/markdownx/widget.html:17
387391
msgid "Help"
388392
msgstr "Nápověda"
389393

390-
#: frontend/templates/markdownx/widget.html:10
394+
#: frontend/templates/markdownx/widget.html:19
391395
msgid "Displays chord"
392396
msgstr "Zobrazí akord"
393397

394-
#: frontend/templates/markdownx/widget.html:11
398+
#: frontend/templates/markdownx/widget.html:20
395399
msgid "Adds N empty spaces"
396400
msgstr "Přidá N mezer"
397401

398-
#: frontend/templates/markdownx/widget.html:18
399-
msgid "Preview"
400-
msgstr "Náhled"
401-
402402
#: frontend/templates/registration/login.html:4
403403
#: frontend/templates/registration/login.html:5
404404
msgid "Login"
@@ -649,7 +649,7 @@ msgstr "Postup"
649649
msgid "Back to all files"
650650
msgstr "Zpátky na seznam souborů"
651651

652-
#: pdf/templates/pdf/index.html:45
652+
#: pdf/templates/pdf/index.html:44
653653
msgid "Table of Contents"
654654
msgstr "Obsah"
655655

@@ -662,15 +662,15 @@ msgstr "Pořadí písniček"
662662
msgid "Please, choose song order and their numbers"
663663
msgstr "Zvolte prosím pořadí písniček a jejich čísla"
664664

665-
#: pdf/templates/pdf/templates/assign.html:23
665+
#: pdf/templates/pdf/templates/assign.html:20
666666
msgid "Song numbers"
667667
msgstr "Čísla písniček"
668668

669-
#: pdf/templates/pdf/templates/assign.html:37
669+
#: pdf/templates/pdf/templates/assign.html:34
670670
msgid "Sort by name"
671671
msgstr "Seřadit podle jména"
672672

673-
#: pdf/templates/pdf/templates/assign.html:38
673+
#: pdf/templates/pdf/templates/assign.html:35
674674
msgid "Finish"
675675
msgstr "Dokončit"
676676

@@ -682,28 +682,28 @@ msgstr "Přidat Šablonu"
682682
msgid "Generate"
683683
msgstr "Generovat"
684684

685+
#: pdf/templates/pdf/templates/select.html:8
685686
#: pdf/templates/pdf/templates/select.html:9
686-
#: pdf/templates/pdf/templates/select.html:10
687687
msgid "Create new File Template"
688688
msgstr "Vytvořit novou Šablonu"
689689

690-
#: pdf/templates/pdf/templates/select.html:26
690+
#: pdf/templates/pdf/templates/select.html:25
691691
msgid ""
692692
"Please enter file configuration option and select which songs you would like "
693693
"to include"
694694
msgstr ""
695695
"Prosím vyplňte parametry PDF souboru a vyberte písničky, které má soubor "
696696
"obsahovat"
697697

698-
#: pdf/templates/pdf/templates/select.html:93
698+
#: pdf/templates/pdf/templates/select.html:92
699699
msgid "Select All"
700700
msgstr "Vybrat všechny"
701701

702-
#: pdf/templates/pdf/templates/select.html:100
702+
#: pdf/templates/pdf/templates/select.html:99
703703
msgid "Deselect all"
704704
msgstr "Zrušit výběr"
705705

706-
#: pdf/templates/pdf/templates/select.html:105
706+
#: pdf/templates/pdf/templates/select.html:104
707707
msgid "Finish selecting"
708708
msgstr "Dokončit výběr"
709709

@@ -717,16 +717,21 @@ msgstr "Jiný Soubor (%(id)s) for %(name)s je již ve frontě"
717717
msgid "Scheduled File (%(id)s) generation from template %(template)s"
718718
msgstr "Generování souboru (%(id)s) ze šablony %(template)s bylo naplánováno"
719719

720-
#: pdf/views/templates.py:171
720+
#: pdf/views/templates.py:141
721721
#, python-format
722722
msgid "File Template '%(name)s' was successfully updated"
723723
msgstr "Šablona %(name)s byla úspěšně upravena"
724724

725-
#: pdf/views/templates.py:176
725+
#: pdf/views/templates.py:146
726726
#, python-format
727727
msgid "File Template '%(name)s' was successfully created"
728728
msgstr "Šablona %(name)s byl úspěšně vytvořena"
729729

730+
#: pdf/views/templates.py:174
731+
#, python-format
732+
msgid "Songs in File Template '%(name)s' were successfully updated"
733+
msgstr "Písničky Šablony %(name)s byly úspěšně upraveny"
734+
730735
#: tenants/admin.py:21 tenants/models.py:58
731736
msgid "Tenant"
732737
msgstr "Zpěvník"

pdf/templates/pdf/templates/assign.html

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313

1414
{% block framed_body %}
1515
<p class="text-center fw-bold">{% trans "Please, choose song order and their numbers" %}</p>
16-
<form method="post" action="{{ action }}">
16+
<form method="post" action="{{ action }}" enctype="multipart/form-data">
1717
{% csrf_token %}
18-
<div class="d-none">
19-
{% bootstrap_form form %}
20-
</div>
2118
{{ formset.management_form }}
2219
{{ formset.non_form_errors.as_ul }}
2320
<h4>{% trans "Song numbers" %}</h4>
@@ -36,8 +33,8 @@ <h4>{% trans "Song numbers" %}</h4>
3633

3734
{% bootstrap_button _("Sort by name") button_type="button" button_class="btn-secondary" id="sort"%}
3835
{% bootstrap_button _("Finish") button_type="submit"%}
36+
{{ form.media }}
3937
</form>
40-
{{ form.media }}
4138
<script type="module">
4239
const sortable = $('#sortable')
4340
function reassign_numbers() {

pdf/urls.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
)
2020

2121
template_patterns = [
22-
path("list", TemplateListView.as_view(), name="list"),
22+
path("", TemplateListView.as_view(), name="list"),
2323
path("new", UpdateTemplateView.as_view(), name="new"),
2424
path("edit/<int:pk>", UpdateTemplateView.as_view(), name="edit"),
2525
path("delete/<int:pk>", TemplateDeleteView.as_view(), name="delete"),
26-
path("assign", TemplateNumberSelectView.as_view(), name="assign"),
2726
path("assign/<int:pk>", TemplateNumberSelectView.as_view(), name="assign"),
2827
path("<int:pk>/generate", GenerateFromTemplateView.as_view(), name="generate"),
2928
path("move", MovePDFTemplatesView.as_view(), name="move"),
@@ -34,7 +33,7 @@
3433
path("info/<int:pk>", RenderInfoView.as_view(), name="info"),
3534
path("delete/<int:pk>", FileDeleteView.as_view(), name="delete"),
3635
path("edit/<int:pk>", FileUpdateView.as_view(), name="edit"),
37-
path("list", FileListView.as_view(), name="list"),
36+
path("", FileListView.as_view(), name="list"),
3837
]
3938

4039
urlpatterns = [

pdf/views/templates.py

+28-34
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,17 @@ class TemplateNumberingMixin:
7676

7777
PDFSongFormset = formset_factory(PDFSongForm, formset=BasePDFSongFormset, min_num=1, validate_min=True, extra=0)
7878

79-
def render_assign_template(self, form, formset=None, songs: Iterable[Song] | None = None):
79+
def render_assign_template(self, pk=None, formset=None, songs: Iterable[Song] | None = None):
8080
"""Renders assign template"""
8181
formset = formset or self.PDFSongFormset(
8282
prefix="songs",
8383
initial=[
8484
{"name": song.name, "song_number": number, "song": song} for number, song in enumerate(songs, start=1)
8585
],
8686
)
87-
if "pk" in self.kwargs:
88-
assign_url = reverse("pdf:templates:assign", kwargs={"pk": self.kwargs.get("pk")})
89-
else:
90-
assign_url = reverse("pdf:templates:assign")
91-
return render(
92-
self.request, "pdf/templates/assign.html", {"form": form, "formset": formset, "action": assign_url}
93-
)
87+
pk = pk or self.kwargs.get("pk")
88+
assign_url = reverse("pdf:templates:assign", kwargs={"pk": pk})
89+
return render(self.request, "pdf/templates/assign.html", {"formset": formset, "action": assign_url})
9490

9591

9692
class UpdateTemplateView(LocalAdminRequired, TemplateNumberingMixin, TemplateView):
@@ -135,7 +131,21 @@ def post(self, request, *args, **kwargs):
135131
template_form = ManualTemplateForm(self.request.POST, request.FILES, prefix=self.PREFIX)
136132
songs_form = SongSelectionForm(self.request.POST, request.FILES, request=self.request)
137133
if template_form.is_valid() and songs_form.is_valid():
138-
return self.render_assign_template(template_form, songs=songs_form.cleaned_data["songs"])
134+
template = template_form.instance
135+
template.tenant = self.request.tenant
136+
template.pdftemplate_ptr_id = self.kwargs.get("pk", None)
137+
template_form.save()
138+
if "pk" in self.kwargs:
139+
messages.success(
140+
self.request,
141+
_("File Template '%(name)s' was successfully updated") % {"name": template.name},
142+
)
143+
else:
144+
messages.success(
145+
self.request,
146+
_("File Template '%(name)s' was successfully created") % {"name": template.name},
147+
)
148+
return self.render_assign_template(pk=template_form.instance.pk, songs=songs_form.cleaned_data["songs"])
139149
return self.render_to_response(self.get_context_data(template_form=template_form, songs_form=songs_form))
140150

141151

@@ -146,38 +156,22 @@ class TemplateNumberSelectView(LocalAdminRequired, TemplateNumberingMixin, View)
146156

147157
def get(self, *args, **kwargs):
148158
"""Redirect back to the start of the process"""
149-
if "pk" in self.kwargs:
150-
return redirect(reverse("pdf:templates:edit", kwargs={"pk": self.kwargs.get("pk")}))
151-
return redirect(reverse("pdf:templates:new"))
159+
return redirect(reverse("pdf:templates:edit", kwargs={"pk": self.kwargs.get("pk")}))
152160

153161
# pylint: disable=unused-argument
154-
def post(self, template, *args, **kwargs):
162+
def post(self, request, *args, **kwargs):
155163
"""POST request method handler"""
156-
form = ManualTemplateForm(self.request.POST, template.FILES, prefix="template")
164+
template = ManualPDFTemplate.objects.get(pk=self.kwargs["pk"])
157165
formset = self.PDFSongFormset(self.request.POST, prefix="songs")
158-
if form.is_valid() and formset.is_valid():
159-
template = form.instance
160-
template.tenant = self.request.tenant
161-
template.pdftemplate_ptr_id = self.kwargs.get("pk", None)
166+
if formset.is_valid():
162167
with transaction.atomic():
163-
form.save()
164168
template.songs.clear()
165169
for form in formset:
166170
form.instance.request = template
167171
form.save()
168-
if "pk" in self.kwargs:
169-
messages.success(
170-
self.request,
171-
_("File Template '%(name)s' was successfully updated") % {"name": template.name},
172-
)
173-
else:
174-
messages.success(
175-
self.request,
176-
_("File Template '%(name)s' was successfully created") % {"name": template.name},
177-
)
172+
messages.success(
173+
self.request,
174+
_("Songs in File Template '%(name)s' were successfully updated") % {"name": template.name},
175+
)
178176
return redirect("pdf:templates:list")
179-
return self.form_invalid(form, formset)
180-
181-
def form_invalid(self, form, formset):
182-
"""If the form is invalid, render the invalid form."""
183-
return self.render_assign_template(form, formset)
177+
return self.render_assign_template(formset)

0 commit comments

Comments
 (0)