summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-27 19:33:35 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-27 19:33:35 +0200
commit77a0f47a7b3bfc8cf4abef63f061bb8b11383f2e (patch)
treead8e0d5d2805f6a920f7db95f4c0c6dd7ed4a220
parent37fc375a42685f65eddfe5a02a7f5401a2835557 (diff)
downloadIshtar-77a0f47a7b3bfc8cf4abef63f061bb8b11383f2e.tar.bz2
Ishtar-77a0f47a7b3bfc8cf4abef63f061bb8b11383f2e.zip
Merge: better layout - fix max page
-rw-r--r--archaeological_warehouse/models.py1
-rw-r--r--ishtar_common/templates/ishtar/merge.html22
-rw-r--r--ishtar_common/views.py11
3 files changed, 26 insertions, 8 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 3dd3f08e8..a93a0917d 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -148,6 +148,7 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem,
dct_orga["organization_type"] = orga_type
dct_orga["name"] = self.name
orga = Organization.objects.create(**dct_orga)
+ orga.save() # force duplicates
self.organization = orga
for k in Address.FIELDS:
if k == "alt_address_is_prefered":
diff --git a/ishtar_common/templates/ishtar/merge.html b/ishtar_common/templates/ishtar/merge.html
index a0bd0dcfd..7f46231f1 100644
--- a/ishtar_common/templates/ishtar/merge.html
+++ b/ishtar_common/templates/ishtar/merge.html
@@ -3,14 +3,26 @@
{% block content %}
<h2>{% trans "Merge" %}</h2>
<div class='form container'>
-<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <label>{%trans "Every operation on this form is irreversible"%}</label></p>
- <p>{% if previous_page %}<a href='{% url current_url 1 %}'>&Larr;</a><a href='{% url current_url previous_page %}'>&larr;</a>{% else %}&nbsp;{% endif %}
- {% trans "Page " %}{{current_page}}/{{max_page}}
-{% if next_page %}<a href='{% url current_url next_page %}'>&rarr;</a><a href='{% url current_url max_page %}'>&Rarr;</a>{% else %}&nbsp;{% endif %} </p>
+<div class='alert alert-warning'>
+ <i class="fa fa-exclamation-triangle"
+ aria-hidden="true"></i>
+ <label>{%trans "Every operation on this form is irreversible"%}</label>
+</div>
+<div class="text-center mb-3">
+ <div class="btn-group" role="group">
+ {% if previous_page %}<a href='{% url current_url 1 %}' class="btn btn-secondary">&Larr;</a><a href='{% url current_url previous_page %}' class="btn btn-secondary">&larr;</a>
+ {% else %}<a href="#" class="btn btn-secondary disabled" disabled="disabled">&Larr;</a><a href='#' class="btn btn-secondary disabled" disabled="disabled">&larr;</a>
+ {% endif %}
+ <span class="btn btn-light disabled">{% trans "Page " %}{{current_page}}/{{max_page}}</span>
+ {% if next_page %}<a href='{% url current_url next_page %}' class="btn btn-secondary">&rarr;</a><a href='{% url current_url max_page %}' class="btn btn-secondary">&Rarr;</a>
+ {% else %}<a href="#" class="btn btn-secondary disabled" disabled="disabled">&rarr;</a><a href='#' class="btn btn-secondary disabled" disabled="disabled">&Rarr;</a>
+ {% endif %}
+ </div>
+</div>
<form action="." method="post">{% csrf_token %}
{{formset.management_form}}
{% for form in formset %}{% for hidden_field in form.hidden_fields %}{{hidden_field}}{% endfor %}{% endfor %}
- <table id='merge-table'>
+ <table id='merge-table' class="table table-striped">
<thead>
<tr>
<th colspan='2'>{% trans "Item A" %}</th>
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index bb68f6044..8b4d212a7 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -883,6 +883,7 @@ def reset_wizards(request):
module.views.reset_wizards(request)
return redirect(reverse('start'))
+
ITEM_PER_PAGE = 20
@@ -896,15 +897,19 @@ def merge_action(model, form, key):
model.merge_candidate.through, form=form,
formset=forms.MergeFormSet, extra=0)
q = model.merge_candidate.through.objects
+ count = q.count()
+ max_page = count // ITEM_PER_PAGE
+ if count % ITEM_PER_PAGE != 0:
+ max_page += 1
context = {'current_url': current_url,
'current_page': page,
- 'max_page': q.count() / ITEM_PER_PAGE}
- if page < context["max_page"]:
+ 'max_page': max_page}
+ if page < max_page:
context['next_page'] = page + 1
if page > 1:
context['previous_page'] = page - 1
- item_nb = page * ITEM_PER_PAGE
+ item_nb = (page - 1) * ITEM_PER_PAGE
item_nb_1 = item_nb + ITEM_PER_PAGE
from_key = 'from_' + key
to_key = 'to_' + key