Skip to content

Commit 234e93e

Browse files
authored
Merge pull request #102 from urtzai/master
Add Basque language + optional function to exclude some DEFAULT_FORMATS
2 parents 9eddf39 + aa8fb58 commit 234e93e

File tree

6 files changed

+213
-20
lines changed

6 files changed

+213
-20
lines changed

README.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ Performing exports with celery
158158
6. Click on the link near the bottom of the page titled `Exported file`.
159159

160160

161+
Excluding export file formats in the admin site
162+
-----------------------------------------------
163+
164+
All available file formats to export are taken from the `Tablib project <https://pypi.org/project/tablib/>`__.
165+
166+
To exclude or disable file formats from the admin site, configure `IMPORT_EXPORT_CELERY_EXCLUDED_FORMATS` django settings variable. This variable is a list of format strings written in lower case.
167+
168+
::
169+
170+
IMPORT_EXPORT_CELERY_EXCLUDED_FORMATS = ["csv", "xls"]
171+
161172

162173
Customizing email template for export job completion email
163174
----------------------------------------------------------
@@ -186,7 +197,7 @@ The email template will get some context variables that you can use to customize
186197

187198

188199
::
189-
200+
190201
{
191202
export_job: The current instance of ExportJob model
192203
app_label: export_job.app_label
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2+
# This file is distributed under the same license as the PACKAGE package.
3+
#
4+
# Urtzi Odriozola <uodriozola@codesyntax.com>, 2023.
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: \n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2023-05-17 20:55+0000\n"
10+
"PO-Revision-Date: 2023-06-07 21:56+0100\n"
11+
"Last-Translator: Urtzi Odriozola <uodriozola@codesyntax.com>\n"
12+
"Language-Team: \n"
13+
"Language: eu\n"
14+
"MIME-Version: 1.0\n"
15+
"Content-Type: text/plain; charset=UTF-8\n"
16+
"Content-Transfer-Encoding: 8bit\n"
17+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
18+
19+
#: import_export_celery/admin.py:12
20+
msgid "Job status info"
21+
msgstr "Lanaren egoera"
22+
23+
#: import_export_celery/admin.py:22 import_export_celery/models/importjob.py:62
24+
msgid "Name of model to import to"
25+
msgstr "Inportatu beharreko modeloaren izena"
26+
27+
#: import_export_celery/admin_actions.py:20
28+
msgid "Perform import"
29+
msgstr "Hasi inportazioa"
30+
31+
#: import_export_celery/admin_actions.py:29
32+
msgid "Perform dry import"
33+
msgstr "Hasi probako inportazioa"
34+
35+
#: import_export_celery/admin_actions.py:39
36+
msgid "Run export job"
37+
msgstr "Hasi esportazio lana"
38+
39+
#: import_export_celery/admin_actions.py:67
40+
msgid "Export with celery"
41+
msgstr "Exportatu celery bidez"
42+
43+
#: import_export_celery/apps.py:7
44+
msgid "Import Export Celery"
45+
msgstr "Inportatu - Esportatu Celery bidez"
46+
47+
#: import_export_celery/models/exportjob.py:27
48+
msgid "exported file"
49+
msgstr "esportatutako fitxategia"
50+
51+
#: import_export_celery/models/exportjob.py:35
52+
#: import_export_celery/models/importjob.py:30
53+
msgid "Have we started processing the file? If so when?"
54+
msgstr "Fitxategia prozesatzen hasi gara? Hala bada, noiz?"
55+
56+
#: import_export_celery/models/exportjob.py:42
57+
#: import_export_celery/models/importjob.py:67
58+
msgid "Status of the job"
59+
msgstr "Lanaren egoera"
60+
61+
#: import_export_celery/models/exportjob.py:48
62+
msgid "Format of file to be exported"
63+
msgstr "Esportatu beharreko fitxategiaren formatua"
64+
65+
#: import_export_celery/models/exportjob.py:55
66+
msgid "App label of model to export from"
67+
msgstr "Esportatu beharreko modeloaren aplikazio izena"
68+
69+
#: import_export_celery/models/exportjob.py:60
70+
msgid "Name of model to export from"
71+
msgstr "Esportatu beharreko modeloaren izena"
72+
73+
#: import_export_celery/models/exportjob.py:65
74+
msgid "Resource to use when exporting"
75+
msgstr "Esportatzeko erabili beharreko baliabidea"
76+
77+
#: import_export_celery/models/exportjob.py:71
78+
msgid "JSON list of pks to export"
79+
msgstr "Esportatzeko ID-en JSON zerrenda"
80+
81+
#: import_export_celery/models/exportjob.py:76
82+
msgid "Send me an email when this export job is complete"
83+
msgstr "Bidali eposta bat esportazio lan hau amaitzen denean"
84+
85+
#: import_export_celery/models/exportjob.py:81
86+
msgid "Site of origin"
87+
msgstr "Jatorrizko gunea"
88+
89+
#: import_export_celery/models/exportjob.py:87
90+
msgid "Export job"
91+
msgstr "Esportazio lana"
92+
93+
#: import_export_celery/models/exportjob.py:88
94+
msgid "Export jobs"
95+
msgstr "Esportazio lanak"
96+
97+
#: import_export_celery/models/importjob.py:22
98+
msgid "File to be imported"
99+
msgstr "Inportatu beharreko fitxategia"
100+
101+
#: import_export_celery/models/importjob.py:37
102+
msgid "Has the import been completed? If so when?"
103+
msgstr "Inportazioa amaitu da? Hala bada, noiz?"
104+
105+
#: import_export_celery/models/importjob.py:44
106+
msgid "Format of file to be imported"
107+
msgstr "Inportatu beharreko fitxategiaren formatua"
108+
109+
#: import_export_celery/models/importjob.py:49
110+
msgid "Summary of changes made by this import"
111+
msgstr "Inportazio honek eginiko aldaketen laburpena"
112+
113+
#: import_export_celery/models/importjob.py:56
114+
msgid "Errors"
115+
msgstr "Erroreak"
116+
117+
#: import_export_celery/models/importjob.py:73
118+
msgid "Import job"
119+
msgstr "Inportazio lana"
120+
121+
#: import_export_celery/models/importjob.py:74
122+
msgid "Import jobs"
123+
msgstr "Inportazio lanak"
124+
125+
#: import_export_celery/tasks.py:61
126+
#, python-format
127+
msgid "Imported file has a wrong encoding: %s"
128+
msgstr "Inportatutako fitxategiak kodetze okerra du: %s"
129+
130+
#: import_export_celery/tasks.py:68
131+
#, python-format
132+
msgid "Error reading file: %s"
133+
msgstr "Errorea fitxategia irakurtzean: %s"
134+
135+
#: import_export_celery/tasks.py:101
136+
#, python-format
137+
msgid ""
138+
"Line: %s - %s\n"
139+
"\t%s\n"
140+
"%s"
141+
msgstr ""
142+
"Lerroa: %s - %s\n"
143+
"\t%s\n"
144+
"%s"
145+
146+
#: import_export_celery/tasks.py:190
147+
#, python-format
148+
msgid "Import error %s"
149+
msgstr "Inportazio errorea %s"

import_export_celery/models/exportjob.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
from django.db.models.signals import post_save
1313
from django.utils.translation import gettext_lazy as _
1414

15-
from import_export.formats.base_formats import DEFAULT_FORMATS
16-
1715
from ..tasks import run_export_job
16+
from ..utils import get_formats
1817

1918

2019
@with_author
@@ -127,7 +126,7 @@ def get_format_choices():
127126
"""returns choices of available export formats"""
128127
return [
129128
(f.CONTENT_TYPE, f().get_title())
130-
for f in DEFAULT_FORMATS
129+
for f in get_formats()
131130
if f().can_export()
132131
]
133132

import_export_celery/tasks.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
from django.utils.encoding import force_str
1212
from django.utils.translation import gettext_lazy as _
1313

14-
from import_export.formats.base_formats import DEFAULT_FORMATS
15-
1614
from . import models
1715
from .model_config import ModelConfig
18-
from .utils import send_export_job_completion_mail
16+
from .utils import send_export_job_completion_mail, get_formats
1917

2018
from celery.utils.log import get_task_logger
2119
import logging
@@ -39,7 +37,7 @@ def change_job_status(job, direction, job_status, dry_run=False):
3937

4038

4139
def get_format(job):
42-
for format in DEFAULT_FORMATS:
40+
for format in get_formats():
4341
if job.format == format.CONTENT_TYPE:
4442
return format()
4543
break
@@ -58,7 +56,9 @@ def _run_import_job(import_job, dry_run=True):
5856
data = force_str(data, "utf8")
5957
dataset = import_format.create_dataset(data)
6058
except UnicodeDecodeError as e:
61-
import_job.errors += _("Imported file has a wrong encoding: %s" % e) + "\n"
59+
import_job.errors += (
60+
_("Imported file has a wrong encoding: %s" % e) + "\n"
61+
)
6262
change_job_status(
6363
import_job, "import", "Imported file has a wrong encoding", dry_run
6464
)
@@ -69,7 +69,9 @@ def _run_import_job(import_job, dry_run=True):
6969
change_job_status(import_job, "import", "Error reading file", dry_run)
7070
import_job.save()
7171
return
72-
change_job_status(import_job, "import", "2/5 Processing import data", dry_run)
72+
change_job_status(
73+
import_job, "import", "2/5 Processing import data", dry_run
74+
)
7375

7476
class Resource(model_config.resource):
7577
def __init__(self, import_job, *args, **kwargs):
@@ -93,7 +95,9 @@ def before_import_row(self, row, **kwargs):
9395
skip_diff = resource._meta.skip_diff or resource._meta.skip_html_diff
9496

9597
result = resource.import_data(dataset, dry_run=dry_run)
96-
change_job_status(import_job, "import", "4/5 Generating import summary", dry_run)
98+
change_job_status(
99+
import_job, "import", "4/5 Generating import summary", dry_run
100+
)
97101
for error in result.base_errors:
98102
import_job.errors += f"\n{error.error}\n{error.traceback}\n"
99103
for line, errors in result.row_errors():
@@ -111,7 +115,9 @@ def before_import_row(self, row, **kwargs):
111115
summary += '<meta charset="utf-8">'
112116
summary += "</head>"
113117
summary += "<body>"
114-
summary += '<table border="1">' # TODO refactor the existing template so we can use it for this
118+
summary += ( # TODO refactor the existing template so we can use it for this
119+
'<table border="1">'
120+
)
115121
# https://github.com/django-import-export/django-import-export/blob/6575c3e1d89725701e918696fbc531aeb192a6f7/import_export/templates/admin/import_export/import.html
116122
if not result.invalid_rows and not skip_diff:
117123
cols = lambda row: "</td><td>".join([field for field in row.diff])
@@ -133,7 +139,9 @@ def before_import_row(self, row, **kwargs):
133139
+ "</tr>"
134140
)
135141
else:
136-
cols = lambda row: "</td><td>".join([str(field) for field in row.values])
142+
cols = lambda row: "</td><td>".join(
143+
[str(field) for field in row.values]
144+
)
137145
cols_error = lambda row: "".join(
138146
[
139147
"<mark>"

import_export_celery/utils.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@
33
from django.template.loader import get_template
44
from django.conf import settings
55
from django.urls import reverse
6+
from import_export.formats.base_formats import DEFAULT_FORMATS
67

78
DEFAULT_EXPORT_JOB_COMPLETION_MAIL_SUBJECT = "Django: Export job completed"
8-
DEFAULT_EXPORT_JOB_COMPLETION_MAIL_TEMPLATE = "email/export_job_completion.html"
9+
DEFAULT_EXPORT_JOB_COMPLETION_MAIL_TEMPLATE = (
10+
"email/export_job_completion.html"
11+
)
12+
IMPORT_EXPORT_CELERY_EXCLUDED_FORMATS = getattr(
13+
settings,
14+
"IMPORT_EXPORT_CELERY_EXCLUDED_FORMATS",
15+
[],
16+
)
17+
18+
19+
def get_formats():
20+
return [
21+
format
22+
for format in DEFAULT_FORMATS
23+
if format.TABLIB_MODULE.split(".")[-1].strip("_")
24+
not in IMPORT_EXPORT_CELERY_EXCLUDED_FORMATS
25+
]
926

1027

1128
def build_html_and_text_message(template_name, context={}):
@@ -60,7 +77,9 @@ def send_export_job_completion_mail(export_job):
6077
template_name = get_export_job_mail_template()
6178
context = get_export_job_mail_context(export_job)
6279
context.update({"export_job": export_job})
63-
html_message, text_message = build_html_and_text_message(template_name, context)
80+
html_message, text_message = build_html_and_text_message(
81+
template_name, context
82+
)
6483
send_mail(
6584
subject=subject,
6685
message=text_message,

setup.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
requires = ["Django", "django-import-export", "django-author", "html2text"]
1010

1111
try:
12-
version = subprocess.check_output(
13-
["git", "describe", "--abbrev=0", "--tags"]
14-
).decode("utf-8").strip()
12+
version = (
13+
subprocess.check_output(["git", "describe", "--abbrev=0", "--tags"])
14+
.decode("utf-8")
15+
.strip()
16+
)
1517
except subprocess.CalledProcessError:
1618
version = "0.dev" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
1719

@@ -23,9 +25,14 @@
2325
url="https://github.com/auto-mat/django-import-export-celery",
2426
download_url="http://pypi.python.org/pypi/django-import-export-celery/",
2527
description="Process long running django imports and exports in celery",
26-
long_description=codecs.open(os.path.join(here, "README.rst"), "r", "utf-8").read(),
28+
long_description=codecs.open(
29+
os.path.join(here, "README.rst"), "r", "utf-8"
30+
).read(),
2731
long_description_content_type="text/x-rst",
28-
license="License :: OSI Approved :: GNU Lesser General Public License v3.0 or later (LGPLv3.0+)",
32+
license=(
33+
"License :: OSI Approved :: GNU Lesser General Public License v3.0 or"
34+
" later (LGPLv3.0+)"
35+
),
2936
install_requires=requires,
3037
packages=find_packages(),
3138
include_package_data=True,

0 commit comments

Comments
 (0)