django-spreadsheets 1.4.2__tar.gz → 1.4.4__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.
Files changed (30) hide show
  1. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/PKG-INFO +8 -7
  2. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/README.md +5 -4
  3. django_spreadsheets-1.4.4/django_spreadsheets/__init__.py +1 -0
  4. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/base_config.py +0 -14
  5. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/importer.py +6 -5
  6. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/shortcuts.py +5 -5
  7. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/validation.py +6 -0
  8. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/pyproject.toml +4 -4
  9. django_spreadsheets-1.4.2/django_spreadsheets/__init__.py +0 -1
  10. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/LICENSE +0 -0
  11. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/admin.py +0 -0
  12. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/apps.py +0 -0
  13. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/autodiscover.py +0 -0
  14. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/conf/__init__.py +0 -0
  15. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/conf/settings.py +0 -0
  16. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/constants.py +0 -0
  17. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/errors.py +0 -0
  18. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/exceptions.py +0 -0
  19. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/exporter.py +0 -0
  20. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/forms.py +0 -0
  21. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/locale/fr/LC_MESSAGES/django.mo +0 -0
  22. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/locale/fr/LC_MESSAGES/django.po +0 -0
  23. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/registry.py +0 -0
  24. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/templates/spreadsheets/base.html +0 -0
  25. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/templates/spreadsheets/done.html +0 -0
  26. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/templates/spreadsheets/export_index.html +0 -0
  27. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/templates/spreadsheets/import_index.html +0 -0
  28. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/templates/spreadsheets/wizard.html +0 -0
  29. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/urls.py +0 -0
  30. {django_spreadsheets-1.4.2 → django_spreadsheets-1.4.4}/django_spreadsheets/views.py +0 -0
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: django_spreadsheets
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: Import from and export to XLSX files with data validation.
5
- Home-page: https://gitlab.com/kapt/open-source/django-spreadsheets
6
5
  License: BSD-3-Clause
7
6
  Author: Kapt dev team
8
7
  Author-email: dev@kapt.mobi
@@ -14,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
14
13
  Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
17
  Requires-Dist: Django (>=3.0,<5)
18
18
  Requires-Dist: django-formtools (>=2.5.1,<3.0.0)
19
19
  Requires-Dist: openpyxl (>=3.1.5,<4.0.0)
@@ -111,7 +111,8 @@ Validate that the configuration version stored in the file is the same as the `S
111
111
 
112
112
  ### Sheets validation
113
113
 
114
- Validate that all sheets in this `SpreadsheetConfig` class used, exist in imported file. Validate that all sheets in imported file, exist in this `SpreadsheetConfig` class used.
114
+ - Validate that all sheets in the selected `SpreadsheetConfig` class, exist in imported file.
115
+ - Validate that all sheets in imported file, exist in the selected `SpreadsheetConfig` class.
115
116
 
116
117
  ### Columns headers validation
117
118
 
@@ -141,8 +142,8 @@ If you want to import data in y our database from this spreadsheet, you need to
141
142
  def update_database(self, sheets):
142
143
  for sheet_name, rows in sheets.items():
143
144
  for row in rows:
144
- for value in row:
145
- print(value)
145
+ for cell_value in row:
146
+ print(cell_value)
146
147
  ```
147
148
 
148
149
 
@@ -174,7 +175,7 @@ Inherit this class to describe your sheets' configuration. Each attribute descri
174
175
 
175
176
  To create a _boolean_ validation, you may use a `list` validation type with `django_spreadsheets.constants.YES_NO_CHOICES` as `formula1` value. To ensure a boolean value is displayed in your exported file, add `"number_format": "BOOLEAN"` in your column configuration.
176
177
 
177
- The `formula1` and `formula2` keys accept callables as values.
178
+ The `formula1` and `formula2` keys accept callable as values. As the attributes of the `SheetConfig` class are assigned at initialization, you must use a callable to retrieve values from the database. Otherwise, those values will not be refreshed until the django process restart.
178
179
 
179
180
  ## Note on number format
180
181
 
@@ -89,7 +89,8 @@ Validate that the configuration version stored in the file is the same as the `S
89
89
 
90
90
  ### Sheets validation
91
91
 
92
- Validate that all sheets in this `SpreadsheetConfig` class used, exist in imported file. Validate that all sheets in imported file, exist in this `SpreadsheetConfig` class used.
92
+ - Validate that all sheets in the selected `SpreadsheetConfig` class, exist in imported file.
93
+ - Validate that all sheets in imported file, exist in the selected `SpreadsheetConfig` class.
93
94
 
94
95
  ### Columns headers validation
95
96
 
@@ -119,8 +120,8 @@ If you want to import data in y our database from this spreadsheet, you need to
119
120
  def update_database(self, sheets):
120
121
  for sheet_name, rows in sheets.items():
121
122
  for row in rows:
122
- for value in row:
123
- print(value)
123
+ for cell_value in row:
124
+ print(cell_value)
124
125
  ```
125
126
 
126
127
 
@@ -152,7 +153,7 @@ Inherit this class to describe your sheets' configuration. Each attribute descri
152
153
 
