# HG changeset patch # User cavaliet # Date 1385133210 -3600 # Node ID 27f7e1083627a523b0de0b4648a03a05e2d12683 # Parent c0cd36df74a0cf310bd1dc19137e76c4bc8eb959 debug css and 0018160 diff -r c0cd36df74a0 -r 27f7e1083627 src/jocondelab/static/jocondelab/css/front-notice.css --- a/src/jocondelab/static/jocondelab/css/front-notice.css Thu Nov 21 19:23:40 2013 +0100 +++ b/src/jocondelab/static/jocondelab/css/front-notice.css Fri Nov 22 16:13:30 2013 +0100 @@ -23,11 +23,11 @@ } .describe-mode .notice-images img { - max-height: 480px; box-shadow: 0 0 3px #999999; + max-height: 480px; box-shadow: 0 0 3px #999999; max-width: 95%; } .describe-mode .notice-images li:nth-child(n+2) img { - max-height: 160px; + max-height: 160px; margin-top: 5px; } .describe-title { diff -r c0cd36df74a0 -r 27f7e1083627 src/jocondelab/views/front_office.py --- a/src/jocondelab/views/front_office.py Thu Nov 21 19:23:40 2013 +0100 +++ b/src/jocondelab/views/front_office.py Fri Nov 22 16:13:30 2013 +0100 @@ -324,15 +324,23 @@ terms.append(t) known_uris.append(uri) else: - # When we're in sort by most frequent terms - tqs = self.image_extra(tqs.order_by('-nb_illustrated_notice'))[:60] - terms = tqs.values('image_url','dbpedia_fields__thumbnail','dbpedia_uri','dbpedia_fields__abstract','dbpedia_fields__label') + # First optimised query with sum of nb of notices + terms = tqs.values('dbpedia_uri','dbpedia_fields__abstract','dbpedia_fields__label').annotate(num_not=Sum('nb_illustrated_notice')).order_by('-num_not')[:60] + # Second query to get images and create dict dbpedia_uri:image_url + img_qs = self.image_extra(Term.objects.filter(dbpedia_uri__in=[t['dbpedia_uri'] for t in terms])).values_list('dbpedia_uri','image_url') + # Build img_dict by avoiding None values + img_dict = {} + for (uri,img) in img_qs: + if img: + img_dict[uri] = img + # Build term list terms = [{ "dbpedia_uri": t['dbpedia_uri'], "label": t.get('dbpedia_fields__label',t.get('label','')), "abstract": t['dbpedia_fields__abstract'], - "image_url": "%s%s"%(settings.JOCONDE_IMAGE_BASE_URL, t.get('image_url','')) - } for t in terms] + "image_url": "%s%s"%(settings.JOCONDE_IMAGE_BASE_URL, img_dict.get(t['dbpedia_uri'],'')) + } for t in terms] + context['termcount'] = len(terms) else: # When ordering is by translated label, we query the DbpediaFields table