From a9724939bde8190cd703cfb3491a4374f92e9a40 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 2 Oct 2023 19:06:05 +0200 Subject: ✨ import sheet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/en/changelog_2022-06-15.md | 11 ++- changelog/fr/changelog_2023-01-25.md | 1 + ishtar_common/models_imports.py | 21 +++- .../templates/ishtar/import_associated_item.html | 23 +++++ ishtar_common/templates/ishtar/import_delete.html | 28 +----- ishtar_common/templates/ishtar/import_list.html | 2 +- ishtar_common/templates/ishtar/import_table.html | 5 +- ishtar_common/templates/ishtar/sheet_import.html | 108 +++++++++++++++++++++ .../templates/ishtar/sheet_import_pdf.html | 14 +++ .../templates/ishtar/sheet_import_window.html | 3 + ishtar_common/urls.py | 5 + ishtar_common/utils.py | 8 +- ishtar_common/views.py | 2 +- ishtar_common/views_item.py | 9 +- 14 files changed, 198 insertions(+), 42 deletions(-) create mode 100644 ishtar_common/templates/ishtar/import_associated_item.html create mode 100644 ishtar_common/templates/ishtar/sheet_import.html create mode 100644 ishtar_common/templates/ishtar/sheet_import_pdf.html create mode 100644 ishtar_common/templates/ishtar/sheet_import_window.html diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md index 0835a89b3..ea40b2b98 100644 --- a/changelog/en/changelog_2022-06-15.md +++ b/changelog/en/changelog_2022-06-15.md @@ -5,11 +5,12 @@ v4.0.XX - 2099-12-31 - pre-import forms - imports form: reorganisation of field order - import table : - - built-in CSV viewer - - automatic progress refresh - - reorganization of fields - - improved presentation - - + - built-in CSV viewer + - automatic progress refresh + - reorganization of fields + - improved presentation +- sheet import + ### Technical ### - update relationship between imports and main items diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md index 1b51d380a..24f0f4841 100644 --- a/changelog/fr/changelog_2023-01-25.md +++ b/changelog/fr/changelog_2023-01-25.md @@ -9,6 +9,7 @@ v4.0.XX - 2099-12-31 - rafraîchissement automatique de l'avancement - réorganisation des champs - amélioration de la présentation +- fiche d'import ### Technique ### - relation de mise à jour entre imports et les éléments principaux diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index af907d44d..02b86849c 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -1744,15 +1744,20 @@ class ImportGroup(BaseImport): self.save() self._archive_pending = False - - def get_all_imported(self): + def _get_all_related(self, key): imported = [] for imp in self.imports.all(): - for related, zorg in get_all_related_m2m_objects_with_model(imp): + for related, zorg in get_all_related_m2m_objects_with_model(imp, related_name=key): accessor = related.get_accessor_name() imported += [(accessor, obj) for obj in getattr(imp, accessor).all()] return sorted(imported, key=lambda i: i[1].__class__.__name__) + def get_all_imported(self): + return self._get_all_related("imported_") + + def get_all_updated(self): + return self._get_all_related("import_updated_") + def save(self, *args, **kwargs): add = self._state.adding super().save(*args, **kwargs) @@ -2547,13 +2552,19 @@ class Import(BaseImport): self.save() self._archive_pending = False - def get_all_imported(self): + def _get_all_related(self, key): imported = [] - for related, zorg in get_all_related_m2m_objects_with_model(self): + for related, zorg in get_all_related_m2m_objects_with_model(self, related_name=key): accessor = related.get_accessor_name() imported += [(accessor, obj) for obj in getattr(self, accessor).all()] return imported + def get_all_imported(self): + return self._get_all_related("imported_") + + def get_all_updated(self): + return self._get_all_related("import_updated_") + def pre_delete_import(sender, **kwargs): # deleted imported items when an import is delete diff --git a/ishtar_common/templates/ishtar/import_associated_item.html b/ishtar_common/templates/ishtar/import_associated_item.html new file mode 100644 index 000000000..359e22a90 --- /dev/null +++ b/ishtar_common/templates/ishtar/import_associated_item.html @@ -0,0 +1,23 @@ +{% load i18n inline_formset verbose_names %} + {% ifchanged imported|verbose_model_name %} + {% if forloop.counter0 %} + + + {% endif %} +
+
+ {{ imported|verbose_model_name }} +
+
+ {% else %} +
+ {% endifchanged %} + {% if imported.SLUG %} + {% url "show-"|add:imported.SLUG imported.pk "" as current_url %} + {% if current_url %} + + + + {% endif %} + {% endif %} + {{ imported }} diff --git a/ishtar_common/templates/ishtar/import_delete.html b/ishtar_common/templates/ishtar/import_delete.html index db3df8fe4..f6698d97d 100644 --- a/ishtar_common/templates/ishtar/import_delete.html +++ b/ishtar_common/templates/ishtar/import_delete.html @@ -14,31 +14,13 @@ {% endblock %}

{{object}}

- {% for accessor, imported in object.get_all_imported %} - {% ifchanged imported|verbose_model_name %} - {% if forloop.counter0 %} + {% for accessor, imported in object.get_all_imported %} + {% include "ishtar/import_associated_item.html" %} + {% endfor %} + {% comment %}
{% endcomment %} +
- {% endif %} -
-
- {{ imported|verbose_model_name }} -
-
- {% else %} -
- {% endifchanged %} - {% if imported.SLUG %} - {% url "show-"|add:imported.SLUG imported.pk "" as current_url %} - {% if current_url %} - - - - {% endif %} - {% endif %} - {{ imported }} - {% endfor %} -
{% block "footer" %}