diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index fde5a67e08058ae9631ef8d3dae0f97a3d699dd5..e98eb1004b7885072a7a07ea858b2a724c8d13cd 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -1,7 +1,7 @@ import json import math -from django.db.models import Max, Min +from django.db.models import Max, Min, Count from django.shortcuts import render from django.http import HttpResponseRedirect, Http404 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger @@ -153,7 +153,7 @@ def compound_list(request): Display the list of compounds """ context = {} - compounds = Compound.objects.order_by('id') + compounds = Compound.objects.all() if request.GET.get('family'): compounds = compounds.filter(compoundaction__ppi__family__id__in=request.GET.getlist('family')) # if filtering on "action on PPI" @@ -179,8 +179,10 @@ 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_option_ids = ['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', 'pubs'] sort_by = request.GET.get('sort_by', 'id') + if sort_by in ['pubs', '-pubs']: + context['compounds'] = context['compounds'].annotate(pubs=Count('refcompoundbiblio')) context['compounds'] = context['compounds'].order_by(sort_by) context['compounds'] = context['compounds'].distinct() # handle pagination in compounds list @@ -201,10 +203,14 @@ def compound_list(request): compound_fields = {f.name: f.verbose_name for f in Compound._meta.get_fields() if not(f.is_relation)} 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} + if sort_by_option_id == 'pubs': + name = 'Number of publications' + else: + name = compound_fields.get(sort_by_option_id) + sort_by_options[sort_by_option_id] = {'name': name, 'order':'ascending', 'id': sort_by_option_id} + sort_by_options['-'+sort_by_option_id] = {'name': name, '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']) + fields = request.GET.getlist('fields',['id', 'common_name', 'molecular_weight', 'a_log_p', 'compound_action_pdb_ids', 'pubs']) if 'id' not in fields: fields.append('id') context['selected_ppis'] = selected_ppis