From cfed8eeaded30cd6bd5d958de247ada785e473d8 Mon Sep 17 00:00:00 2001 From: Julian Baumann Date: Wed, 9 Aug 2023 18:31:54 +0200 Subject: [PATCH 1/2] use proper image rendering instead of preview (#377) --- myhpi/core/markdown/extensions.py | 22 ++++++++++++++++++++++ myhpi/static/js/admin/easymde_custom.js | 2 +- myhpi/static/scss/myHPI.scss | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/myhpi/core/markdown/extensions.py b/myhpi/core/markdown/extensions.py index 5e3c1612..15ec98e9 100644 --- a/myhpi/core/markdown/extensions.py +++ b/myhpi/core/markdown/extensions.py @@ -7,6 +7,7 @@ from markdown.inlinepatterns import LinkInlineProcessor from markdown.preprocessors import Preprocessor from wagtail.core.models import Page +from wagtail.images.models import Image class MinutesBasePreprocessor(Preprocessor): @@ -158,6 +159,22 @@ def url(self, id): return Page.objects.get(id=id).localized.get_url() +class ImagePattern(LinkInlineProcessor): + def handleMatch(self, m, data=None): + el = markdown.util.etree.Element("img") + try: + el.set("src", self.url(m.group("id"))) + el.set("alt", markdown.util.AtomicString(m.group("title"))) + el.set("class", "rendered-image") + except ObjectDoesNotExist: + el = markdown.util.etree.Element("span") + el.text = markdown.util.AtomicString(_("[missing image]")) + return el, m.start(0), m.end(0) + + def url(self, id): + return Image.objects.get(id=id).get_rendition("width-800").url + + class MinuteExtension(Extension): def extendMarkdown(self, md): md.registerExtension(self) @@ -172,3 +189,8 @@ def extendMarkdown(self, md): "InternalLinkPattern", 200, ) + md.inlinePatterns.register( + ImagePattern(r"!\[(?P[^\[]+)\]\(image:(?P<id>\d+)\)", md), + "ImagePattern", + 200, + ) diff --git a/myhpi/static/js/admin/easymde_custom.js b/myhpi/static/js/admin/easymde_custom.js index 18a60625..1ba2f49a 100644 --- a/myhpi/static/js/admin/easymde_custom.js +++ b/myhpi/static/js/admin/easymde_custom.js @@ -69,7 +69,7 @@ window.wagtailMarkdown.options = { onload: IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS, responses: { imageChosen: function (t) { - editor.codemirror.replaceSelection("![" + t.title + "](" + t.preview.url + ")") + editor.codemirror.replaceSelection("![" + t.title + "](image:" + t.id + ")"); } }, diff --git a/myhpi/static/scss/myHPI.scss b/myhpi/static/scss/myHPI.scss index 2c85eecc..be70d3d7 100644 --- a/myhpi/static/scss/myHPI.scss +++ b/myhpi/static/scss/myHPI.scss @@ -207,6 +207,10 @@ h1.toc-title::after { margin-top: -0.25rem; } +.rendered-image { + max-width: 100%; +} + @import "./navbar.scss"; @import "./footer.scss"; From a6db67ec7ef52580049ea5aacbca982d63c3bbaa Mon Sep 17 00:00:00 2001 From: frcroth <frcroth@users.noreply.github.com> Date: Wed, 9 Aug 2023 18:46:51 +0200 Subject: [PATCH 2/2] Use firstname lastname for last edited by (#375) --- README.md | 2 + myhpi/core/models.py | 3 +- .../core/templates/core/information_page.html | 2 +- myhpi/locale/de/LC_MESSAGES/django.po | 43 ++++++++++++------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2e56c8d2..31f548f5 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ If you want to do that manually, run `pre-commit run --all-files`. Next to that, ## Tips +- To create translations, run `django-admin makemessages -l de` in the myhpi directory. + ### Reset database 1. Delete `db.sqlite3` diff --git a/myhpi/core/models.py b/myhpi/core/models.py index 75464dac..3510313b 100644 --- a/myhpi/core/models.py +++ b/myhpi/core/models.py @@ -78,7 +78,8 @@ class InformationPage(BasePage): @property def last_edited_by(self): if self.get_latest_revision(): - return self.get_latest_revision().user + user = self.get_latest_revision().user + return f"{user.first_name} {user.last_name}" class MinutesList(BasePage): diff --git a/myhpi/core/templates/core/information_page.html b/myhpi/core/templates/core/information_page.html index ce7d8657..3be6f309 100644 --- a/myhpi/core/templates/core/information_page.html +++ b/myhpi/core/templates/core/information_page.html @@ -19,7 +19,7 @@ <h1 class="page-title"> <h1 class="toc-title">{% translate "Last edited" %}</h1> {{ page.last_published_at|date:"d.m.Y, H:i" }} {% if page.author_visible %} - <i>von</i> + <i>{% translate "by" %}</i> {{ page.last_edited_by }} {% endif %} </aside> diff --git a/myhpi/locale/de/LC_MESSAGES/django.po b/myhpi/locale/de/LC_MESSAGES/django.po index 96de4dc5..d9900fea 100644 --- a/myhpi/locale/de/LC_MESSAGES/django.po +++ b/myhpi/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-04-14 12:42+0000\n" +"POT-Creation-Date: 2023-08-09 16:50+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -70,6 +70,10 @@ msgstr "[link fehlt]" msgid "Last edited" msgstr "Zuletzt bearbeitet" +#: core/templates/core/information_page.html:22 +msgid "by" +msgstr "von" + #: core/templates/core/information_page.html:27 #: core/templates/core/minutes.html:47 polls/templates/polls/poll.html:29 msgid "Table of contents" @@ -178,11 +182,11 @@ msgstr " Ergebnisse gefunden." msgid "No results found." msgstr "Keine Ergebnisse gefunden." -#: search/templates/search/search_field.html:6 templates/base.html:150 +#: search/templates/search/search_field.html:6 templates/base.html:157 msgid "Search..." msgstr "Suchen..." -#: templates/403.html:5 myhpi/templates/403.html:11 +#: templates/403.html:5 templates/403.html:11 msgid "Access denied" msgstr "Zugang verweigert" @@ -190,26 +194,34 @@ msgstr "Zugang verweigert" msgid "" "Unfortunately you are not allowed to view this page. This might have one of " "the following reasons:" -msgstr "Du bist nicht berechtigt, diese Seite zu sehen. Das kann einen der folgenden Gründe haben:" +msgstr "" +"Du bist nicht berechtigt, diese Seite zu sehen. Das kann einen der folgenden " +"Gründe haben:" #: templates/403.html:16 msgid "" "You are not logged in and are not accessing the page from the university " "network." -msgstr "Du bist nicht eingeloggt oder rufst die Seite nicht aus dem Universitätsnetzwerk auf." +msgstr "" +"Du bist nicht eingeloggt oder rufst die Seite nicht aus dem " +"Universitätsnetzwerk auf." #: templates/403.html:17 msgid "" "You are not logged in and the page is only available for logged in users." -msgstr "Du bist nicht eingeloggt und die Seite ist nur für eingeloggte Nutzer sichtbar." +msgstr "" +"Du bist nicht eingeloggt und die Seite ist nur für eingeloggte Nutzer " +"sichtbar." #: templates/403.html:18 msgid "" "You are logged in but don't have the required permissions to access this " "page." -msgstr "Du bist eingeloggt, aber hast keine ausreichenden Berechtigungen, um diese Seite zu sehen." +msgstr "" +"Du bist eingeloggt, aber hast keine ausreichenden Berechtigungen, um diese " +"Seite zu sehen." -#: myhpi/templates/404.html:7 +#: templates/404.html:7 msgid "Page not found" msgstr "Seite nicht gefunden." @@ -229,19 +241,19 @@ msgstr "Zur Startseite" msgid "Ctrl+K" msgstr "Strg+K" -#: templates/base.html:73 +#: templates/base.html:74 msgid "Sign in" msgstr "Anmelden" -#: templates/base.html:93 +#: templates/base.html:99 msgid "Your groups:" msgstr "Deine Gruppen" -#: templates/base.html:100 +#: templates/base.html:106 msgid "Sign out" msgstr "Abmelden" -#: templates/base.html:152 +#: templates/base.html:159 msgid "Start search" msgstr "Suche starten" @@ -330,8 +342,10 @@ msgstr "" "\t" #: tenca_django/templates/tenca_django/delete_list.html:20 +#, fuzzy +#| msgid "Delete list" msgid "Delete" -msgstr "Löschen" +msgstr "Liste Löschen" #: tenca_django/templates/tenca_django/delete_list.html:21 msgid "Cancel" @@ -484,6 +498,3 @@ msgstr "Die Anmeldung von {email} auf {list} wurde rückgänig gemacht." #~ msgstr "" #~ " Die angeforderte Seite existiert nicht. Bitte überprüfe die URL oder " #~ "nutze das Menü oben, um die gewünschte Seite zu finden. " - -#~ msgid "Previous" -#~ msgstr "Vorherige "