Skip to content

Commit

Permalink
translate_url templatetag is added, changes were made to make code co…
Browse files Browse the repository at this point in the history
…mpatible with it
  • Loading branch information
4-dash committed Nov 9, 2024
1 parent 802af13 commit b8386e0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 97 deletions.
17 changes: 17 additions & 0 deletions src/feedback/templatetags/translate_url.py
Original file line number Diff line number Diff line change
@@ -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
90 changes: 2 additions & 88 deletions src/feedback/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]', geschlecht='w',
anschrift='S202 D120')
p1 = Person.objects.create(vorname='Noch Je', nachname='Mand', email='[email protected]', 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
5 changes: 3 additions & 2 deletions src/feedback/views/veranstalter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', )



Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"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"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"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"
Expand Down
6 changes: 3 additions & 3 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit b8386e0

Please sign in to comment.