mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Translate question options in backend and PDFs (Z#23134850) (#3693)
* Translate question options in backend and PDFs * Extend to invoices
This commit is contained in:
@@ -1271,6 +1271,21 @@ class QuestionAnswer(models.Model):
|
||||
return self.file.name.split('.', 1)[-1]
|
||||
|
||||
def __str__(self):
|
||||
return self.to_string(use_cached=True)
|
||||
|
||||
def to_string_i18n(self):
|
||||
return self.to_string(use_cached=False)
|
||||
|
||||
def to_string(self, use_cached=True):
|
||||
"""
|
||||
Render this answer as a string.
|
||||
|
||||
:param use_cached: If ``True`` (default), choice and multiple choice questions will show their cached
|
||||
value, i.e. the value of the selected options at the time of saving and in the language
|
||||
the answer was saved in. If ``False``, the values will instead be loaded from the
|
||||
database, yielding current and translated values of the options. However, additional database
|
||||
queries might be required.
|
||||
"""
|
||||
if self.question.type == Question.TYPE_BOOLEAN and self.answer == "True":
|
||||
return str(_("Yes"))
|
||||
elif self.question.type == Question.TYPE_BOOLEAN and self.answer == "False":
|
||||
@@ -1305,6 +1320,8 @@ class QuestionAnswer(models.Model):
|
||||
return PhoneNumber.from_string(self.answer).as_international
|
||||
except NumberParseException:
|
||||
return self.answer
|
||||
elif self.question.type in (Question.TYPE_CHOICE, Question.TYPE_CHOICE_MULTIPLE) and self.answer and not use_cached:
|
||||
return ", ".join(str(o.answer) for o in self.options.all())
|
||||
else:
|
||||
return self.answer
|
||||
|
||||
|
||||
@@ -567,7 +567,7 @@ def variables_from_questions(sender, *args, **kwargs):
|
||||
if not a:
|
||||
return ""
|
||||
else:
|
||||
return str(a)
|
||||
return a.to_string_i18n()
|
||||
|
||||
d = {}
|
||||
for q in sender.questions.all():
|
||||
|
||||
@@ -199,7 +199,7 @@ def build_invoice(invoice: Invoice) -> Invoice:
|
||||
positions = list(
|
||||
invoice.order.positions.select_related('addon_to', 'item', 'tax_rule', 'subevent', 'variation').annotate(
|
||||
addon_c=Count('addons')
|
||||
).prefetch_related('answers', 'answers__question').order_by('positionid', 'id')
|
||||
).prefetch_related('answers', 'answers__options', 'answers__question').order_by('positionid', 'id')
|
||||
)
|
||||
|
||||
reverse_charge = False
|
||||
@@ -247,7 +247,7 @@ def build_invoice(invoice: Invoice) -> Invoice:
|
||||
desc += "<br />{}{} {}".format(
|
||||
answ.question.question,
|
||||
"" if str(answ.question.question).endswith("?") else ":",
|
||||
str(answ)
|
||||
answ.to_string_i18n()
|
||||
)
|
||||
|
||||
if invoice.event.has_subevents:
|
||||
|
||||
@@ -589,9 +589,9 @@
|
||||
</a>
|
||||
{% endif %}
|
||||
{% elif q.type == "M" %}
|
||||
{{ q.answer|rich_text_snippet }}
|
||||
{{ q.answer.to_string_i18n|rich_text_snippet }}
|
||||
{% else %}
|
||||
{{ q.answer|linebreaksbr }}
|
||||
{{ q.answer.to_string_i18n|linebreaksbr }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<em>{% trans "not answered" %}</em>
|
||||
|
||||
Reference in New Issue
Block a user