django-spreadsheets 1.2.1__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/PKG-INFO +15 -9
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/README.md +14 -8
- django_spreadsheets-1.3.0/django_spreadsheets/__init__.py +1 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/base_config.py +4 -8
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/conf/settings.py +4 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/exporter.py +15 -9
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/importer.py +3 -5
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/validation.py +8 -6
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/pyproject.toml +2 -2
- django_spreadsheets-1.2.1/django_spreadsheets/__init__.py +0 -1
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/LICENSE +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/admin.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/apps.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/autodiscover.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/conf/__init__.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/constants.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/errors.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/exceptions.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/forms.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/locale/fr/LC_MESSAGES/django.mo +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/locale/fr/LC_MESSAGES/django.po +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/registry.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/shortcuts.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/templates/spreadsheets/base.html +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/templates/spreadsheets/done.html +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/templates/spreadsheets/export_index.html +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/templates/spreadsheets/import_index.html +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/templates/spreadsheets/wizard.html +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/urls.py +0 -0
- {django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/views.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django_spreadsheets
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Import from and export to XLSX files with data validation.
|
|
5
5
|
Home-page: https://gitlab.com/kapt/open-source/django-spreadsheets
|
|
6
6
|
License: BSD-3-Clause
|
|
@@ -193,37 +193,43 @@ def get_data_to_export(self):
|
|
|
193
193
|
|
|
194
194
|
# Settings
|
|
195
195
|
|
|
196
|
-
## `
|
|
196
|
+
## `SPREADSHEETS_CONFIG_SHEET_TITLE`
|
|
197
197
|
|
|
198
198
|
Default: `_("Configuration")`
|
|
199
199
|
|
|
200
200
|
The name of the (hidden) config sheet in the generated file. This special sheet is used to store data needed for validation (eg. lists of choices).
|
|
201
201
|
|
|
202
|
-
## `
|
|
202
|
+
## `SPREADSHEETS_MAX_VALIDATION_ROWS`
|
|
203
203
|
|
|
204
204
|
Default: `700`
|
|
205
205
|
|
|
206
|
-
When exporting data, the generated spreadsheet will have at least `
|
|
206
|
+
When exporting data, the generated spreadsheet will have at least `SPREADSHEETS_MAX_VALIDATION_ROWS` rows with data validation set up.
|
|
207
207
|
|
|
208
|
-
## `
|
|
208
|
+
## `SPREADSHEETS_MAX_STYLED_ROWS`
|
|
209
209
|
|
|
210
210
|
Default: `700`
|
|
211
211
|
|
|
212
|
-
When exporting data, the generated spreadsheet will have at least `
|
|
212
|
+
When exporting data, the generated spreadsheet will have at least `SPREADSHEETS_MAX_STYLED_ROWS` rows styled.
|
|
213
213
|
|
|
214
|
-
## `
|
|
214
|
+
## `SPREADSHEETS_COMMENT_AUTHOR`
|
|
215
215
|
|
|
216
216
|
Default: `"Django Spreadsheet"`
|
|
217
217
|
|
|
218
218
|
The name of the author used when adding comments on cells.
|
|
219
219
|
|
|
220
|
-
## `
|
|
220
|
+
## `SPREADSHEETS_VALIDATION_LIST_REPLACEMENT_DELIMITER`
|
|
221
|
+
|
|
222
|
+
Default: `"/"`
|
|
223
|
+
|
|
224
|
+
The delimiter used to replace `,` found in list items as `,` is not permitted inside list items.
|
|
225
|
+
|
|
226
|
+
## `SPREADSHEETS_EXPORT_FILE_NAME`
|
|
221
227
|
|
|
222
228
|
Default: `"export {config_name} {date}.xlsx"`
|
|
223
229
|
|
|
224
230
|
The name of the exported file when downloaded. Token `config_name` and `date` will be replaced respectively by the name of the configuration that is currently exported and the current date.
|
|
225
231
|
|
|
226
|
-
## `
|
|
232
|
+
## `SPREADSHEETS_TEMPLATE_FILE_NAME`
|
|
227
233
|
|
|
228
234
|
Default: `"{config_name} template file.xlsx"`
|
|
229
235
|
|
|
@@ -171,37 +171,43 @@ def get_data_to_export(self):
|
|
|
171
171
|
|
|
172
172
|
# Settings
|
|
173
173
|
|
|
174
|
-
## `
|
|
174
|
+
## `SPREADSHEETS_CONFIG_SHEET_TITLE`
|
|
175
175
|
|
|
176
176
|
Default: `_("Configuration")`
|
|
177
177
|
|
|
178
178
|
The name of the (hidden) config sheet in the generated file. This special sheet is used to store data needed for validation (eg. lists of choices).
|
|
179
179
|
|
|
180
|
-
## `
|
|
180
|
+
## `SPREADSHEETS_MAX_VALIDATION_ROWS`
|
|
181
181
|
|
|
182
182
|
Default: `700`
|
|
183
183
|
|
|
184
|
-
When exporting data, the generated spreadsheet will have at least `
|
|
184
|
+
When exporting data, the generated spreadsheet will have at least `SPREADSHEETS_MAX_VALIDATION_ROWS` rows with data validation set up.
|
|
185
185
|
|
|
186
|
-
## `
|
|
186
|
+
## `SPREADSHEETS_MAX_STYLED_ROWS`
|
|
187
187
|
|
|
188
188
|
Default: `700`
|
|
189
189
|
|
|
190
|
-
When exporting data, the generated spreadsheet will have at least `
|
|
190
|
+
When exporting data, the generated spreadsheet will have at least `SPREADSHEETS_MAX_STYLED_ROWS` rows styled.
|
|
191
191
|
|
|
192
|
-
## `
|
|
192
|
+
## `SPREADSHEETS_COMMENT_AUTHOR`
|
|
193
193
|
|
|
194
194
|
Default: `"Django Spreadsheet"`
|
|
195
195
|
|
|
196
196
|
The name of the author used when adding comments on cells.
|
|
197
197
|
|
|
198
|
-
## `
|
|
198
|
+
## `SPREADSHEETS_VALIDATION_LIST_REPLACEMENT_DELIMITER`
|
|
199
|
+
|
|
200
|
+
Default: `"/"`
|
|
201
|
+
|
|
202
|
+
The delimiter used to replace `,` found in list items as `,` is not permitted inside list items.
|
|
203
|
+
|
|
204
|
+
## `SPREADSHEETS_EXPORT_FILE_NAME`
|
|
199
205
|
|
|
200
206
|
Default: `"export {config_name} {date}.xlsx"`
|
|
201
207
|
|
|
202
208
|
The name of the exported file when downloaded. Token `config_name` and `date` will be replaced respectively by the name of the configuration that is currently exported and the current date.
|
|
203
209
|
|
|
204
|
-
## `
|
|
210
|
+
## `SPREADSHEETS_TEMPLATE_FILE_NAME`
|
|
205
211
|
|
|
206
212
|
Default: `"{config_name} template file.xlsx"`
|
|
207
213
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.3.0"
|
|
@@ -110,6 +110,10 @@ class SpreadsheetConfig:
|
|
|
110
110
|
|
|
111
111
|
comment_author = local_settings.COMMENT_AUTHOR
|
|
112
112
|
|
|
113
|
+
validation_list_replacement_delimiter = (
|
|
114
|
+
local_settings.VALIDATION_LIST_REPLACEMENT_DELIMITER
|
|
115
|
+
)
|
|
116
|
+
|
|
113
117
|
version = 1
|
|
114
118
|
|
|
115
119
|
class Meta:
|
|
@@ -207,13 +211,5 @@ class SpreadsheetConfig:
|
|
|
207
211
|
|
|
208
212
|
return validation_config
|
|
209
213
|
|
|
210
|
-
def init_named_styles(self):
|
|
211
|
-
for named_style in self.named_styles:
|
|
212
|
-
try:
|
|
213
|
-
self.workbook.add_named_style(named_style)
|
|
214
|
-
except ValueError:
|
|
215
|
-
# If the named style is already registered, do nothing
|
|
216
|
-
...
|
|
217
|
-
|
|
218
214
|
def update_database(self, sheets):
|
|
219
215
|
raise NotImplementedError
|
{django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/conf/settings.py
RENAMED
|
@@ -12,6 +12,10 @@ MAX_STYLED_ROWS = getattr(settings, "SPREADSHEETS_MAX_STYLED_ROWS", 700)
|
|
|
12
12
|
|
|
13
13
|
COMMENT_AUTHOR = getattr(settings, "SPREADSHEETS_COMMENT_AUTHOR", "Django Spreadsheet")
|
|
14
14
|
|
|
15
|
+
VALIDATION_LIST_REPLACEMENT_DELIMITER = getattr(
|
|
16
|
+
settings, "SPREADSHEETS_VALIDATION_LIST_REPLACEMENT_DELIMITER", "/"
|
|
17
|
+
)
|
|
18
|
+
|
|
15
19
|
EXPORT_FILE_NAME = getattr(
|
|
16
20
|
settings, "SPREADSHEETS_EXPORT_FILE_NAME", _("export {config_name} {date}.xlsx")
|
|
17
21
|
)
|
|
@@ -11,15 +11,13 @@ from openpyxl.packaging.custom import IntProperty
|
|
|
11
11
|
from openpyxl.styles import Alignment
|
|
12
12
|
|
|
13
13
|
# Local application / specific library imports
|
|
14
|
-
from .base_config import SpreadsheetConfig
|
|
15
14
|
from .conf import settings as local_settings
|
|
16
15
|
from .constants import DEFAULT_HEADER_STYLE_NAME, VERSION_CUSTOM_PROPERTY_NAME
|
|
17
16
|
from .validation import ValidationMixin
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
class Exporter(
|
|
19
|
+
class Exporter(ValidationMixin):
|
|
21
20
|
def __init__(self, config, no_data=False, **kwargs) -> None:
|
|
22
|
-
super().__init__(**kwargs)
|
|
23
21
|
self.config = config
|
|
24
22
|
self.no_data = no_data
|
|
25
23
|
self.workbook = Workbook()
|
|
@@ -52,6 +50,12 @@ class Exporter(SpreadsheetConfig, ValidationMixin):
|
|
|
52
50
|
self.set_rows_height(sheet)
|
|
53
51
|
self.set_column_styles(sheet, columns_count)
|
|
54
52
|
|
|
53
|
+
def get_file_name(self):
|
|
54
|
+
date = localtime(now()).strftime("%Y-%m-%d %Hh%Mm%Ss")
|
|
55
|
+
return local_settings.EXPORT_FILE_NAME.format(
|
|
56
|
+
date=date, config_name=str(self.config)
|
|
57
|
+
)
|
|
58
|
+
|
|
55
59
|
def save_to_file(self):
|
|
56
60
|
self.process()
|
|
57
61
|
|
|
@@ -134,6 +138,14 @@ class Exporter(SpreadsheetConfig, ValidationMixin):
|
|
|
134
138
|
for row_index in range(0, sheet.max_row):
|
|
135
139
|
sheet.row_dimensions[row_index + 1].height = 30
|
|
136
140
|
|
|
141
|
+
def init_named_styles(self):
|
|
142
|
+
for named_style in self.config.named_styles:
|
|
143
|
+
try:
|
|
144
|
+
self.workbook.add_named_style(named_style)
|
|
145
|
+
except ValueError:
|
|
146
|
+
# If the named style is already registered, do nothing
|
|
147
|
+
...
|
|
148
|
+
|
|
137
149
|
def set_column_styles(self, sheet, max_col):
|
|
138
150
|
for col in sheet.iter_cols(
|
|
139
151
|
min_row=2,
|
|
@@ -159,12 +171,6 @@ class Exporter(SpreadsheetConfig, ValidationMixin):
|
|
|
159
171
|
if number_format is not None:
|
|
160
172
|
cell.number_format = number_format
|
|
161
173
|
|
|
162
|
-
def get_file_name(self):
|
|
163
|
-
date = localtime(now()).strftime("%Y-%m-%d %Hh%Mm%Ss")
|
|
164
|
-
return local_settings.EXPORT_FILE_NAME.format(
|
|
165
|
-
date=date, config_name=str(self.config)
|
|
166
|
-
)
|
|
167
|
-
|
|
168
174
|
def set_version(self):
|
|
169
175
|
self.workbook.custom_doc_props.append(
|
|
170
176
|
IntProperty(name=VERSION_CUSTOM_PROPERTY_NAME, value=self.config.version)
|
|
@@ -14,7 +14,6 @@ from openpyxl import load_workbook
|
|
|
14
14
|
from openpyxl.utils.exceptions import InvalidFileException
|
|
15
15
|
|
|
16
16
|
# Local application / specific library imports
|
|
17
|
-
from .base_config import SpreadsheetConfig
|
|
18
17
|
from .constants import VERSION_CUSTOM_PROPERTY_NAME, YES_NO_CHOICES
|
|
19
18
|
from .errors import (
|
|
20
19
|
ConfigVersionWarning,
|
|
@@ -30,9 +29,8 @@ from .errors import (
|
|
|
30
29
|
from .shortcuts import extract_rows, xlsx_to_bool
|
|
31
30
|
|
|
32
31
|
|
|
33
|
-
class Importer
|
|
32
|
+
class Importer:
|
|
34
33
|
def __init__(self, config, file=None, matched_data=None, **kwargs):
|
|
35
|
-
super().__init__(**kwargs)
|
|
36
34
|
self.config = config
|
|
37
35
|
self.load_errors = []
|
|
38
36
|
self._import_errors = []
|
|
@@ -153,9 +151,9 @@ class Importer(SpreadsheetConfig):
|
|
|
153
151
|
except KeyError:
|
|
154
152
|
version_found = None
|
|
155
153
|
|
|
156
|
-
if version_found != self.version:
|
|
154
|
+
if version_found != self.config.version:
|
|
157
155
|
version_warning = ConfigVersionWarning(
|
|
158
|
-
expected=self.version, found=version_found
|
|
156
|
+
expected=self.config.version, found=version_found
|
|
159
157
|
)
|
|
160
158
|
return [version_warning]
|
|
161
159
|
return []
|
|
@@ -42,8 +42,9 @@ class ValidationMixin:
|
|
|
42
42
|
|
|
43
43
|
def setup_list_validation(self, validation_config, name=""):
|
|
44
44
|
"""Setup a data validation on the provided choices.
|
|
45
|
-
Use an inline choice list when the choices do not exceed 255 characters
|
|
46
|
-
and otherwise store de choices in an hidden config
|
|
45
|
+
Use an inline choice list when the choices do not exceed 255 characters
|
|
46
|
+
(Excel limitation), and otherwise store de choices in an hidden config
|
|
47
|
+
sheet.
|
|
47
48
|
|
|
48
49
|
Args:
|
|
49
50
|
formula1 (list): an iterable describing possible values
|
|
@@ -61,7 +62,8 @@ class ValidationMixin:
|
|
|
61
62
|
) from e
|
|
62
63
|
|
|
63
64
|
def format_validation_list_item(item):
|
|
64
|
-
|
|
65
|
+
# items must not contain `,` as it is the official list's items delimiter
|
|
66
|
+
return item.replace(",", self.config.validation_list_replacement_delimiter)
|
|
65
67
|
|
|
66
68
|
prepared_choices = ",".join(
|
|
67
69
|
format_validation_list_item(element)
|
|
@@ -73,10 +75,10 @@ class ValidationMixin:
|
|
|
73
75
|
# If the choices exceed 255 characters, we must store them in an
|
|
74
76
|
# hidden sheet and use a range validation
|
|
75
77
|
try:
|
|
76
|
-
config_sheet = self.workbook[self.config_sheet_title]
|
|
78
|
+
config_sheet = self.workbook[self.config.config_sheet_title]
|
|
77
79
|
except KeyError:
|
|
78
80
|
config_sheet = self.workbook.create_sheet(
|
|
79
|
-
title=self.config_sheet_title, index=99
|
|
81
|
+
title=self.config.config_sheet_title, index=99
|
|
80
82
|
)
|
|
81
83
|
config_sheet.sheet_state = config_sheet.SHEETSTATE_HIDDEN
|
|
82
84
|
|
|
@@ -94,7 +96,7 @@ class ValidationMixin:
|
|
|
94
96
|
|
|
95
97
|
validation_config[
|
|
96
98
|
"choices"
|
|
97
|
-
] = f"{quote_sheetname(self.config_sheet_title)}!${get_column_letter(config_column_cursor)}$2:${get_column_letter(config_column_cursor)}${config_sheet.max_row}"
|
|
99
|
+
] = f"{quote_sheetname(self.config.config_sheet_title)}!${get_column_letter(config_column_cursor)}$2:${get_column_letter(config_column_cursor)}${config_sheet.max_row}"
|
|
98
100
|
return self.setup_range_validation(validation_config)
|
|
99
101
|
|
|
100
102
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "django_spreadsheets"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.3.0"
|
|
4
4
|
description = "Import from and export to XLSX files with data validation."
|
|
5
5
|
authors = ["Kapt dev team <dev@kapt.mobi>"]
|
|
6
6
|
license = "BSD-3-Clause"
|
|
@@ -25,7 +25,7 @@ isort = "~5.9.3"
|
|
|
25
25
|
djhtml = "~1.4.10"
|
|
26
26
|
|
|
27
27
|
[build-system]
|
|
28
|
-
requires = ["poetry-core>=1.
|
|
28
|
+
requires = ["poetry-core>=1.3.0", "setuptools"]
|
|
29
29
|
build-backend = "poetry.core.masonry.api"
|
|
30
30
|
|
|
31
31
|
[tool.isort]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "1.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_spreadsheets-1.2.1 → django_spreadsheets-1.3.0}/django_spreadsheets/conf/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|