| author | cavaliet |
| Thu, 31 Oct 2013 12:42:46 +0100 | |
| changeset 171 | 9136e10ad374 |
| parent 163 | bd4fac229345 |
| child 173 | 388c12f7a720 |
| permissions | -rw-r--r-- |
| 86 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Aug 08, 2013 |
|
4 |
||
5 |
@author: rvelt |
|
6 |
''' |
|
7 |
||
| 97 | 8 |
from core.models import (Notice, Thesaurus, Term) |
| 171 | 9 |
from django.conf import settings |
10 |
from django.core.cache import cache |
|
| 106 | 11 |
from django.core.paginator import Paginator |
| 171 | 12 |
from django.db.models import Sum, Count |
13 |
from django.db.models.query import prefetch_related_objects |
|
14 |
from django.shortcuts import redirect |
|
15 |
from django.utils.http import urlencode |
|
16 |
from django.utils.translation import ugettext |
|
| 110 | 17 |
from django.views.generic import DetailView, TemplateView |
| 171 | 18 |
from jocondelab.models import (DbpediaFields, Country, ContributableTerm, TagcloudTerm) |
19 |
import django.utils.simplejson as json |
|
| 110 | 20 |
import random |
| 86 | 21 |
|
| 160 | 22 |
import logging |
23 |
logger = logging.getLogger(__name__) |
|
24 |
||
| 150 | 25 |
def get_terms_by_thesaurus(notice, lang): |
26 |
termsbythesaurus = {} |
|
| 160 | 27 |
for nt in Term.objects.filter(noticeterm__notice=notice, dbpedia_fields=None).select_related('thesaurus__label').order_by('label').distinct(): |
| 150 | 28 |
term = { |
29 |
"thesaurus": nt.thesaurus.label, |
|
30 |
"dbpedia_uri": nt.dbpedia_uri, |
|
31 |
"translated": False, |
|
32 |
"label": nt.label |
|
33 |
} |
|
34 |
th = termsbythesaurus.setdefault(term["thesaurus"], { "translated": [], "untranslated": [] }) |
|
35 |
th["untranslated"].append(term) |
|
| 161 | 36 |
# We use "values" because it avoids an other db request for dbpedia_fields.get(language_code = lang).label |
37 |
for nt in Term.objects.select_related('thesaurus__label,dbpedia_fields').filter(noticeterm__notice=notice, dbpedia_fields__language_code=lang).order_by('dbpedia_fields__label').distinct().values("thesaurus__label", "dbpedia_uri", "dbpedia_fields__label"): |
|
| 150 | 38 |
term = { |
| 161 | 39 |
"thesaurus": nt["thesaurus__label"], |
40 |
"dbpedia_uri": nt["dbpedia_uri"], |
|
| 150 | 41 |
"translated": True, |
| 161 | 42 |
"label": nt["dbpedia_fields__label"] |
| 150 | 43 |
} |
44 |
th = termsbythesaurus.setdefault(term["thesaurus"], { "translated": [], "untranslated": [] }) |
|
45 |
th["translated"].append(term) |
|
46 |
return termsbythesaurus |
|
47 |
||
| 110 | 48 |
class SearchView(TemplateView): |
| 86 | 49 |
|
| 118 | 50 |
# This view is used for |
51 |
# - the home and search pages, displaying random images |
|
52 |
# - search result pages |
|
53 |
# - ajax-fetched results |
|
54 |
||
| 86 | 55 |
def get(self, request): |
| 106 | 56 |
|
| 86 | 57 |
context = {} |
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
58 |
lang = request.GET.get('lang',request.LANGUAGE_CODE)[:2] |
| 106 | 59 |
page = request.GET.get('page',1) |
| 87 | 60 |
querystr = request.GET.get('q', "") |
| 106 | 61 |
is_ajax = request.is_ajax() |
| 110 | 62 |
queryterms = [s.strip(" ") for s in querystr.split(";") if s.strip(" ")] |
| 143 | 63 |
dbpedia_uri = request.GET.get('dbpedia_uri', "") |
64 |
dbpedia_uris = [s.strip(" ") for s in dbpedia_uri.split(";") if s.strip(" ")] |
|
| 111 | 65 |
from_year = request.GET.get('from_year', None) |
66 |
to_year = request.GET.get('to_year', from_year) |
|
67 |
show_years = request.GET.get('show_years',False) |
|
68 |
emptysearch = ((not queryterms) and (not dbpedia_uri) and (not from_year)) |
|
69 |
npp = request.GET.get('count', 12 if emptysearch else 30) |
|
| 118 | 70 |
context["lang"] = lang |
| 106 | 71 |
context["current_page"] = page |
| 108 | 72 |
|
73 |
if self.template_name is None: |
|
74 |
if is_ajax and page > 1: |
|
75 |
self.template_name = "jocondelab/partial/notice_list.html" |
|
| 106 | 76 |
else: |
| 108 | 77 |
if is_ajax: |
78 |
self.template_name = "jocondelab/partial/wrapped_notice_list.html" |
|
79 |
else: |
|
80 |
self.template_name = "jocondelab/front_search.html" |
|
| 86 | 81 |
|
| 162 | 82 |
qs = Notice.objects.prefetch_related("images").filter(image=True) |
| 118 | 83 |
|
| 106 | 84 |
if emptysearch: |
| 171 | 85 |
if not cache.get('notice_count'): |
86 |
cache.set('notice_count', qs.count(), settings.DB_QUERY_CACHE_TIME) |
|
87 |
context["count"] = cache.get('notice_count') |
|
| 160 | 88 |
# Optimize random : order_by('?') is too slow |
| 171 | 89 |
# generate_series(1, 100) and not generate_series(1, 12) to be sure we have existing ids |
90 |
orm_request = """ |
|
91 |
SELECT "core_notice"."id", "core_notice"."ref", "core_notice"."adpt", "core_notice"."appl", "core_notice"."aptn", "core_notice"."attr", "core_notice"."autr", "core_notice"."bibl", "core_notice"."comm", "core_notice"."contact", "core_notice"."coor", "core_notice"."copy", "core_notice"."dacq", "core_notice"."data", "core_notice"."dation", "core_notice"."ddpt", "core_notice"."decv", "core_notice"."deno", "core_notice"."depo", "core_notice"."desc", "core_notice"."desy", "core_notice"."dims", "core_notice"."dmaj", "core_notice"."dmis", "core_notice"."domn", "core_notice"."drep", "core_notice"."ecol", "core_notice"."epoq", "core_notice"."etat", "core_notice"."expo", "core_notice"."gene", "core_notice"."geohi", "core_notice"."hist", "core_notice"."image", "core_notice"."insc", "core_notice"."inv", "core_notice"."label", "core_notice"."labo", "core_notice"."lieux", "core_notice"."loca", "core_notice"."loca2", "core_notice"."mill", "core_notice"."milu", "core_notice"."mosa", "core_notice"."msgcom", "core_notice"."museo", "core_notice"."nsda", "core_notice"."onom", "core_notice"."paut", "core_notice"."pdat", "core_notice"."pdec", "core_notice"."peoc", "core_notice"."peri", "core_notice"."peru", "core_notice"."phot", "core_notice"."pins", "core_notice"."plieux", "core_notice"."prep", "core_notice"."puti", "core_notice"."reda", "core_notice"."refim", "core_notice"."repr", "core_notice"."srep", "core_notice"."stat", "core_notice"."tech", "core_notice"."tico", "core_notice"."titr", "core_notice"."util", "core_notice"."video", "core_notice"."www" |
|
92 |
FROM ( |
|
93 |
SELECT 1 + floor(random() * %i)::integer AS id |
|
94 |
FROM generate_series(1, 100) g |
|
95 |
GROUP BY 1 |
|
96 |
) r |
|
97 |
JOIN "core_notice" USING (id) |
|
98 |
WHERE "core_notice"."image" = true |
|
99 |
LIMIT 12; |
|
100 |
""" |
|
101 |
ns = list(Notice.objects.raw(orm_request % context["count"])) |
|
102 |
# list because prefetch_related_objects needs list and not QuerySet or RawQuerySet |
|
103 |
prefetch_related_objects(ns, ['images']) |
|
| 87 | 104 |
else: |
| 143 | 105 |
uri_cache = {} |
106 |
if dbpedia_uris: |
|
107 |
queryobj = {'dbpedia_uri': dbpedia_uri} |
|
108 |
searchterms = [] |
|
109 |
for i, uri in enumerate(dbpedia_uris): |
|
110 |
fs = DbpediaFields.objects.filter(dbpedia_uri=uri, language_code=lang) |
|
111 |
if fs.exists(): |
|
112 |
firstres = fs[0] |
|
113 |
searchterms.append(firstres.label) |
|
114 |
uri_cache[firstres.label.lower()] = firstres.dbpedia_uri |
|
115 |
if i == 0 and page == 1 and len(dbpedia_uris) == 1: |
|
116 |
context["wkinfo"] = firstres |
|
117 |
fs = fs.values('term_id').distinct() |
|
118 |
qs = qs.filter(noticeterm__term__in=fs) |
|
119 |
elif queryterms: |
|
120 |
searchterms = queryterms |
|
121 |
queryobj = {'q': querystr} |
|
| 118 | 122 |
for i, term in enumerate(queryterms): |
123 |
fs = DbpediaFields.objects.filter(label=term, language_code=lang) |
|
| 143 | 124 |
if fs.exists(): |
125 |
firstres = fs[0] |
|
126 |
uri_cache[firstres.label.lower()] = firstres.dbpedia_uri |
|
127 |
if i == 0 and page == 1 and len(queryterms) == 1: |
|
128 |
context["wkinfo"] = firstres |
|
| 118 | 129 |
fs = fs.values('term_id').distinct() |
| 106 | 130 |
qs = qs.filter(noticeterm__term__in=fs) |
| 143 | 131 |
elif from_year: |
132 |
queryobj = {'from_year': from_year, 'to_year': to_year} |
|
133 |
searchterms = [u"%s – %s"%(from_year, to_year)] |
|
| 111 | 134 |
qs = qs.filter(years__start_year__lte=to_year, years__end_year__gte=from_year) |
| 143 | 135 |
context["queryobj"] = json.dumps(queryobj) |
136 |
context["querystr"] = urlencode(queryobj) |
|
137 |
context["searchterms_label"] = ugettext(u" ET ").join(searchterms) |
|
138 |
context["searchterms_input"] = u";".join(searchterms) |
|
139 |
context["uri_cache"] = json.dumps(uri_cache) |
|
| 118 | 140 |
qs = qs.order_by('id').distinct() |
| 106 | 141 |
paginator = Paginator(qs, npp) |
142 |
context["count"] = paginator.count |
|
143 |
ns = paginator.page(page) |
|
144 |
context["page_count"] = paginator.num_pages |
|
| 86 | 145 |
|
| 106 | 146 |
notices = [] |
147 |
for n in ns: |
|
| 150 | 148 |
termsbythesaurus = get_terms_by_thesaurus(n, lang) |
| 162 | 149 |
# select first image with "_p.jpg" |
150 |
selected_image = None |
|
151 |
for i in n.images.all(): |
|
152 |
if i.relative_url.endswith('p.jpg'): |
|
153 |
selected_image = settings.JOCONDE_IMG_BASE_URL + i.relative_url |
|
154 |
break |
|
| 106 | 155 |
noticedict = { |
156 |
"id": n.id, |
|
157 |
"title": n.titr, |
|
| 143 | 158 |
"designation": " | ".join([ v for v in [ n.deno, n.appl] if v ]), |
| 162 | 159 |
"image": selected_image, |
| 110 | 160 |
"author": n.autr, |
| 111 | 161 |
"terms_by_thesaurus": termsbythesaurus, |
| 150 | 162 |
"datation": termsbythesaurus.get("PERI",{}).get("translated",[]) + termsbythesaurus.get("EPOQ",{}).get("translated",[]) |
| 106 | 163 |
} |
| 143 | 164 |
noticedict['image_title'] = noticedict['title'] if noticedict['title'] else noticedict['designation'] |
| 111 | 165 |
if show_years and n.years.exists(): |
166 |
noticedict["years"] = [n.years.all()[0].start_year, n.years.all()[0].end_year] |
|
| 106 | 167 |
notices.append(noticedict) |
168 |
context["notices"] = notices |
|
| 110 | 169 |
|
| 87 | 170 |
return self.render_to_response(context) |
171 |
||
| 110 | 172 |
class GeoView(TemplateView): |
| 103 | 173 |
|
174 |
template_name = "jocondelab/front_geo.html" |
|
175 |
||
176 |
def get(self, request): |
|
177 |
||
178 |
context = {} |
|
179 |
cqs = Country.objects.order_by('-nb_notices') |
|
180 |
context["countries"] = json.dumps([c for c in cqs.values('dbpedia_uri','iso_code_3','nb_notices')]) |
|
181 |
||
182 |
return self.render_to_response(context) |
|
183 |
||
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
184 |
class NoticeView(DetailView): |
| 87 | 185 |
|
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
186 |
model = Notice |
| 87 | 187 |
template_name = "jocondelab/front_notice.html" |
| 113 | 188 |
show_contributions = True |
| 87 | 189 |
|
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
190 |
def get_context_data(self, **kwargs): |
| 87 | 191 |
|
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
192 |
context = super(NoticeView, self).get_context_data(**kwargs) |
|
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
193 |
lang = self.request.GET.get('lang',self.request.LANGUAGE_CODE)[:2] |
| 87 | 194 |
|
| 148 | 195 |
context["images"] = [settings.JOCONDE_IMG_BASE_URL + i.url for i in self.object.images.exclude(relative_url__endswith='v.jpg').order_by('id')] |
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
196 |
context["title"] = self.object.titr if self.object.titr else self.object.deno |
| 150 | 197 |
context["terms_by_thesaurus"] = get_terms_by_thesaurus(self.object, lang) |
| 101 | 198 |
|
| 113 | 199 |
if self.show_contributions: |
200 |
cqs = self.object.contribution_set.select_related('term__dbpedia_fields') |
|
201 |
contributions = [{ |
|
202 |
"label": ct.term.dbpedia_fields.get(language_code=lang).label, |
|
203 |
"dbpedia_uri": ct.term.dbpedia_uri, |
|
204 |
"contribution_id": ct.id, |
|
205 |
"li_style": "positive" if ct.contribution_count > 0 else "null", |
|
| 123 | 206 |
"font_size": "%.1f"%(12. + .5 * max(0., min(12., ct.contribution_count))), |
207 |
"vote_mode": True |
|
| 113 | 208 |
} for ct in cqs.filter(thesaurus=None,term__dbpedia_fields__language_code=lang).order_by('-contribution_count')] |
209 |
context["contributions"] = contributions |
|
210 |
||
| 101 | 211 |
context['wikipedia_urls'] = json.dumps(settings.WIKIPEDIA_URLS) |
| 108 | 212 |
context['JOCONDE_NOTICE_BASE_URL'] = settings.JOCONDE_NOTICE_BASE_URL |
| 87 | 213 |
|
| 144 | 214 |
notice_history = self.request.session.get('notice_history',[]) |
|
140
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
215 |
if self.object.id in notice_history: |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
216 |
p = notice_history.index(self.object.id) |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
217 |
if p < len(notice_history) - 1: |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
218 |
context['next_notice'] = notice_history[p + 1] |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
219 |
if p > 0: |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
220 |
context['prev_notice'] = notice_history[p - 1] |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
221 |
|
|
100
25636bb50756
Grouped geographical locations and years by dbpedia uri
veltr
parents:
98
diff
changeset
|
222 |
return context |
|
140
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
223 |
|
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
224 |
def describe_view(request): |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
225 |
notice_history = request.session.get('notice_history',[]) |
| 142 | 226 |
all_qs = Notice.objects.filter(image=True, repr='', peri__contains='4e quart 19e siècle', noticeterm__term__id__in=ContributableTerm.objects.values('term__id')) |
227 |
qs = all_qs.exclude(id__in=notice_history) |
|
228 |
found_notices = qs.count() |
|
229 |
if not found_notices: |
|
230 |
notice_history = [] |
|
231 |
qs = all_qs |
|
232 |
found_notices = qs.count() |
|
233 |
id = qs[random.randint(0, found_notices - 1)].id |
|
|
140
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
234 |
notice_history.append(id) |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
235 |
request.session['notice_history'] = notice_history |
|
752062bdeb10
Corrected image load bug and added describe prev/next
veltr
parents:
136
diff
changeset
|
236 |
return redirect('front_describe', pk=id) |
| 110 | 237 |
|
238 |
class FrontTermListView(TemplateView): |
|
239 |
||
240 |
template_name = "jocondelab/front_termlist.html" |
|
241 |
||
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
242 |
def image_extra(self, qs): |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
243 |
return qs.extra(select={ |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
244 |
'image_url': 'SELECT relative_url FROM core_noticeimage AS JL01 JOIN core_notice AS JL02 ON JL02.id = JL01.notice_id JOIN core_noticeterm AS JL03 ON JL02.id = JL03.notice_id WHERE JL03.term_id = core_term.id LIMIT 1' |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
245 |
}) |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
246 |
|
| 110 | 247 |
def get(self, request): |
248 |
||
249 |
context = {} |
|
250 |
lang = self.request.GET.get('lang',self.request.LANGUAGE_CODE)[:2] |
|
251 |
is_ajax = request.is_ajax() |
|
252 |
letter = self.request.GET.get('letter',None) |
|
253 |
alpha_sort = (letter is not None) or self.request.GET.get('alphabet',False) |
|
254 |
context['alpha_sort'] = alpha_sort |
|
255 |
thesaurus = self.request.GET.get('thesaurus',None) |
|
256 |
context['thesaurus'] = thesaurus |
|
257 |
||
| 136 | 258 |
if thesaurus is None: |
| 110 | 259 |
wqs = TagcloudTerm.objects.filter(term__dbpedia_fields__language_code=lang).values('term__dbpedia_fields__label','term__dbpedia_uri') |
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
260 |
wqs = wqs.distinct().annotate(sum_notice=Sum('term__nb_illustrated_notice')).order_by('-sum_notice') |
| 110 | 261 |
n = wqs.count() |
262 |
context['words'] = [{ |
|
263 |
'label': w['term__dbpedia_fields__label'], |
|
264 |
'uri': w['term__dbpedia_uri'], |
|
265 |
'font_size': "%.2f"%(1. + float(n-i)/n) |
|
266 |
} for i, w in enumerate(wqs)] |
|
| 118 | 267 |
random.shuffle(context['words']) |
| 136 | 268 |
else: |
| 110 | 269 |
alphabets = [{ |
270 |
"languages": [ "fr", "en", "de", "it", "es", "pt", "ca", "br", "eu", "oc" ], |
|
271 |
"letters": u"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
272 |
}, { |
|
273 |
"languages": [ "ru" ], |
|
274 |
"letters": u"АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ" |
|
275 |
}, { |
|
276 |
"languages": [ "ar" ], |
|
277 |
"letters": u"ابتثجحخدذرزسشصضطظعغفقكلمنهوي" |
|
278 |
}] |
|
279 |
latinalph = alphabets[0] |
|
280 |
alphabet = None |
|
281 |
for a in alphabets: |
|
282 |
if lang in a["languages"]: |
|
283 |
alphabet = a |
|
284 |
if alphabet is not None: |
|
285 |
if thesaurus in ['REPR','AUTR']: |
|
286 |
context["show_alphabet"] = True |
|
287 |
letters = alphabet["letters"] |
|
288 |
context["alphabet"] = letters |
|
289 |
if letter is not None: |
|
290 |
letterpos = letters.find(letter) |
|
291 |
context["current_letter"] = letter |
|
292 |
if (not alpha_sort) or (thesaurus == 'AUTR' and alphabet == latinalph and letter is not None): |
|
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
293 |
# When ordering is not by translated label, we query the Term table |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
294 |
tqs = Term.objects.filter(dbpedia_fields__language_code=lang, nb_illustrated_notice__gt=0) |
| 110 | 295 |
if thesaurus == 'REPR': |
296 |
tqs = tqs.filter(thesaurus__label__in=['REPR','SREP']) |
|
297 |
else: |
|
298 |
tqs = tqs.filter(thesaurus__label=thesaurus) |
|
299 |
if alpha_sort: |
|
300 |
# Particular case in which thesaurus == AUTR and the alphabet is latin, |
|
301 |
# we use original sorting by family name |
|
302 |
if letterpos >= 0: |
|
303 |
tqs = tqs.filter(label__gte=letters[letterpos]) |
|
304 |
if letterpos < len(letters)-1: |
|
305 |
tqs = tqs.filter(label__lt=letters[letterpos+1]) |
|
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
306 |
tqs = tqs.distinct('label').order_by('label') |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
307 |
tqs = self.image_extra(tqs).values('image_url','dbpedia_uri','dbpedia_fields__abstract','label') |
| 110 | 308 |
terms = [] |
309 |
known_uris = [] |
|
310 |
for t in tqs: |
|
311 |
uri = t['dbpedia_uri'] |
|
312 |
if uri not in known_uris: |
|
313 |
terms.append(t) |
|
314 |
known_uris.append(uri) |
|
315 |
else: |
|
316 |
# When we're in sort by most frequent terms |
|
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
317 |
tqs = self.image_extra(tqs.order_by('-nb_illustrated_notice'))[:60] |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
318 |
terms = tqs.values('image_url','dbpedia_fields__thumbnail','dbpedia_uri','dbpedia_fields__abstract','dbpedia_fields__label') |
| 110 | 319 |
terms = [{ |
320 |
"dbpedia_uri": t['dbpedia_uri'], |
|
| 113 | 321 |
"label": t.get('dbpedia_fields__label',t.get('label','')), |
| 110 | 322 |
"abstract": t['dbpedia_fields__abstract'], |
| 148 | 323 |
"image_url": "%s%s"%(settings.JOCONDE_IMG_BASE_URL, t.get('image_url','')) |
| 110 | 324 |
} for t in terms] |
325 |
context['termcount'] = len(terms) |
|
326 |
else: |
|
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
327 |
# When ordering is by translated label, we query the DbpediaFields table |
|
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
328 |
tqs = DbpediaFields.objects.filter(language_code=lang, term__nb_illustrated_notice__gt=0).exclude(label=None) |
| 110 | 329 |
if thesaurus == 'REPR': |
330 |
tqs = tqs.filter(term__thesaurus__label__in=['REPR','SREP']) |
|
331 |
else: |
|
332 |
tqs = tqs.filter(term__thesaurus__label=thesaurus) |
|
333 |
if thesaurus in ['REPR','AUTR'] and letter is not None: #Pagination required for these two thesaura |
|
334 |
if alphabet is not None: |
|
335 |
if letterpos >= 0: |
|
336 |
tqs = tqs.filter(label__gte=letters[letterpos]) |
|
337 |
if letterpos < len(letters)-1: |
|
338 |
tqs = tqs.filter(label__lt=letters[letterpos+1]) |
|
339 |
tqs = tqs.distinct('label').order_by('label') |
|
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
340 |
terms = self.image_extra(tqs).values('image_url','dbpedia_uri','abstract','label') |
| 110 | 341 |
for t in terms: |
|
146
b5ce341745e3
Added nb_illustrated_notice and changed queries for keywords
veltr
parents:
144
diff
changeset
|
342 |
t['image_url'] = "%s%s"%(settings.JOCONDE_IMG_BASE_URL, t['image_url']) |
| 110 | 343 |
context['termcount'] = terms.count() |
344 |
context['terms'] = terms |
|
345 |
||
346 |
return self.render_to_response(context) |
|
| 96 | 347 |