web/hdalab/views/ajax.py
changeset 134 75f8f05f9a60
parent 133 e821a1ae9773
child 135 dd6578e36a57
equal deleted inserted replaced
133:e821a1ae9773 134:75f8f05f9a60
   168     if contentlist is None:
   168     if contentlist is None:
   169         contenus = sorted(contenus.values(),key=lambda e: -e['score'])
   169         contenus = sorted(contenus.values(),key=lambda e: -e['score'])
   170     else:
   170     else:
   171         contenus = contenus.values()
   171         contenus = contenus.values()
   172 
   172 
   173     tagqs = tagqs.annotate(nb=Count('datasheet')).order_by('-nb')[:tag_count]
   173     #tagqs = tagqs.annotate(nb=Count('datasheet')).order_by('-nb')[:tag_count]
       
   174     tagqs = tagqs.annotate(nb=Count('datasheet')).order_by('-nb').only('id','label')[:tag_count]
       
   175     # hack to add only necessary fileds in the group by
       
   176     # contournement bug https://code.djangoproject.com/ticket/17144
       
   177     tagqs.query.clear_select_fields()
       
   178     tagqs.query.add_fields(['id','label'], False)
       
   179     tagqs.query.set_group_by()
       
   180 
       
   181     #hack : django bug
   174 
   182 
   175     tags = [{'id': tag.id, 'label': tag.label, 'score': tag.nb} for tag in tagqs]
   183     tags = [{'id': tag.id, 'label': tag.label, 'score': tag.nb} for tag in tagqs]
   176 
   184 
   177     countryqs = countryqs.annotate(nb=Count('includes__tag__taggedsheet'))
   185     countryqs = countryqs.annotate(nb=Count('includes__tag__taggedsheet'))
   178     countries = dict([(country.dbpedia_uri, country.nb) for country in countryqs])
   186     countries = dict([(country.dbpedia_uri, country.nb) for country in countryqs])