Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions concrete_datastore/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
HTTP_204_NO_CONTENT,
)
from rest_framework import authentication, permissions, generics, viewsets
from rest_framework.utils.urls import remove_query_param, replace_query_param
from rest_framework.utils.urls import remove_query_param

from concrete_datastore.concrete.models import ( # pylint:disable=E0611
AuthToken,
Expand Down Expand Up @@ -1199,7 +1199,7 @@ def get_export(self, request):
export_queryset = queryset.values(*export_fields)

response = csv_streaming_response(
request, export_queryset, export_fields
export_queryset, export_fields, language=request.GET.get('lang'),
)

return response
Expand Down
147 changes: 147 additions & 0 deletions concrete_datastore/concrete/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-30 14:46+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: concrete/apps.py:58
msgid "NS concrete"
msgstr ""

#: concrete/models.py:74 concrete/models.py:209
msgid "User"
msgstr ""

#: concrete/models.py:204
msgid "Key"
msgstr ""

#: concrete/models.py:217
msgid "Temporary Token"
msgstr ""

#: concrete/models.py:218
msgid "Temporary Tokens"
msgstr ""

#: concrete/models.py:863
msgid "email address"
msgstr ""

#: concrete/templates/admin/add_form.html:6
msgid ""
"First, enter an email and password. Then, you'll be able to edit more user "
"options."
msgstr ""

#: concrete/templates/admin/add_form.html:8
msgid "Enter an email and password."
msgstr ""

#: concrete/templates/admin/base.html:36
msgid "Welcome,"
msgstr ""

#: concrete/templates/admin/change_list.html:5
msgid "Home"
msgstr ""

#: concrete/templates/admin/index.html:24
msgid "Add"
msgstr ""

#: concrete/templates/admin/index.html:31
msgid "View"
msgstr ""

#: concrete/templates/admin/index.html:33
msgid "Change"
msgstr ""

#: concrete/templates/admin/index.html:44
msgid "You don't have permission to view or edit anything."
msgstr ""

#: concrete/templates/admin/mfa-login.html:47
msgid "Please correct the error below."
msgstr ""

#: concrete/templates/admin/mfa-login.html:47
msgid "Please correct the errors below."
msgstr ""

#: concrete/templates/admin/mfa-login.html:63
#, python-format
msgid ""
"You are authenticated as %(username)s, but are not authorized to access this "
"page. Would you like to login to a different account?"
msgstr ""

#: concrete/templates/admin/mfa-login.html:83
msgid "OTP Token:"
msgstr ""

#: concrete/templates/admin/mfa-login.html:89
msgid "Forgotten your password or username?"
msgstr ""

#: concrete/templates/admin/mfa-login.html:93
msgid "Log in"
msgstr ""

#: concrete/templates/admin/mfa-login.html:95
msgid "Request a new code"
msgstr ""

msgid "True"
msgstr "Wahr"

msgid "False"
msgstr "Falsch"

msgid "photo"
msgstr "foto"

msgid "establishment_type"
msgstr "einrichtungstyp"

msgid "address"
msgstr "adresse"

msgid "opening_hours"
msgstr "öffnungszeiten"

msgid "tel_number"
msgstr "telefonnummer"

msgid "order_recover_details"
msgstr "bestellungs_details"

msgid "email"
msgstr "e-mail"

msgid "archived"
msgstr "archiviert"

msgid "logo"
msgstr "logo"

msgid "name"
msgstr "name"

msgid "creation_date"
msgstr "erstellungsdatum"
148 changes: 148 additions & 0 deletions concrete_datastore/concrete/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-30 14:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: concrete/apps.py:58
msgid "NS concrete"
msgstr ""

#: concrete/models.py:74 concrete/models.py:209
msgid "User"
msgstr ""

#: concrete/models.py:204
msgid "Key"
msgstr ""

#: concrete/models.py:217
msgid "Temporary Token"
msgstr ""

#: concrete/models.py:218
msgid "Temporary Tokens"
msgstr ""

#: concrete/models.py:863
msgid "email address"
msgstr ""

#: concrete/templates/admin/add_form.html:6
msgid ""
"First, enter an email and password. Then, you'll be able to edit more user "
"options."
msgstr ""

#: concrete/templates/admin/add_form.html:8
msgid "Enter an email and password."
msgstr ""

#: concrete/templates/admin/base.html:36
msgid "Welcome,"
msgstr ""

#: concrete/templates/admin/change_list.html:5
msgid "Home"
msgstr ""

#: concrete/templates/admin/index.html:24
msgid "Add"
msgstr ""

#: concrete/templates/admin/index.html:31
msgid "View"
msgstr ""

#: concrete/templates/admin/index.html:33
msgid "Change"
msgstr ""

#: concrete/templates/admin/index.html:44
msgid "You don't have permission to view or edit anything."
msgstr ""

#: concrete/templates/admin/mfa-login.html:47
msgid "Please correct the error below."
msgstr ""

#: concrete/templates/admin/mfa-login.html:47
msgid "Please correct the errors below."
msgstr ""

#: concrete/templates/admin/mfa-login.html:63
#, python-format
msgid ""
"You are authenticated as %(username)s, but are not authorized to access this "
"page. Would you like to login to a different account?"
msgstr ""

#: concrete/templates/admin/mfa-login.html:83
msgid "OTP Token:"
msgstr ""

#: concrete/templates/admin/mfa-login.html:89
msgid "Forgotten your password or username?"
msgstr ""

#: concrete/templates/admin/mfa-login.html:93
msgid "Log in"
msgstr ""

#: concrete/templates/admin/mfa-login.html:95
msgid "Request a new code"
msgstr ""

msgid "True"
msgstr "Vrai"

msgid "False"
msgstr "Faux"

msgid "photo"
msgstr "photo"

msgid "establishment_type"
msgstr "type_d'établissement"

msgid "address"
msgstr "adresse"

msgid "opening_hours"
msgstr "heures_d'ouverture"

msgid "tel_number"
msgstr "numéro_tél"

msgid "order_recover_details"
msgstr "détails_de_la_commande"

msgid "email"
msgstr "e-mail"

msgid "archived"
msgstr "archivé"

msgid "logo"
msgstr "logo"

msgid "name"
msgstr "nom"

msgid "creation_date"
msgstr "date_création"

48 changes: 37 additions & 11 deletions concrete_datastore/interfaces/csv.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
# coding: utf-8
import pendulum
import datetime
from typing import Iterable, Dict
from django.utils import timezone
from django.http import StreamingHttpResponse
from django.utils.translation import gettext_lazy as _
from django.utils import translation


def csv_data_generator(iterable: Iterable[Dict], fields: Iterable[str]):
def translate_if_date(language, field):
if language and isinstance(field, datetime.datetime):
try:
field = pendulum.parse(str(field)).format(
"DD/MM/YYYY HH:mm:ss", locale=language
)
except Exception:
pass
return str(field) # i18n translation only works if the value is a string


def csv_data_generator(
queryset: Iterable[Dict], fields: Iterable[str], language=None
):
"""
Generator producing UTF-8 - quoted and semicolon separated CSV
"""
if language:
translation.activate(language)

# Yields headers
yield '{}\n'.format(
';'.join('"{}"'.format(field) for field in fields)
).encode('utf-8')
yield '{}\n'.format(';'.join('"{}"'.format(_(field)) for field in fields))

# Yields rows
for item in iterable:
for item in queryset:
value = '{}\n'.format(
';'.join(['"{}"'.format(item.get(field, '')) for field in fields])
';'.join(
[
'"{}"'.format(
_(translate_if_date(language, item.get(field, '')))
)
for field in fields
]
)
).encode('utf-8')
yield value


def csv_streaming_response(
request, queryset, fields: Iterable[str], filename: str = None
queryset, fields: Iterable[str], filename: str = None, language=None,
):
if filename is None:
now = timezone.now()
filename = 'export_{}_{}.csv'.format(
queryset.model.__name__, now.strftime("%Y-%m-%d_%H-%M")
)
filename = f'export_{queryset.model.__name__}_{now.strftime("%Y-%m-%d_%H-%M")}.csv'
if language:
filename = f'export_{language}_{queryset.model.__name__}_{now.strftime("%Y-%m-%d_%H-%M")}.csv'

response = StreamingHttpResponse(
csv_data_generator(queryset, fields), content_type="text/csv"
csv_data_generator(queryset, fields, language),
content_type="text/csv",
)

response['Content-Disposition'] = 'attachment; filename="{}"'.format(
filename
)
Expand Down