Skip to content

Commit

Permalink
Rewrite all File related views
Browse files Browse the repository at this point in the history
- Add FILES.md to explain design of Files
- Change workflows/views to match FILES.md
- Fixes to individual views
- Reorganization of pdf app
- Namespaced urls
- Less util code for PDF generation
  • Loading branch information
pehala committed Dec 26, 2024
1 parent 37b8711 commit 15d55ca
Show file tree
Hide file tree
Showing 39 changed files with 1,285 additions and 968 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reformat:
$(RUN) black .

check-fuzzy:
@ for app in "backend" "pdf" "frontend" "category" "analytics" "tenants" ; do \
@ for app in "backend" "pdf" "frontend" "category" "analytics" "tenants"; do \
if [ ! -z "$$(msgattrib $${app}/locale/cs/LC_MESSAGES/django.po --only-fuzzy)" ]; then echo "$${app} app contains fuzzy strings" && exit 1; fi \
done;

Expand Down
34 changes: 17 additions & 17 deletions backend/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-22 22:15+0000\n"
"POT-Creation-Date: 2024-12-23 15:17+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -44,43 +44,35 @@ msgstr "%(class)s %(identifier)s byla úspěšně vytvořena"
msgid "Create %(class)s"
msgstr "Nová %(class)s"

#: backend/menus.py:10
#: backend/menus.py:12
msgid "Analytics"
msgstr "Statistiky"

#: backend/menus.py:11
#: backend/menus.py:13
msgid "Edit Songbook"
msgstr "Upravit zpěvník"

#: backend/menus.py:12
#: backend/menus.py:14
msgid "Django Admin"
msgstr ""

#: backend/menus.py:18
#: backend/menus.py:20
msgid "Admin"
msgstr "Administrace"

#: backend/menus.py:26
#: backend/menus.py:28
msgid "Add Song"
msgstr "Přidat Písničku"

#: backend/menus.py:27 backend/models.py:29
msgid "Categories"
msgstr "Kategorie"

#: backend/menus.py:33 backend/models.py:70
msgid "Songs"
msgstr "Písničky"

#: backend/menus.py:41
#: backend/menus.py:43
msgid "Logout"
msgstr "Odhlásit se"

#: backend/menus.py:43
#: backend/menus.py:45
msgid "Change password"
msgstr "Změna hesla"

#: backend/menus.py:50
#: backend/menus.py:52
msgid "Account"
msgstr "Účet"

Expand All @@ -100,6 +92,10 @@ msgstr "Autor"
msgid "Youtube Link"
msgstr "Odkaz na Youtube"

#: backend/models.py:29
msgid "Categories"
msgstr "Kategorie"

#: backend/models.py:30
msgid "Archived"
msgstr "Archivovat"
Expand All @@ -112,6 +108,10 @@ msgstr "Text"
msgid "Song"
msgstr "Písnička"

#: backend/models.py:70
msgid "Songs"
msgstr "Písničky"

#: backend/templates/songs/index.html:27
msgid "Hide chords"
msgstr "Skrýt akordy"
Expand Down
6 changes: 4 additions & 2 deletions backend/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from menu import MenuItem, Menu

from backend.auth import is_authenticated, is_localadmin, is_superadmin
from backend.models import Song
from category.models import Category

