mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user