Skip to content

Commit

Permalink
fixed bug related to translate_url templatetag
Browse files Browse the repository at this point in the history
  • Loading branch information
4-dash committed Nov 23, 2024
1 parent d644a73 commit b68ed05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/feedback/templatetags/translate_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
## 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 ""
4 changes: 2 additions & 2 deletions src/feedback/views/veranstalter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', )



Expand Down

0 comments on commit b68ed05

Please sign in to comment.