From f58aa8293e992f8a666823f81df8d99af5cd4ef6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 12 Aug 2019 16:33:46 +0200 Subject: Import - match form: only display 250 first matches --- ishtar_common/templates/ishtar/formset_import_match.html | 6 ++++++ ishtar_common/views.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'ishtar_common') diff --git a/ishtar_common/templates/ishtar/formset_import_match.html b/ishtar_common/templates/ishtar/formset_import_match.html index 8997c309a..eda44e2b9 100644 --- a/ishtar_common/templates/ishtar/formset_import_match.html +++ b/ishtar_common/templates/ishtar/formset_import_match.html @@ -12,6 +12,12 @@ {% trans "Back to import list" %}

+ {% if MAX_FIELDS_REACHED %} +
+ {% blocktrans %}Only {{MAX_FIELDS_REACHED}} out of {{TOTAL}} fields have been displayed. + Fill these fields and submit the form to reach the other fields.{% endblocktrans %} +
+ {% endif %} {% if extra_formset.non_form_errors %}
{{extra_formset.non_form_errors.as_ul}}
{% endif %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 8b4d212a7..f867a03cf 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1606,16 +1606,28 @@ class ImportLinkView(IshtarMixin, LoginRequiredMixin, ModelFormSetView): } form_class = forms.TargetKeyForm formset_class = forms.TargetKeyFormset + max_fields = 250 def get_formset_kwargs(self): kwargs = super(ImportLinkView, self).get_formset_kwargs() kwargs['user'] = self.request.user return kwargs - def get_queryset(self): + def full_queryset(self): return self.model.objects.filter( is_set=False, associated_import=self.kwargs['pk']) + def get_queryset(self): + return self.full_queryset()[:self.max_fields] + + def get_context_data(self, **kwargs): + data = super().get_context_data(**kwargs) + total = self.full_queryset().count() + if total > self.max_fields: + data['MAX_FIELDS_REACHED'] = self.max_fields + data['TOTAL'] = total + return data + def get_success_url(self): return reverse('import_link_unmatched', args=[self.kwargs['pk']]) -- cgit v1.2.3