153
154
  To create a _boolean_ validation, you may use a `list` validation type with `django_spreadsheets.constants.YES_NO_CHOICES` as `formula1` value. To ensure a boolean value is displayed in your exported file, add `"number_format": "BOOLEAN"` in your column configuration.
154
155
 
155
- The `formula1` and `formula2` keys accept callables as values.
156
+ The `formula1` and `formula2` keys accept callable as values. As the attributes of the `SheetConfig` class are assigned at initialization, you must use a callable to retrieve values from the database. Otherwise, those values will not be refreshed until the django process restart.
156
157
 
157
158
  ## Note on number format
158
159
 
@@ -0,0 +1 @@
1
+ __version__ = "1.4.4"
@@ -47,20 +47,6 @@ class SheetConfig(metaclass=IndexedAttributesMeta):
47
47
  ```
48
48
  """
49
49
 
50
- def __init__(self, *args, **kwargs):
51
- super().__init__(*args, **kwargs)
52
-
53
- # Replace functions found in formula1 and formula2 by their return values
54
- for column_name, column_config in self.items():
55
- validation_config = column_config.get("validation")
56
- if validation_config:
57
- formula1 = validation_config.get("formula1")
58
- if callable(formula1):
59
- self[column_name]["validation"]["formula1"] = formula1()
60
- formula2 = validation_config.get("formula2")
61
- if callable(formula2):
62
- self[column_name]["validation"]["formula2"] = formula2()
63
-
64
50
  def __getitem__(self, key):
65
51
  return getattr(self, key)
66
52
 
@@ -484,10 +484,14 @@ class Importer:
484
484
  if not is_required and cell.value in (None, ""):
485
485
  continue
486
486
 
487
+ choices = validation_config.get("formula1")
488
+ if callable(choices):
489
+ choices = choices()
490
+
487
491
  try:
488
492
  next(
489
493
  choice
490
- for choice in validation_config["formula1"]
494
+ for choice in choices
491
495
  if choice.lower()
492
496
  == self.clean_string(cell.value).lower()
493
497
  )
@@ -514,10 +518,7 @@ class Importer:
514
518
  _("Please select an existing element."),
515
519
  )
516
520
  ]
517
- + [
518
- (choice, choice)
519
- for choice in validation_config["formula1"]
520
- ],
521
+ + [(choice, choice) for choice in choices],
521
522
  }
522
523
 
523
524
  if must_break_row_loop:
@@ -35,16 +35,16 @@ def extract_rows(
35
35
 
36
36
  columns = {}
37
37
  for cell in row:
38
- column_key = columns_keys[cell.column - 1]
38
+ try:
39
+ column_key = columns_keys[cell.column - 1]
40
+ except IndexError:
41
+ ... # Ignore all content on columns not present in column_keys (ie: not described in the sheet's config)
39
42
  value = cell.value
40
43
 
41
44
  if isinstance(value, str):
42
45
  value = value.strip()
43
46
 
44
- try:
45
- columns[column_key] = value
46
- except IndexError:
47
- ...
47
+ columns[column_key] = value
48
48
  yield cell.row, columns
49
49
 
50
50
 
@@ -56,6 +56,8 @@ class ValidationMixin:
56
56
  """
57
57
  try:
58
58
  choices = validation_config["formula1"]
59
+ if callable(choices):
60
+ choices = choices()
59
61
  except KeyError as e:
60
62
  raise KeyError(
61
63
  "There is no `formula1` key in your validation configuration."
@@ -136,7 +138,11 @@ class ValidationMixin:
136
138
 
137
139
  def setup_type_validation(self, validation_config):
138
140
  formula1 = validation_config.get("formula1")
141
+ if callable(formula1):
142
+ formula1 = formula1()
139
143
  formula2 = validation_config.get("formula2")
144
+ if callable(formula2):
145
+ formula2 = formula2()
140
146
 
141
147
  return DataValidation(
142
148
  type=validation_config.get("type"),
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django_spreadsheets"
3
- version = "1.4.2"
3
+ version = "1.4.4"
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"
@@ -16,16 +16,16 @@ Django = ">=3.0,<5"
16
16
  django-formtools = "^2.5.1"
17
17
  openpyxl = "^3.1.5"
18
18
 
19
- [tool.poetry.dev-dependencies]
19
+ [tool.poetry.group.dev.dependencies]
20
20
  gitchangelog = "^3.0.4"
21
21
  bumpversion = "^0.6.0"
22
22
  black = "~21.9b0"
23
23
  flake8 = "~3.9.2"
24
24
  isort = "~5.9.3"
25
- djhtml = "~1.4.20"
25
+ djhtml = "~3.0.9"
26
26
 
27
27
  [build-system]
28
- requires = ["poetry-core>=1.4.2", "setuptools"]
28
+ requires = ["poetry-core>=1.4.4", "setuptools"]
29
29
  build-backend = "poetry.core.masonry.api"
30
30
 
31
31
  [tool.isort]
@@ -1 +0,0 @@
1
- __version__ = "1.4.2"