diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-10-05 13:14:56 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-02-05 10:51:52 +0100 | 
| commit | 71d9b6fdc1b48f0a31c3c2f348bb715d9dde155b (patch) | |
| tree | 79753e031ae9f190bde9e17429ce302379979a86 | |
| parent | 6393088eb7490f6dbb9a74a12184ca5cb0e11433 (diff) | |
| download | Ishtar-71d9b6fdc1b48f0a31c3c2f348bb715d9dde155b.tar.bz2 Ishtar-71d9b6fdc1b48f0a31c3c2f348bb715d9dde155b.zip | |
✨ improve import and import group sheet
- link to errors, match, result files
- pre import values
- link to associated imports and group imports
| -rw-r--r-- | ishtar_common/models_imports.py | 84 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/sheet_import.html | 2 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/sheet_import_gen.html | 55 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/sheet_importgroup.html | 2 | 
4 files changed, 119 insertions, 24 deletions
| diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 84ea42112..1723fc5bf 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -1499,6 +1499,20 @@ class ImportGroup(BaseImport):          return False      @property +    def pre_import_items(self) -> list: +        """ +        Get list of tuple : (label, value) of pre-import values for this group import. Cached in memory. +        :return: pre import as a list of 2-tuple +        """ +        if hasattr(self, "_pre_import_items"): +            return self._pre_import_items +        values = [] +        for imprt in self.imports.all(): +            values += imprt.pre_import_items +        self._pre_import_items = values +        return values + +    @property      def has_error(self) -> bool:          return any(1 for imprt in self.imports.all() if imprt.has_error) @@ -1949,6 +1963,55 @@ class Import(BaseImport):                  return False          return True +    def _get_pre_import_value(self, value, target): +        if value == "": +            return +        many = target.formater_type.many_split +        if many: +            if value.startswith("['") and value.endswith("']"): +                value = value[2:-2].split("', '") +        associated_model = target.formater_type.associated_model +        if associated_model: +            if many: +                try: +                    value = [associated_model.objects.get(pk=int(pk)) for pk in value] +                except (associated_model.DoesNotExist, ValueError): +                    return +            else: +                try: +                    value = associated_model.objects.get(pk=value) +                except (associated_model.DoesNotExist, ValueError): +                    return +        return value + +    @property +    def pre_import_items(self) -> list: +        """ +        Get list of tuple : (label, value) of pre-import values for this import. Cached in memory. +        :return: pre import as a list of 2-tuple +        """ +        if hasattr(self, "_pre_import_items"): +            return self._pre_import_items +        values = [] +        for column in self.importer_type.columns.filter(col_number__lte=0): +            q = ImportColumnValue.objects.filter(column=column, import_item=self) +            if not q.count(): +                continue +            column_value = q.all()[0] +            q = column_value.column.targets.all() +            if not q.count(): +                continue + +            target = q.all()[0] +            value = column_value.value +            value = self._get_pre_import_value(value, target) +            if value is None: +                continue + +            values.append((column_value.column.label, value)) +        self._pre_import_items = values +        return values +      @property      def pre_import_values(self) -> dict:          """ @@ -1966,27 +2029,12 @@ class Import(BaseImport):              q = column_value.column.targets.all()              if not q.count():                  continue -            target = q.all()[0] +            target = q.all()[0]              value = column_value.value -            if value == "": +            value = self._get_pre_import_value(value, target) +            if value is None:                  continue -            many = target.formater_type.many_split -            if many: -                if value.startswith("['") and value.endswith("']"): -                    value = value[2:-2].split("', '") -            associated_model = target.formater_type.associated_model -            if associated_model: -                if many: -                    try: -                        value = [associated_model.objects.get(pk=int(pk)) for pk in value] -                    except (associated_model.DoesNotExist, ValueError): -                        continue -                else: -                    try: -                        value = associated_model.objects.get(pk=value) -                    except (associated_model.DoesNotExist, ValueError): -                        continue              keys = target.target.split("__")              dct = generate_dict_from_list(keys, value) diff --git a/ishtar_common/templates/ishtar/sheet_import.html b/ishtar_common/templates/ishtar/sheet_import.html index 8685d9ae8..be5e12340 100644 --- a/ishtar_common/templates/ishtar/sheet_import.html +++ b/ishtar_common/templates/ishtar/sheet_import.html @@ -1,7 +1,7 @@  {% extends "ishtar/sheet.html" %}  {% load i18n window_header window_field window_tables %} -{% block head_title %}<strong>{% trans "Import" %}</strong> – {{item.name}}{% endblock %} +{% block head_title %}<strong>{% trans "Import" %}</strong> – {{item.name}} – {{item.importer_type}}{% endblock %}  {% block toolbar %}  {% window_nav item window_id 'show-import' %} diff --git a/ishtar_common/templates/ishtar/sheet_import_gen.html b/ishtar_common/templates/ishtar/sheet_import_gen.html index 86c2ac6fe..4078c059b 100644 --- a/ishtar_common/templates/ishtar/sheet_import_gen.html +++ b/ishtar_common/templates/ishtar/sheet_import_gen.html @@ -1,4 +1,4 @@ -{% load i18n window_header window_field window_tables %} +{% load i18n link_to_window window_header window_field window_tables %}  {% trans "Source" as source_label %}  {% trans "Media" as media_label %}  {% trans "Result" as result_label %} @@ -43,12 +43,13 @@        {% 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 %} +        <i class="fa fa-fw fa-user" aria-hidden="true"></i>  {{item.user}}        </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}} +        <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> +      {% field_flex_detail "Import group" item.group %}        {% if item.imported_file %}        <div class="col-12 col-md-6 col-lg-3 flex-wrap"> @@ -67,7 +68,53 @@        <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 %} + +      {% if item.error_file %} +      <div class="col-12 col-md-6 col-lg-3 flex-wrap"> +        {% with file_label=error_label logo='text-danger fa fa-fw fa-exclamation-triangle' file_type='error' file=item.error_file %} +        {% include "ishtar/blocks/import_table_buttons_view.html" %} +        {% endwith %} +      </div> +      {% endif %} + +      {% if item.result_file %} +      <div class="col-12 col-md-6 col-lg-3 flex-wrap"> +        {% with file_label=result_label logo='fa fa-fw fa-th' file_type='result' file=item.result_file %} +        {% include "ishtar/blocks/import_table_buttons_view.html" %} +        {% endwith %} +      </div> +      {% endif %} + +      {% if item.match_file %} +      <div class="col-12 col-md-6 col-lg-3 flex-wrap"> +        {% with file_label=match_label logo='fa fa-fw fa-arrows-h' file_type='match' file=item.match_file %} +        {% include "ishtar/blocks/import_table_buttons_view.html" %} +        {% endwith %} +      </div> +      {% endif %} +      {% with import_list=item.import_list %}{% if import_list %} +      <hr class="col-12"> +      <dl class="col-12 flex-wrap"> +        <dt>{% trans "Associated imports" %}</dt> +        <dd>{% for import in import_list %}{{import|simple_link_to_window}} {{import}}<br>{% endfor %}</dd> +      </dl> +      {% endif %} {% endwith %} +    </div> + + +    {% with pre_import_items=item.pre_import_items %}{% if pre_import_items %} +    <h3>{% trans "Pre-import values "%}</h3> +    <div class="row mb-3">{% for k, v in pre_import_items %} +      <dl class="col-12 col-md-6 col-lg-3 flex-wrap"> +        <dt> +          {{k}} +        </dt> +        <dd> +          {{v}} +        </dd> +      </dl>{% endfor %}      </div> +    {% endif %}{% endwith %}    </div>    {% if imported_list %}    <div class="tab-pane fade" id="{{window_id}}-created" diff --git a/ishtar_common/templates/ishtar/sheet_importgroup.html b/ishtar_common/templates/ishtar/sheet_importgroup.html index 593642945..050da29a2 100644 --- a/ishtar_common/templates/ishtar/sheet_importgroup.html +++ b/ishtar_common/templates/ishtar/sheet_importgroup.html @@ -1,7 +1,7 @@  {% extends "ishtar/sheet.html" %}  {% load i18n window_header window_field window_tables %} -{% block head_title %}<strong>{% trans "Import" %}</strong> – {{item.name}}{% endblock %} +{% block head_title %}<strong>{% trans "Import group" %}</strong> – {{item.name}} – {{item.importer_type}}{% endblock %}  {% block toolbar %}  {% window_nav item window_id 'show-importgroup' %} | 
