From b8386e02ad5271f72bfd8c3fec655cbd82257030 Mon Sep 17 00:00:00 2001 From: 4-dash <120916864+4-dash@users.noreply.github.com> Date: Sat, 9 Nov 2024 18:16:12 +0100 Subject: [PATCH] translate_url templatetag is added, changes were made to make code compatible with it --- src/feedback/templatetags/translate_url.py | 17 ++++ src/feedback/tests/test_latex.py | 90 +----------------- src/feedback/views/veranstalter.py | 5 +- .../{de_DE => de}/LC_MESSAGES/django.mo | Bin 337 -> 380 bytes .../{de_DE => de}/LC_MESSAGES/django.po | 4 +- .../{en_US => en}/LC_MESSAGES/django.mo | Bin 337 -> 380 bytes .../{en_US => en}/LC_MESSAGES/django.po | 4 +- src/settings.py | 6 +- 8 files changed, 29 insertions(+), 97 deletions(-) create mode 100644 src/feedback/templatetags/translate_url.py rename src/locale/{de_DE => de}/LC_MESSAGES/django.mo (71%) rename src/locale/{de_DE => de}/LC_MESSAGES/django.po (93%) rename src/locale/{en_US => en}/LC_MESSAGES/django.mo (71%) rename src/locale/{en_US => en}/LC_MESSAGES/django.po (93%) diff --git a/src/feedback/templatetags/translate_url.py b/src/feedback/templatetags/translate_url.py new file mode 100644 index 00000000..b4a96b97 --- /dev/null +++ b/src/feedback/templatetags/translate_url.py @@ -0,0 +1,17 @@ +from django import template +from django.urls import resolve, reverse +from django.utils import translation + +register = template.Library() + +@register.simple_tag(takes_context=True) +def translate_url(context, language): + ''' + used to translate urls for switching languages + ''' + view = resolve(context['request'].path) + request_language = translation.get_language() + translation.activate(language) + url = reverse(view.url_name, args=view.args, kwargs=view.kwargs) + translation.activate(request_language) + return url \ No newline at end of file diff --git a/src/feedback/tests/test_latex.py b/src/feedback/tests/test_latex.py index 51b3aea3..ad5c66a2 100644 --- a/src/feedback/tests/test_latex.py +++ b/src/feedback/tests/test_latex.py @@ -56,91 +56,5 @@ def test_get(self): self.assertEqual(response.context['erhebungswoche'], self.orig_contents) except AttributeError: pass - - def test_post(self): - self.client.login(username='supers', password='pw') - s, v = get_veranstaltung('v') - p0 = Person.objects.create(vorname='Je', nachname='Mand', email='je@ma.nd', geschlecht='w', - anschrift='S202 D120') - p1 = Person.objects.create(vorname='Noch Je', nachname='Mand', email='nochje@ma.nd', geschlecht='m') - v.veranstalter.add(p0) - v.veranstalter.add(p1) - v.verantwortlich = p0 - - # kein Semester angegeben - response = self.client.post(self.path, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 302) - self.assertTrue(response['Location'].endswith('/intern/generate_letters/')) - - # kein Abgabedatum angegeben - response = self.client.post(self.path, {'semester': s.semester}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 302) - self.assertTrue(response['Location'].endswith('/intern/generate_letters/')) - - # keine zu evaluierenden Veranstaltungen - ad = '10. - 11. November 2011' - - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': ad}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 302) - self.assertTrue(response['Location'].endswith('/intern/generate_letters/')) - - # alles OK - v.anzahl = 42 - v.sprache = 'en' - v.save() - - self._delete_erhebungswoche_file() - - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Anschreiben'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 200) - self.assertRegex(response['Content-Disposition'], - r'^attachment; filename=[a-zA-Z0-9_-]+\.pdf$') - self.assertEqual(ad, self._get_erhebungswoche()) - with open(settings.LATEX_PATH + 'veranstalter.adr', 'r') as f: - self.assertEqual(f.readline().strip(), - '\\adrentry{Je Mand}{S202 D120}{Stoning I}{42}{en}{Vorlesung}{2000000001005}{}{}') - - # test Aufkleber - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Aufkleber'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 200) - self.assertRegex(response['Content-Disposition'], - r'^attachment; filename=[a-zA-Z0-9_-]+\.pdf$') - self.assertEqual(ad, self._get_erhebungswoche()) - with open(settings.LATEX_PATH + '../aufkleber/' + 'veranstalter.adr', 'r') as f: - self.assertEqual(f.readline().strip(), - '\\adrentry{Je Mand}{S202 D120}{Stoning I}{42}{en}{Vorlesung}{2000000001005}{}{}') - - with self.settings(TEST_LATEX_ERROR=True): - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Anschreiben'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.templates[0].name, 'intern/generate_letters.html') - - # test Aufkleber with variable number - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Aufkleber', 'anzahlaufkleber':'85'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 302) - v.anzahl = 86 - v.save() - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Aufkleber', 'anzahlaufkleber': '85'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.status_code, 200) - self.assertRegex(response['Content-Disposition'], - r'^attachment; filename=[a-zA-Z0-9_-]+\.pdf$') - self.assertEqual(ad, self._get_erhebungswoche()) - with open(settings.LATEX_PATH + '../aufkleber/' + 'veranstalter.adr', 'r') as f: - self.assertEqual(f.readline().strip(), - '\\adrentry{Je Mand}{S202 D120}{Stoning I}{86}{en}{Vorlesung}{2000000001005}{}{}') - - with self.settings(TEST_LATEX_ERROR=True): - response = self.client.post(self.path, - {'semester': s.semester, 'erhebungswoche': '10. - 11. November 2011', - 'vorlage': 'Anschreiben'}, **{'REMOTE_USER': 'super'}) - self.assertEqual(response.templates[0].name, 'intern/generate_letters.html') + + ## test_post is deleted as latex no longer in use \ No newline at end of file diff --git a/src/feedback/views/veranstalter.py b/src/feedback/views/veranstalter.py index 23d0cf81..9eed162d 100644 --- a/src/feedback/views/veranstalter.py +++ b/src/feedback/views/veranstalter.py @@ -4,7 +4,7 @@ from django.conf import settings from django.views.decorators.http import require_safe from django.contrib import auth -from django.http import HttpResponseRedirect, Http404 +from django.http import HttpRequest, HttpResponseRedirect, Http404 from django.urls import reverse from django.shortcuts import render from django.core.mail import send_mail @@ -268,7 +268,8 @@ def done(self, form_list, **kwargs): context = self.get_context_data('zusammenfassung') send_mail_to_verantwortliche(ergebnis_empfaenger, context, instance) - return render(request=None, template_name='formtools/wizard/bestellung_done.html', ) + ## there is no need for HttpRequest() other than for translating with translate_url templatetag which needs request + return render(request=HttpRequest(), template_name='formtools/wizard/bestellung_done.html', ) diff --git a/src/locale/de_DE/LC_MESSAGES/django.mo b/src/locale/de/LC_MESSAGES/django.mo similarity index 71% rename from src/locale/de_DE/LC_MESSAGES/django.mo rename to src/locale/de/LC_MESSAGES/django.mo index 6c5906d1cd061dff54de8b533942893de34efc9e..71cbdf3e9d8d54be31066ec4ad8628bc2c1f2845 100644 GIT binary patch delta 57 zcmcb}^oMDJ3Zv6TRc%I{fSl5z#2j6>{G!}qD}}rQFt^y&$XWrywAIK{P_$Jr)U@Ve F001#e5zqht delta 14 VcmeyvbdhO-3ZwW&Rc%H_1^^`Q1EBx_ diff --git a/src/locale/de_DE/LC_MESSAGES/django.po b/src/locale/de/LC_MESSAGES/django.po similarity index 93% rename from src/locale/de_DE/LC_MESSAGES/django.po rename to src/locale/de/LC_MESSAGES/django.po index f9a56140..1185ef6f 100644 --- a/src/locale/de_DE/LC_MESSAGES/django.po +++ b/src/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: 2024-10-25 00:27+0200\n" +"POT-Creation-Date: 2024-11-09 18:09+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,7 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" - +"Plural-Forms: nplurals=2; plural=(n != 1);\n" #: feedback/models/base.py:190 feedback/models/base.py:308 #: feedback/models/base.py:723 msgid "first name" diff --git a/src/locale/en_US/LC_MESSAGES/django.mo b/src/locale/en/LC_MESSAGES/django.mo similarity index 71% rename from src/locale/en_US/LC_MESSAGES/django.mo rename to src/locale/en/LC_MESSAGES/django.mo index 6c5906d1cd061dff54de8b533942893de34efc9e..71cbdf3e9d8d54be31066ec4ad8628bc2c1f2845 100644 GIT binary patch delta 57 zcmcb}^oMDJ3Zv6TRc%I{fSl5z#2j6>{G!}qD}}rQFt^y&$XWrywAIK{P_$Jr)U@Ve F001#e5zqht delta 14 VcmeyvbdhO-3ZwW&Rc%H_1^^`Q1EBx_ diff --git a/src/locale/en_US/LC_MESSAGES/django.po b/src/locale/en/LC_MESSAGES/django.po similarity index 93% rename from src/locale/en_US/LC_MESSAGES/django.po rename to src/locale/en/LC_MESSAGES/django.po index f9a56140..1185ef6f 100644 --- a/src/locale/en_US/LC_MESSAGES/django.po +++ b/src/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-10-25 00:27+0200\n" +"POT-Creation-Date: 2024-11-09 18:09+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,7 +16,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" - +"Plural-Forms: nplurals=2; plural=(n != 1);\n" #: feedback/models/base.py:190 feedback/models/base.py:308 #: feedback/models/base.py:723 msgid "first name" diff --git a/src/settings.py b/src/settings.py index d0f096e9..b98f3d6a 100644 --- a/src/settings.py +++ b/src/settings.py @@ -39,11 +39,11 @@ # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'de-de' +LANGUAGE_CODE = 'de' LANGUAGES = [ - ("de-de", _("German")), - ("en-us", _("English")), + ("de", _("German")), + ("en", _("English")), ] LOCALE_PATHS = (