Commit d950315d authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add sort options to compound list (#43 WIP)


Former-commit-id: be28f3ef1caeaada5be3293fc092906141b4ab25
parent c67f33f8
......@@ -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>
......
......@@ -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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment