diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-10-02 19:06:05 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-05 10:51:52 +0100 |
commit | a9724939bde8190cd703cfb3491a4374f92e9a40 (patch) | |
tree | 6e7d9806c603b930c1fdf491c98168b37df812b1 | |
parent | 443e6592b9a6ea77feeccc9a9cdd7d3e81bd45aa (diff) | |
download | Ishtar-a9724939bde8190cd703cfb3491a4374f92e9a40.tar.bz2 Ishtar-a9724939bde8190cd703cfb3491a4374f92e9a40.zip |
✨ import sheet
-rw-r--r-- | changelog/en/changelog_2022-06-15.md | 11 | ||||
-rw-r--r-- | changelog/fr/changelog_2023-01-25.md | 1 | ||||
-rw-r--r-- | ishtar_common/models_imports.py | 21 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/import_associated_item.html | 23 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/import_delete.html | 28 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/import_list.html | 2 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/import_table.html | 5 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_import.html | 108 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_import_pdf.html | 14 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_import_window.html | 3 | ||||
-rw-r--r-- | ishtar_common/urls.py | 5 | ||||
-rw-r--r-- | ishtar_common/utils.py | 8 | ||||
-rw-r--r-- | ishtar_common/views.py | 2 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 9 |
14 files changed, 198 insertions, 42 deletions
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 %} + </div> + </div> + {% endif %} + <div class="card w-100"> + <div class="card-header"> + {{ imported|verbose_model_name }} + </div> + <div class="card-body"> + {% else %} + <hr> + {% endifchanged %} + {% if imported.SLUG %} + {% url "show-"|add:imported.SLUG imported.pk "" as current_url %} + {% if current_url %} + <a class="display_details_inline" href="#" onclick='load_window("{% url "show-"|add:imported.SLUG imported.pk "" %}")'> + <i class="fa fa-info-circle" aria-hidden="true"></i> + </a> + {% 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 %} <h3>{{object}}</h3> - {% 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 %}<div><div>{% endcomment %} + </div> </div> </div> - {% endif %} - <div class="card"> - <div class="card-header"> - {{ imported|verbose_model_name }} - </div> - <div class="card-body"> - {% else %} - <hr> - {% endifchanged %} - {% if imported.SLUG %} - {% url "show-"|add:imported.SLUG imported.pk "" as current_url %} - {% if current_url %} - <a class="display_details_inline" href="#" onclick='load_window("{% url "show-"|add:imported.SLUG imported.pk "" %}")'> - <i class="fa fa-info-circle" aria-hidden="true"></i> - </a> - {% endif %} - {% endif %} - {{ imported }} - {% endfor %} - </div> </div> {% block "footer" %} <div id="footer"> diff --git a/ishtar_common/templates/ishtar/import_list.html b/ishtar_common/templates/ishtar/import_list.html index 254ba8429..35821c5bf 100644 --- a/ishtar_common/templates/ishtar/import_list.html +++ b/ishtar_common/templates/ishtar/import_list.html @@ -16,7 +16,7 @@ {% endblock %} {% block content %} -<div class="text-center"> +<div class="text-center m-3"> {% if has_import_table %}<a href="{% url 'new_import' %}" class="btn btn-success"> <i class="fa fa-plus"></i> {% trans 'import (table)' %} </a>{% endif %} diff --git a/ishtar_common/templates/ishtar/import_table.html b/ishtar_common/templates/ishtar/import_table.html index 57e28abc3..0a894b778 100644 --- a/ishtar_common/templates/ishtar/import_table.html +++ b/ishtar_common/templates/ishtar/import_table.html @@ -64,7 +64,10 @@ <tr id="import-{{import.import_id}}" class='import-row{% if import.has_error or not import.pre_import_form_is_valid %}-error{% endif %}{% if import.pk in refreshed_pks %} bg-info{% endif %}'> <td><ul class="simple"> - <li><strong>{{import.name|default:"-"}}</strong></li> + <li> + <a class="display_details" href="#" onclick="load_window('{% url 'show-import' import.pk %}')"><i class="fa fa-info-circle" aria-hidden="true"></i></a> + <strong>{{import.name|default:"-"}}</strong> + </li> <li><small><i class="fa fa-fw fa-calendar" aria-hidden="true"></i> {{import.creation_date|date:"DATE_FORMAT"}} {{import.creation_date|time:"H:i"}} - {% if import.end_date %}{{import.end_date|date:"DATE_FORMAT"}} {{import.end_date|time:"H:i"}}{% endif %}</small></li> <li><small><i class="fa fa-fw fa-user" aria-hidden="true"></i> {{import.user}}</small></li> </ul></td> diff --git a/ishtar_common/templates/ishtar/sheet_import.html b/ishtar_common/templates/ishtar/sheet_import.html new file mode 100644 index 000000000..6ee4837a9 --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_import.html @@ -0,0 +1,108 @@ +{% extends "ishtar/sheet.html" %} +{% load i18n window_header window_field window_tables %} + +{% block head_title %}<strong>{% trans "Import" %}</strong> – {{item.name}}{% endblock %} + +{% block toolbar %} +{% window_nav item window_id 'show-import' %} +{% endblock %} + +{% block content %} +{% trans "Source" as source_label %} +{% trans "Media" as media_label %} +{% trans "Result" as result_label %} +{% trans "Error" as error_label %} +{% trans "Match" as match_label %} + +{% with current_import=item %}{% with object=item %} +{% with imported_list=object.get_all_imported %} +{% with updated_list=object.get_all_updated %} + +{% if output != "ODT" and output != "PDF" %} +<ul class="nav nav-tabs" id="{{window_id}}-tabs" role="tablist"> + <li class="nav-item"> + <a class="nav-link active" id="{{window_id}}-general-tab" + data-toggle="tab" href="#{{window_id}}-general" role="tab" + aria-controls="{{window_id}}-general" aria-selected="false"> + {% trans "General" %} + </a> + </li> + {% if imported_list %}<li class="nav-item"> + <a class="nav-link" id="{{window_id}}-created-tab" + data-toggle="tab" href="#{{window_id}}-created" role="tab" + aria-controls="{{window_id}}-general" aria-selected="false"> + {% trans "Created" %} + </a> + </li>{% endif %} + {% if updated_list %}<li class="nav-item"> + <a class="nav-link" id="{{window_id}}-updated-tab" + data-toggle="tab" href="#{{window_id}}-updated" role="tab" + aria-controls="{{window_id}}-updated" aria-selected="false"> + {% trans "Updated" %} + </a> + </li>{% endif %} +</ul> +{% endif %} + +<div class="tab-content" id="{{window_id}}-tab-content"> + <div class="tab-pane fade show active" id="{{window_id}}-general" + role="tabpanel" aria-labelledby="{{window_id}}-general-tab"> + <div class="row mb-3"> + {% field_flex "Name" item.name %} + {% field_flex "Type" item.importer_type %} + + <div class="col-12 col-md-6 col-lg-3 flex-wrap"> + <i class="fa fa-hourglass-start" aria-hidden="true"></i> {{item.creation_date|date:"DATE_FORMAT"}} {{item.creation_date|time:"H:i"}} + {% if item.end_date %}<br><i class="fa fa-hourglass-end" aria-hidden="true"></i> {{item.end_date|date:"DATE_FORMAT"}} {{item.end_date|time:"H:i"}}{% endif %} + </div> + <div class="col-12 col-md-6 col-lg-3 flex-wrap"> + <i class="fa fa-fw fa-user" aria-hidden="true"></i> {{item.user}} + </div> + + {% if item.imported_file %} + <div class="col-12 col-md-6 col-lg-3 flex-wrap"> + {% with file_label=source_label logo='fa fa-fw fa-file-text-o' file_type='source' file=item.imported_file %} + {% include "ishtar/blocks/import_table_buttons_view.html" %} + {% endwith %} + </div> + + {% if item.get_imported_images %} + <div class="col-12 col-md-6 col-lg-3 flex-wrap"> + {% with file_label=media_label logo='fa fa-fw fa-file-image-o' file_type='' file=item.get_imported_images %} + {% include "ishtar/blocks/import_table_buttons_view.html" %} + {% endwith %} + </div>{% endif %} + {% elif item.archive_file %} + <div class="col-12 col-md-6 col-lg-3 flex-wrap"> + <i class="fa fa-fw fa-file-archive-o" aria-hidden="true"></i> <a href='{{item.archive_file.url}}'>{% trans "Archive" context "name" %}</a> + </div>{% endif %} + </div> + </div> + {% if imported_list %} + <div class="tab-pane fade" id="{{window_id}}-created" + role="tabpanel" aria-labelledby="{{window_id}}-created-tab"> + <div class="row"> + {% for accessor, imported in imported_list %} + {% include "ishtar/import_associated_item.html" %} + {% endfor %} + {% comment %}<div><div>{% endcomment %} + </div> + </div> + </div> + </div>{% endif %} + {% if updated_list %} + <div class="tab-pane fade" id="{{window_id}}-updated" + role="tabpanel" aria-labelledby="{{window_id}}-updated-tab"> + <div class="row"> + {% for accessor, imported in updated_list %} + {% include "ishtar/import_associated_item.html" %} + {% endfor %} + {% comment %}<div><div>{% endcomment %} + </div> + </div> + </div> + </div>{% endif %} +</div> + +{% endwith %}{% endwith %}{% endwith %}{% endwith %} +{% endblock %} diff --git a/ishtar_common/templates/ishtar/sheet_import_pdf.html b/ishtar_common/templates/ishtar/sheet_import_pdf.html new file mode 100644 index 000000000..47f28239f --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_import_pdf.html @@ -0,0 +1,14 @@ +{% extends "ishtar/sheet_import.html" %} +{% block header %} +{% endblock %} +{% block main_head %} +{{ block.super }} +<div id="pdfheader"> +Ishtar – {{APP_NAME}} – {{item}} +</div> +{% endblock %} +{%block head_sheet%}{%endblock%} +{%block main_foot%} +</body> +</html> +{%endblock%} diff --git a/ishtar_common/templates/ishtar/sheet_import_window.html b/ishtar_common/templates/ishtar/sheet_import_window.html new file mode 100644 index 000000000..40ad00320 --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_import_window.html @@ -0,0 +1,3 @@ +{% extends "ishtar/sheet_import.html" %} +{% block main_head %}{%endblock%} +{% block main_foot %}{%endblock%} diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 2dbc13434..099839102 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -455,6 +455,11 @@ urlpatterns += [ name="show-organization", ), url( + r"show-import(?:/(?P<pk>\d+))?/(?P<type>odt|pdf)?$", + views.show_import, + name="show-import", + ), + url( r"autocomplete-organization/([0-9_]+)?$", views.autocomplete_organization, name="autocomplete-organization", diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 0f4e7ecd6..1a7fecba4 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1239,11 +1239,15 @@ def get_all_field_names(model): ) -def get_all_related_m2m_objects_with_model(model): +def get_all_related_m2m_objects_with_model(model, related_name=None): + for f in model._meta.get_fields(include_hidden=True): + if f.many_to_many and f.auto_created: + print(f.related_name) return [ (f, f.model if f.model != model else None) for f in model._meta.get_fields(include_hidden=True) - if f.many_to_many and f.auto_created + if f.many_to_many and f.auto_created and + (not related_name or f.related_name.startswith(related_name)) ] diff --git a/ishtar_common/views.py b/ishtar_common/views.py index ca9df098c..fe0e94e87 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1094,7 +1094,7 @@ get_ishtaruser = get_item(models.IshtarUser, "get_ishtaruser", "ishtaruser") show_town = show_item(models.Town, "town") show_area = show_item(models.Area, "area") - +show_import = show_item(models.Import, "import") def action(request, action_slug, obj_id=None, *args, **kwargs): """ diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index c6110d930..382ea1a5a 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -435,10 +435,11 @@ def show_item(model, name, extra_dct=None, model_for_perms=None): dct.update(extra_dct(request, item)) context_instance = deepcopy(dct) context_instance["output"] = "html" - if hasattr(item, "history_object"): - filename = item.history_object.associated_filename - else: - filename = item.associated_filename + if hasattr(item, "associated_filename"): + if hasattr(item, "history_object"): + filename = item.history_object.associated_filename + else: + filename = item.associated_filename if doc_type == "odt" and settings.ODT_TEMPLATE: tpl = loader.get_template("ishtar/sheet_%s.html" % name) context_instance["output"] = "ODT" |