From f5c611982a16cdcb45beb3d54492e7f1476d977d Mon Sep 17 00:00:00 2001 From: Martin Gross Date: Fri, 9 Aug 2019 13:40:32 +0200 Subject: [PATCH] Do not localize date, time, datetime in csv/excel exports --- src/pretix/base/exporters/orderlist.py | 9 +++++-- src/pretix/base/models/items.py | 1 + src/pretix/plugins/checkinlists/exporters.py | 28 +++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/pretix/base/exporters/orderlist.py b/src/pretix/base/exporters/orderlist.py index 43e542297..71bef8e81 100644 --- a/src/pretix/base/exporters/orderlist.py +++ b/src/pretix/base/exporters/orderlist.py @@ -9,7 +9,7 @@ from django.utils.formats import date_format, localize from django.utils.translation import pgettext, ugettext as _, ugettext_lazy from pretix.base.models import ( - InvoiceAddress, InvoiceLine, Order, OrderPosition, + InvoiceAddress, InvoiceLine, Order, OrderPosition, Question, ) from pretix.base.models.orders import OrderFee, OrderPayment, OrderRefund from pretix.base.settings import PERSON_NAME_SCHEMES @@ -341,7 +341,12 @@ class OrderListExporter(MultiSheetListExporter): ] acache = {} for a in op.answers.all(): - acache[a.question_id] = str(a) + # We do not want to localize Date, Time and Datetime question answers, as those can lead + # to difficulties parsing the data (for example 2019-02-01 may become Février, 2019 01 in French). + if a.question.type in Question.UNLOCALIZED_TYPES: + acache[a.question_id] = a.answer + else: + acache[a.question_id] = str(a) for q in questions: row.append(acache.get(q.pk, '')) try: diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py index 3ec1489f2..a6faa3d9a 100644 --- a/src/pretix/base/models/items.py +++ b/src/pretix/base/models/items.py @@ -982,6 +982,7 @@ class Question(LoggedModel): (TYPE_DATETIME, _("Date and time")), (TYPE_COUNTRYCODE, _("Country code (ISO 3166-1 alpha-2)")), ) + UNLOCALIZED_TYPES = [TYPE_DATE, TYPE_TIME, TYPE_DATETIME] event = models.ForeignKey( Event, diff --git a/src/pretix/plugins/checkinlists/exporters.py b/src/pretix/plugins/checkinlists/exporters.py index 7cd03a9db..af54f54dc 100644 --- a/src/pretix/plugins/checkinlists/exporters.py +++ b/src/pretix/plugins/checkinlists/exporters.py @@ -250,9 +250,19 @@ class PDFCheckinList(ReportlabExportMixin, CheckInListMixin, BaseExporter): acache = {} if op.addon_to: for a in op.addon_to.answers.all(): - acache[a.question_id] = str(a) + # We do not want to localize Date, Time and Datetime question answers, as those can lead + # to difficulties parsing the data (for example 2019-02-01 may become Février, 2019 01 in French). + if a.question.type in Question.UNLOCALIZED_TYPES: + acache[a.question_id] = a.answer + else: + acache[a.question_id] = str(a) for a in op.answers.all(): - acache[a.question_id] = str(a) + # We do not want to localize Date, Time and Datetime question answers, as those can lead + # to difficulties parsing the data (for example 2019-02-01 may become Février, 2019 01 in French). + if a.question.type in Question.UNLOCALIZED_TYPES: + acache[a.question_id] = a.answer + else: + acache[a.question_id] = str(a) for q in questions: txt = acache.get(q.pk, '') p = Paragraph(txt, self.get_style()) @@ -365,9 +375,19 @@ class CSVCheckinList(CheckInListMixin, ListExporter): acache = {} if op.addon_to: for a in op.addon_to.answers.all(): - acache[a.question_id] = str(a) + # We do not want to localize Date, Time and Datetime question answers, as those can lead + # to difficulties parsing the data (for example 2019-02-01 may become Février, 2019 01 in French). + if a.question.type in Question.UNLOCALIZED_TYPES: + acache[a.question_id] = a.answer + else: + acache[a.question_id] = str(a) for a in op.answers.all(): - acache[a.question_id] = str(a) + # We do not want to localize Date, Time and Datetime question answers, as those can lead + # to difficulties parsing the data (for example 2019-02-01 may become Février, 2019 01 in French). + if a.question.type in Question.UNLOCALIZED_TYPES: + acache[a.question_id] = a.answer + else: + acache[a.question_id] = str(a) for q in questions: row.append(acache.get(q.pk, ''))