Skip to content
Snippets Groups Projects
Commit 2094daa2 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

first pass at sorting compounds in ascending/descending orders

(refers to #48)


Former-commit-id: 7888802c3ed03d6e8797784ffaa3cf0c0338d589
parent ac03874f
No related branches found
No related tags found
No related merge requests found
......@@ -70,8 +70,8 @@
<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>
{% for sort_by_value, sort_by_entry in sort_by_options.items %}
<a class="dropdown-item {% if sort_by_value == sort_by %}active{% endif %}" href="#" onclick="modifyUrl('sort_by','{{ sort_by_value }}')">{{ sort_by_entry.name }} ({{ sort_by_entry.order }})</a>
{% endfor %}
</div>
</div>
......
......@@ -199,7 +199,7 @@ def compound_list(request):
taxonomies = Taxonomy.objects.exclude(id__in=request.GET.getlist('taxonomy'))
selected_boundcomplexes = ProteinDomainBoundComplex.objects.filter(id__in=request.GET.getlist('boundcomplex'))
boundcomplexes = ProteinDomainBoundComplex.objects.exclude(id__in=request.GET.getlist('boundcomplex'))
sort_by_options = ['id', 'molecular_weight', 'a_log_p', 'nb_aromatic_sssr', 'nb_chiral_centers']
sort_by_option_ids = ['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()
......@@ -219,7 +219,10 @@ 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}
sort_by_options = {}
for sort_by_option_id in sort_by_option_ids:
sort_by_options[sort_by_option_id] = {'name': compound_fields[sort_by_option_id], 'order':'ascending', 'id': sort_by_option_id}
sort_by_options['-'+sort_by_option_id] = {'name': compound_fields[sort_by_option_id], 'order':'descending', 'id': sort_by_option_id}
fields = request.GET.getlist('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,
......
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