Skip to content

Commit

Permalink
override import template from suit, to add our warning message, fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed Jun 26, 2015
1 parent 7ff380e commit 1430ad9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
@@ -0,0 +1,97 @@
{% extends "admin/import_export/base.html" %}
{% load url from future %}
{% load i18n admin_urls import_export_tags %}

{% block breadcrumbs_last %}
{% trans "Import" %}
{% endblock %}

{% block content %}

{% if not confirm_form %}
<form action="{{ form_url }}" method="POST" id="{{ opts.module_name }}_form" enctype="multipart/form-data" class="form-horizontal">
{% csrf_token %}


<div class="alert alert-info">
{% trans "This importer will import the following fields: " %}
{% for f in fields %}
<code>{{ f }}</code>
{% endfor %}
</div>

<div class="alert alert-danger">
{% trans "Make sure to include those fieldnames as headers in the first row of your data files!" %}
</div>

{% include 'suit/form_as_fieldset.html' %}
<div class="submit-row submit-row-bottom">
<input type="submit" value="{% trans "Import" %}" class="btn btn-info"/>
</div>

</form>
{% endif %}

{% if result %}
{% if result.has_errors %}
<div class="alert alert-error alert-block">
<h4>{% trans "Errors" %}</h4>
<ul>
{% for error in result.base_errors %}
<li>{{ error.error }}</li>
{% endfor %}
{% for line, errors in result.row_errors %}
{% for error in errors %}
<li>
{% trans "Line number" %}: {{ line }} - {{ error.error }}
<pre class="traceback">{{ error.traceback|linebreaks }}</pre>
</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% else %}

<h2>{% trans "Preview" %}</h2>
<table class="table table-bordered table-hover table-condensed table-striped">
<thead>
<tr>
<th></th>
{% for field in fields %}
<th>{{ field }}</th>
{% endfor %}
</tr>
</thead>
{% for row in result.rows %}
<tr>
<td>
{% 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 %}
</td>
{% for field in row.diff %}
<td>
{{ field }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endif %}

{% endif %}

{% if confirm_form %}
<form action="{% url opts|admin_urlname:"process_import" %}" method="POST">
{% csrf_token %}
{{ confirm_form.as_p }}
<input class="btn btn-success" name="confirm" type="submit" value="{% trans "Confirm import" %}">
</form>
{% endif %}
{% endblock %}
2 changes: 2 additions & 0 deletions voseq/public_interface/admin.py
Expand Up @@ -43,6 +43,8 @@ class Meta:

# Customize what and the way you show it
class VouchersAdmin(ImportExportModelAdmin):
import_template_name = 'admin/public_interface/vouchers/batch_import.html'

list_display = ['code', 'genus', 'species', 'sex', 'voucher', 'country', 'collector']
ordering = ['code']
search_fields = ['=code', '=genus', '=species']
Expand Down

0 comments on commit 1430ad9

Please sign in to comment.