--- a/web/hdalab/views/ajax.py Tue Mar 13 15:11:46 2012 +0100
+++ b/web/hdalab/views/ajax.py Tue Mar 13 15:38:57 2012 +0100
@@ -25,7 +25,7 @@
resobj["content_count"] = Datasheet.objects.filter(taggedsheet__tag__label__iexact = label).distinct().count()
- res = Tag.objects.select_related('dbpedia_fields').filter(label__iexact = label).order_by('-dbpedia_uri')[0:1]
+ res = Tag.objects.select_related('dbpedia_fields').filter(~Q(dbpedia_uri = None), label__iexact = label).order_by('-dbpedia_uri')[0:1]
if len(res) == 1:
restag = res.get()
resobj["dbpedia_uri"] = restag.dbpedia_uri
@@ -69,7 +69,7 @@
masters = []
for lbl in labelslist:
- labelqs = Tag.objects.select_related('dbpedia_fields').get(label__iexact = lbl)[0:1]
+ labelqs = Tag.objects.select_related('dbpedia_fields').filter(~Q(dbpedia_uri = None), label__iexact = lbl)[0:1]
if len(labelqs) > 0:
tag = labelqs.get()
if tag.dbpedia_fields:
@@ -129,7 +129,7 @@
q = request.GET.get('term',None)
if q:
lq = q.lower()
- qs = Tag.objects.filter( Q(label__icontains = q ) | Q(dbpedia_fields__translations__label__icontains = q, dbpedia_fields__translations__language_code=request.LANGUAGE_CODE)) if q else Tag.objects.all()
+ qs = Tag.objects.filter( Q(label__icontains = q ) | Q(dbpedia_fields__translations__label__icontains = q, dbpedia_fields__translations__language_code=request.LANGUAGE_CODE), ~Q(dbpedia_uri = None)) if q else Tag.objects.filter(~Q(dbpedia_uri = None))
qs = qs.annotate(nb=Count('datasheet')).order_by('-nb')[:20]
qslist = list(qs)
@@ -173,9 +173,9 @@
matchtagids = []
- tagqs = Tag.objects.exclude(category__label__in = ['Datation', 'Localisation', 'Discipline artistique'])
+ tagqs = Tag.objects.exclude(category__label__in = ['Datation', 'Localisation', 'Discipline artistique']).filter(~Q(dbpedia_uri = None))
countryqs = Country.objects
- discqs = Tag.objects.filter(category__label = u'Discipline artistique').select_related('dbpedia_fields')
+ discqs = Tag.objects.filter(~Q(dbpedia_uri = None), category__label = u'Discipline artistique').select_related('dbpedia_fields')
yearqs = TagYears.objects
contentqs = Datasheet.objects.filter(validated=True)
@@ -190,10 +190,12 @@
delta = max(1, (end_year-start_year)/2)
minstart = start_year - delta
maxend = end_year + delta
- matchtagqs = Tag.objects.filter(years__end_year__gte = start_year,
- years__start_year__lte = end_year,
- years__end_year__lte = maxend,
- years__start_year__gte = minstart)
+ matchtagqs = Tag.objects.filter(~Q(dbpedia_uri = None),
+ years__end_year__gte = start_year,
+ years__start_year__lte = end_year,
+ years__end_year__lte = maxend,
+ years__start_year__gte = minstart,
+ )
matchtagids += [t.id for t in matchtagqs]
contentqs = contentqs.filter(taggedsheet__tag__in = matchtagqs,
taggedsheet__order__lte = max_tag_order)
@@ -201,7 +203,7 @@
if label:
masters = []
for txtlbl in label.split(","):
- matchtagqs = Tag.objects.select_related('dbpedia_fields').filter(label__iexact = txtlbl.strip())
+ matchtagqs = Tag.objects.select_related('dbpedia_fields').filter(~Q(dbpedia_uri = None), label__iexact = txtlbl.strip())
for t in matchtagqs:
if t.id not in matchtagids:
matchtagids.append(t.id)
@@ -215,7 +217,7 @@
if country:
for country_uri in country.split(","):
- matchtagqs = Tag.objects.filter(locatedin__country__dbpedia_uri = country_uri)
+ matchtagqs = Tag.objects.filter(~Q(dbpedia_uri = None),locatedin__country__dbpedia_uri = country_uri)
matchtagids += [t.id for t in matchtagqs if t.id not in matchtagids]
contentqs = contentqs.filter(taggedsheet__tag__in = matchtagqs,
taggedsheet__order__lte = max_tag_order)