From d950315d31e2a909f461c1f4e5d89940b87a99b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Fri, 16 Feb 2018 22:53:25 +0100 Subject: [PATCH] add sort options to compound list (#43 WIP) Former-commit-id: be28f3ef1caeaada5be3293fc092906141b4ab25 --- ippisite/ippidb/templates/compound_list.html | 10 ++++++++++ ippisite/ippidb/views.py | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index 8d6a65a5..0487ab61 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -67,6 +67,16 @@ {% endif %} {% endif %} </span> + <div class="dropdown"> + <button class="btn btn-secondary dropdown-toggle" type="button" id="sortMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + <i class="fas fa-sort-amount-down" title="sort by"></i> + </button> + <div class="dropdown-menu" aria-labelledby="sortMenuButto"> + {% for sort_by_option, verbose_name in sort_by_options.items %} + <a class="dropdown-item {% if sort_by_option == sort_by %}active{% endif %}" href="#" onclick="modifyUrl('sort_by','{{ sort_by_option }}')">{{ verbose_name }}</a> + {% endfor %} + </div> + </div> <span class="btn-group col-md-2"> <a class="btn btn-default btn-outline-primary {% if display == 'v' %}active{% endif %}" href="#" {% if display != 'v' %}onclick="modifyUrl('display', 'v')"{% endif %}> <i class="fa fa-th" title="Vignettes"></i> diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index f6dea702..958d2b86 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -198,6 +198,9 @@ def compound_list(request): boundcomplexes = ProteinDomainBoundComplex.objects.exclude(id__in=request.GET.getlist('boundcomplex')) if boundcomplexes_all is None: boundcomplexes = boundcomplexes[:5] + sort_by_options = ['id', 'molecular_weight', 'a_log_p', 'nb_aromatic_sssr', 'nb_chiral_centers'] + sort_by = request.GET.get('sort_by', 'id') + compounds = compounds.order_by(sort_by) compounds = compounds.distinct() count = compounds.count() # handle pagination in compounds list @@ -215,6 +218,7 @@ def compound_list(request): if display not in ['l', 't']: display = 'v' compound_fields = {f.name: f.verbose_name for f in Compound._meta.get_fields() if not(f.is_relation)} + sort_by_options = {sort_by_option: compound_fields[sort_by_option] for sort_by_option in sort_by_options} fields = request.GET.get('fields',['id', 'common_name', 'molecular_weight', 'a_log_p', 'compound_action_pdb_ids', 'biblio_refs']) return render(request, 'compound_list.html', {'compounds': compounds, 'count': count, @@ -232,7 +236,9 @@ def compound_list(request): 'boundcomplexes_all': boundcomplexes_all, 'display': display, 'compound_fields': compound_fields, - 'fields': fields + 'fields': fields, + 'sort_by': sort_by, + 'sort_by_options': sort_by_options }) def compound_card(request, compound_id): -- GitLab