From 0d87c88e4d001bb4e448365951d2a75ec602b640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Mon, 13 Nov 2017 14:19:09 +0100 Subject: [PATCH] add back-end gears to filter compounds list on PPIs... Former-commit-id: 83831b68fdff30a54b8f7a3212d0ab72d3347249 --- ippisite/ippidb/templates/compound_list.html | 8 ++++++++ ippisite/ippidb/views.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index 92cec141..51d88c8b 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -12,6 +12,14 @@ <form> <fieldset class="form-group row border border-info m-2"> <div class="bg-info col-12"><legend>PPI</legend></div> + {% for ppi in selected_ppis|slice:":5" %} + <div class="form-check col-12"> + <label class="form-check-label"> + <input class="form-check-input text-right" type="checkbox" checked value="{{ ppi.id }}" onchange="this.form.submit()" name="ppi" style="width: auto; margin-right: inherit!;"> + {{ ppi.name }} + </label> + </div> + {% endfor %} {% for ppi in ppis|slice:":5" %} <div class="form-check col-12"> <label class="form-check-label"> diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index bc416a80..1a088a28 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -182,9 +182,17 @@ def biblio_card(request, source, id_source): 'tad_ppis': tad_ppis}) def compound_list(request): + """ + Display the list of compounds + """ compounds = Compound.objects.all() + # if filtering on "action on PPI" + if request.GET.get('ppi'): + compounds = compounds.filter(compoundaction__ppi__id__in=request.GET.getlist('ppi')) + selected_ppis = Ppi.objects.filter(id__in=request.GET.getlist('ppi')) + ppis = Ppi.objects.exclude(id__in=request.GET.getlist('ppi')) + # handle pagination in compounds list paginator = Paginator(compounds, 5) - ppis = Ppi.objects.all() page = request.GET.get('page') try: compounds = paginator.page(page) @@ -194,4 +202,4 @@ def compound_list(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. compounds = paginator.page(paginator.num_pages) - return render(request, 'compound_list.html', {'compounds': compounds, 'ppis': ppis}) + return render(request, 'compound_list.html', {'compounds': compounds, 'selected_ppis': selected_ppis, 'ppis': ppis}) -- GitLab