admin_children = (
MenuItem(_("Analytics"), reverse("analytics:index")),
Expand All @@ -24,13 +26,13 @@

songbook_children = (
MenuItem(_("Add Song"), reverse("backend:add")),
MenuItem(_("Categories"), reverse("category:list")),
MenuItem(Category._meta.verbose_name_plural, reverse("category:list")),
)

Menu.add_item(
"songbook-admin",
MenuItem(
_("Songs"),
Song._meta.verbose_name_plural,
reverse("backend:index"),
children=songbook_children,
check=is_localadmin,
Expand Down
7 changes: 3 additions & 4 deletions backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

from django.conf import settings

from pdf.utils import request_pdf_regeneration
from category.utils import request_pdf_regeneration


def regenerate_pdf(song, update: bool = False):
def regenerate_pdf(song):
"""Regenerates PDFs for each category song is in"""
for category in song.categories.all():
if category.generate_pdf:
request_pdf_regeneration(category, update)
request_pdf_regeneration(category)


def regenerate_prerender(song):
Expand Down
2 changes: 1 addition & 1 deletion backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SongUpdateView(
def post(self, request, *args, **kwargs):
response = super().post(request, *args, **kwargs)
if self.regenerate:
regenerate_pdf(self.object, True)
regenerate_pdf(self.object)
regenerate_prerender(self.object)
return response

Expand Down
8 changes: 5 additions & 3 deletions category/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.translation import gettext_lazy as _

from category.models import Category
from pdf.forms import PrependWidget
from tenants.models import Tenant


Expand All @@ -17,17 +18,18 @@ class Meta:
fields = [
"name",
"slug",
"generate_pdf",
"tenant",
"generate_pdf",
"title",
"display_name",
"filename",
"public",
"locale",
"title",
"show_date",
"image",
"margin",
"link",
]
widgets = {"filename": PrependWidget(".pdf")}


class NameForm(Form):
Expand Down
77 changes: 50 additions & 27 deletions category/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-25 17:43+0000\n"
"POT-Creation-Date: 2024-12-25 21:59+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -23,29 +23,29 @@ msgstr ""
msgid "Move Category to a different Tenant"
msgstr "Přesunout Kategorie do jiného Zpěvníku"

#: category/models.py:14 category/templates/category/list.html:11
#: category/models.py:19 category/templates/category/list.html:12
msgid "Name"
msgstr "Jméno"

#: category/models.py:15 category/templates/category/list.html:12
#: category/models.py:20 category/templates/category/list.html:13
msgid "URL pattern"
msgstr "URL vzor"

#: category/models.py:17 category/templates/category/list.html:13
#: category/models.py:22 category/templates/category/list.html:16
msgid "PDF generation"
msgstr "Automatické Generování PDF"

#: category/models.py:18
#: category/models.py:23
msgid "Should the PDF file be automatically generated when a song changes?"
msgstr ""
"Má být vygenerován pdf soubor když se nějaká písnička z kategorie změní?"

#: category/models.py:25
#: category/models.py:33
msgid "Category"
msgstr "Kategorie"

#: category/models.py:26 category/templates/category/list.html:4
#: category/templates/category/list.html:5
#: category/models.py:34 category/templates/category/list.html:5
#: category/templates/category/list.html:6
msgid "Categories"
msgstr "Kategorie"

Expand All @@ -54,47 +54,70 @@ msgid "Language"
msgstr "Jazyk"

#: category/templates/category/list.html:15
msgid "Number of songs"
msgstr "Počet písniček"

#: category/templates/category/list.html:17
msgid "Number of files"
msgstr "Počet souborů"

#: category/templates/category/list.html:18
msgid "Last file"
msgstr "Poslední soubor"

#: category/templates/category/list.html:19
msgid "Status"
msgstr ""

#: category/templates/category/list.html:20
msgid "Last update"
msgstr "Poslední změna"

#: category/templates/category/list.html:21
msgid "Actions"
msgstr "Akce"

#: category/templates/category/list.html:23
msgid "Yes"
msgstr "Ano"
#: category/templates/category/list.html:40
msgid "None"
msgstr "Nic"

#: category/templates/category/list.html:23
msgid "No"
msgstr "Ne"
#: category/templates/category/list.html:48
msgid "No generated files"
msgstr "Žádné soubory"

#: category/templates/category/list.html:27
#: category/templates/category/list.html:55
msgid "Edit"
msgstr "Upravit"

#: category/templates/category/list.html:29
#: category/templates/category/list.html:58
msgid "Toggle Dropdown"
msgstr "Rozbalit"

#: category/templates/category/list.html:34
#: category/templates/category/list.html:64
msgid "Already in queue"
msgstr "Již ve frontě"

#: category/templates/category/list.html:36
msgid "Regenerate"
msgstr "Přegenerovat"
#: category/templates/category/list.html:67
msgid "Generate PDF"
msgstr "Vygenerovat PDF"

#: category/templates/category/list.html:70
msgid "Filename required for PDF generation"
msgstr "Chybí jméno souboru pro generování PDF"

#: category/templates/category/list.html:39
#: category/templates/category/list.html:74
msgid "Delete"
msgstr "Smazat"

#: category/templates/category/list.html:48
#: category/templates/category/list.html:83
msgid "Add Category"
msgstr "Přidat Kategorii"

#: category/views.py:40
#: category/views.py:38
#, python-format
msgid "Category with url /%(slug)s does not exist"
msgstr "Kategorie s url /%(slug)s neexistuje"

#: category/views.py:107
#, python-format
msgid "Category %s was successfully staged for PDF generation"
msgstr "PDF pro Kategorii %s bylo přidáno do fronty"
#: category/views.py:72
msgid "songbook"
msgstr "zpevnicek"
2 changes: 1 addition & 1 deletion category/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Category(PDFTemplate):
)

def get_songs(self) -> Iterable[Tuple[int, "Song"]]:
return list(enumerate(self.song_set.filter(archived=False)))
return list(enumerate(self.song_set.filter(archived=False), start=1))

def __str__(self):
return self.name
Expand Down
Loading

0 comments on commit 15d55ca

Please sign in to comment.