diff --git a/sigi/apps/utils/mixins.py b/sigi/apps/utils/mixins.py index e973c23..9d15f0a 100644 --- a/sigi/apps/utils/mixins.py +++ b/sigi/apps/utils/mixins.py @@ -12,7 +12,7 @@ from django.template.response import TemplateResponse from django.urls import path from django.utils.translation import gettext as _, ngettext from import_export import resources -from import_export.admin import ExportMixin +from import_export.admin import ImportMixin, ExportMixin from import_export.fields import Field from import_export.forms import ExportForm from import_export.signals import post_export @@ -243,6 +243,15 @@ class CartExportMixin(ExportMixin): return TemplateResponse(request, [self.export_template_name], context) +class ImportCartExportMixin(ImportMixin, CartExportMixin): + """ + Import and export mixin. + """ + + #: template for change_list view + change_list_template = "admin/cart/change_list_import_cart_export.html" + + class CartExportReportMixin(CartExportMixin): export_template_name = "admin/import_export/export_report.html" reports = [] diff --git a/sigi/apps/utils/templates/admin/cart/change_list_import_cart_export.html b/sigi/apps/utils/templates/admin/cart/change_list_import_cart_export.html new file mode 100644 index 0000000..e956342 --- /dev/null +++ b/sigi/apps/utils/templates/admin/cart/change_list_import_cart_export.html @@ -0,0 +1,6 @@ +{% extends "admin/cart/change_list_cart_export.html" %} + +{% block object-tools-items %} + {% include "admin/import_export/change_list_import_item.html" %} + {{ block.super }} +{% endblock %} diff --git a/sigi/apps/utils/templates/admin/import_export/change_list.html b/sigi/apps/utils/templates/admin/import_export/change_list.html new file mode 100644 index 0000000..239b1bf --- /dev/null +++ b/sigi/apps/utils/templates/admin/import_export/change_list.html @@ -0,0 +1 @@ +{% extends "admin/change_list.html" %} diff --git a/sigi/apps/utils/templates/admin/import_export/change_list_export_item.html b/sigi/apps/utils/templates/admin/import_export/change_list_export_item.html index 4fb7ccb..99c2356 100644 --- a/sigi/apps/utils/templates/admin/import_export/change_list_export_item.html +++ b/sigi/apps/utils/templates/admin/import_export/change_list_export_item.html @@ -4,7 +4,7 @@ {% if has_export_permission %}
  • - open_in_new + file_download
  • {% endif %} diff --git a/sigi/apps/utils/templates/admin/import_export/change_list_import_item.html b/sigi/apps/utils/templates/admin/import_export/change_list_import_item.html new file mode 100644 index 0000000..3ed472d --- /dev/null +++ b/sigi/apps/utils/templates/admin/import_export/change_list_import_item.html @@ -0,0 +1,10 @@ +{% load i18n %} +{% load admin_urls %} + +{% if has_import_permission %} +
  • + + file_upload + +
  • +{% endif %} diff --git a/sigi/apps/utils/templates/admin/import_export/export.html b/sigi/apps/utils/templates/admin/import_export/export.html index fdcf1ab..4a546d7 100644 --- a/sigi/apps/utils/templates/admin/import_export/export.html +++ b/sigi/apps/utils/templates/admin/import_export/export.html @@ -14,7 +14,7 @@ {% endblock %} {% block breadcrumbs %}{% endblock %} -{% block content_title %}
    {% blocktrans with name=opts.verbose_name_plural %}Exportar {{ name }}{% endblocktrans %}
    {% endblock %} +{% block content_title %}

    {% blocktrans with name=opts.verbose_name_plural %}Exportar {{ name }}{% endblocktrans %}

    {% endblock %} {% block content %}
    {% csrf_token %}
    diff --git a/sigi/apps/utils/templates/admin/import_export/import.html b/sigi/apps/utils/templates/admin/import_export/import.html new file mode 100644 index 0000000..15b4b50 --- /dev/null +++ b/sigi/apps/utils/templates/admin/import_export/import.html @@ -0,0 +1,165 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} +{% load admin_urls %} +{% load import_export_tags %} +{% load static %} + +{% block extrastyle %} + {{ block.super }} + + +{% endblock %} +{% block breadcrumbs %}{% endblock %} +{% block content_title %}

    {% blocktrans with name=opts.verbose_name_plural %}Importar {{ name }}{% endblocktrans %}

    {% endblock %} +{% block content %} + {% if confirm_form %} + {% csrf_token %} + {{ confirm_form.as_p }} +

    + {% trans "Below is a preview of data to be imported. If you are satisfied with the results, click 'Confirm import'" %} +

    +
    + +
    + + {% else %} +
    {% csrf_token %} +

    + {% trans "This importer will import the following fields: " %} + {{ fields|join:", " }} +

    + +
    + {% for field in form %} +
    + {{ field.errors }} + {{ field.label_tag }} + {{ field }} + {% if field.field.help_text %} +

    {{ field.field.help_text|safe }}

    + {% endif %} +
    + {% endfor %} +
    +
    + + + navigate_before + {% trans "Voltar" %} + +
    +
    + {% endif %} + + {% if result %} + {% if result.has_errors %} +
    {% trans "Errors" %}
    + {% for error in result.base_errors %} +
    + {{ error.error }} +
    {{ error.traceback|linebreaks }}
    +
    + {% endfor %} + {% for line, errors in result.row_errors %} + {% for error in errors %} +
    + {% trans "Line number" %}: {{ line }} - {{ error.error }} +
    {{ error.row.values|join:", " }}
    +
    {{ error.traceback|linebreaks }}
    +
    + {% endfor %} + {% endfor %} + {% elif result.has_validation_errors %} +
    {% trans "Some rows failed to validate" %}
    +

    {% trans "Please correct these errors in your data where possible, then reupload it using the form above." %}

    + + + + + + {% for field in result.diff_headers %} + + {% endfor %} + + + + {% for row in result.invalid_rows %} + + + + {% for field in row.values %} + + {% endfor %} + + {% endfor %} + +
    {% trans "Row" %}{% trans "Errors" %}{{ field }}
    {{ row.number }} + {{ row.error_count }} +
    +
      + {% for field_name, error_list in row.field_specific_errors.items %} +
    • + {{ field_name }} +
        + {% for error in error_list %} +
      • {{ error }}
      • + {% endfor %} +
      +
    • + {% endfor %} + {% if row.non_field_specific_errors %} +
    • + {% trans "Non field specific" %} +
        + {% for error in row.non_field_specific_errors %} +
      • {{ error }}
      • + {% endfor %} +
      +
    • + {% endif %} +
    +
    +
    {{ field }}
    + {% else %} +
    {% trans "Preview" %}
    + + + + + {% for field in result.diff_headers %} + + {% endfor %} + + + {% for row in result.valid_rows %} + + + {% for field in row.diff %} + + {% endfor %} + + {% endfor %} +
    {{ field }}
    + {% if row.import_type == 'new' %} + {% trans "New" %} + {% elif row.import_type == 'skip' %} + {% trans "Skipped" %} + {% elif row.import_type == 'delete' %} + {% trans "Delete" %} + {% elif row.import_type == 'update' %} + {% trans "Update" %} + {% endif %} + {{ field }}
    + {% endif %} + {% endif %} +{% endblock %}