From b68ed055be00726ca5565c6ee254ed179ca1c16f Mon Sep 17 00:00:00 2001 From: 4-dash <120916864+4-dash@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:49:55 +0100 Subject: [PATCH] fixed bug related to translate_url templatetag --- src/feedback/templatetags/translate_url.py | 16 ++++++++++------ src/feedback/views/veranstalter.py | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/feedback/templatetags/translate_url.py b/src/feedback/templatetags/translate_url.py index b4a96b9..623256c 100644 --- a/src/feedback/templatetags/translate_url.py +++ b/src/feedback/templatetags/translate_url.py @@ -9,9 +9,13 @@ 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 + ## this if is here only because of veranstalter.py > VeranstalterWizard > done method. + ## see comment there, why we might not have request + if 'request' in context : + 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 + return "" \ No newline at end of file diff --git a/src/feedback/views/veranstalter.py b/src/feedback/views/veranstalter.py index a08d94f..a0c9ecc 100644 --- a/src/feedback/views/veranstalter.py +++ b/src/feedback/views/veranstalter.py @@ -269,8 +269,8 @@ def done(self, form_list, **kwargs): context = self.get_context_data('zusammenfassung') send_mail_to_verantwortliche(ergebnis_empfaenger, context, instance) - ## 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', ) + # previously render_to_response was used which didn't require request, but later it was deprecated, leaving this only viable option + return render(request=None, template_name='formtools/wizard/bestellung_done.html', )