# HG changeset patch # User ymh # Date 1331634806 -3600 # Node ID e2ceeb903de6201c52508852a227125cc0d54402 # Parent 3e5d26b4844b7fa0344cf095285586c0ae9654cc improve requests diff -r 3e5d26b4844b -r e2ceeb903de6 .settings/org.eclipse.core.resources.prefs --- a/.settings/org.eclipse.core.resources.prefs Tue Mar 13 11:12:38 2012 +0100 +++ b/.settings/org.eclipse.core.resources.prefs Tue Mar 13 11:33:26 2012 +0100 @@ -1,5 +1,6 @@ -#Thu Mar 08 00:58:04 CET 2012 +#Mon Mar 12 08:25:39 CET 2012 eclipse.preferences.version=1 +encoding//data/villes.csv=ISO-8859-1 encoding//virtualenv/web/env/hdabo/lib/python2.6/site-packages/haystack/backends/__init__.py=utf-8 encoding//virtualenv/web/env/hdabo/lib/python2.6/site-packages/sortedm2m/fields.py=utf-8 encoding//virtualenv/web/env/hdabo/lib/python2.6/site-packages/sortedm2m/forms.py=utf-8 diff -r 3e5d26b4844b -r e2ceeb903de6 data/villes.csv --- a/data/villes.csv Tue Mar 13 11:12:38 2012 +0100 +++ b/data/villes.csv Tue Mar 13 11:33:26 2012 +0100 @@ -35247,131 +35247,4 @@ Lorp-Sentaraille;LORP SENTARAILLE;9190;9289;0;43,008888;1,119444 Soueix-Rogalle;SOUEIX ROGALLE;9140;9299;0;42,893333;1,211388 Soulan;SOULAN;9320;9301;0;42,913333;1,233055 -Villeneuve;VILLENEUVE;9800;9335;0;42,938333;0,981666 -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;;;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; -;;; +Villeneuve;VILLENEUVE;9800;9335;0;42,938333;0,981666 \ No newline at end of file diff -r 3e5d26b4844b -r e2ceeb903de6 web/hdalab/__init__.py --- a/web/hdalab/__init__.py Tue Mar 13 11:12:38 2012 +0100 +++ b/web/hdalab/__init__.py Tue Mar 13 11:33:26 2012 +0100 @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -VERSION = (0, 2, 0, "final", 0) +VERSION = (1, 1, 0, "final", 0) def get_version(): diff -r 3e5d26b4844b -r e2ceeb903de6 web/hdalab/management/commands/import_hdabo_db.py --- a/web/hdalab/management/commands/import_hdabo_db.py Tue Mar 13 11:12:38 2012 +0100 +++ b/web/hdalab/management/commands/import_hdabo_db.py Tue Mar 13 11:33:26 2012 +0100 @@ -35,8 +35,9 @@ call_command('query_dbpedia') call_command('fill_tag_years') + call_command('query_geo_inclusion') call_command('import_insee_csv', os.path.join(data_path,'villes.csv')) call_command('import_insee_csv', os.path.join(data_path,'additional_cities.csv')) - call_command('import_hda_insee_csv', os.path.join(data_path,'HDA_insee.csv')) + call_command('import_hda_insee_csv', os.path.join(data_path,'HDA_Insee.csv')) \ No newline at end of file diff -r 3e5d26b4844b -r e2ceeb903de6 web/hdalab/views/ajax.py --- a/web/hdalab/views/ajax.py Tue Mar 13 11:12:38 2012 +0100 +++ b/web/hdalab/views/ajax.py Tue Mar 13 11:33:26 2012 +0100 @@ -10,7 +10,7 @@ from hdabo.models import Tag, Datasheet, TaggedSheet from hdalab.models import (TagLinks, HdaSession, Country, TagYears, DatasheetExtras) -from hdalab.models.dataviz import DbpediaFieldsTranslation +from hdalab.models.dataviz import DbpediaFieldsTranslation, DbpediaFields import django.utils.simplejson as json import hmac import itertools @@ -129,13 +129,19 @@ 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 = qs.annotate(nb=Count('datasheet')).order_by('-nb')[:20] + + qslist = list(qs) + + transqs = DbpediaFieldsTranslation.objects.filter(master__tag__in = qslist, language_code=request.LANGUAGE_CODE).select_related("master") + + translations = dict([(tr.master.tag_id, tr.label) for tr in transqs]) + res = [] - for t in qs: + for t in qslist: resobj = {'value':t.label,'nb':t.nb} - transqs = DbpediaFieldsTranslation.objects.filter(master__tag = t, language_code=request.LANGUAGE_CODE)[0:1] - if transqs: - resobj['label'] = transqs.get().label + if t.id in translations: + resobj['label'] = translations[t.id] else: resobj['label'] = t.label if q is None or resobj['label'].lower().find(lq) != -1: @@ -155,7 +161,7 @@ matchtagids = [] - tagqs = Tag.objects.exclude(category__label__in = ['Datation', 'Localisation', 'Discipline artistique']).select_related('dbpedia_fields') + tagqs = Tag.objects.exclude(category__label__in = ['Datation', 'Localisation', 'Discipline artistique']) countryqs = Country.objects discqs = Tag.objects.filter(category__label = u'Discipline artistique').select_related('dbpedia_fields') yearqs = TagYears.objects @@ -240,6 +246,7 @@ #tagqs = tagqs.annotate(nb=Count('datasheet')).order_by('-nb')[:tag_count] tagqs = tagqs.annotate(nb=Count('datasheet')).order_by('-nb').only('id','label')[:tag_count] + #.select_related('dbpedia_fields') # hack to add only necessary fields in the group by # contournement bug https://code.djangoproject.com/ticket/17144 tagqs.query.clear_select_fields() @@ -247,11 +254,13 @@ tagqs.query.set_group_by() tagqslist = list(tagqs) + + dbpediafields = dict([(df.tag_id, df) for df in DbpediaFields.objects.filter(tag__in = tagqslist)]) - transqs = DbpediaFieldsTranslation.objects.filter(master__in = [tag.dbpedia_fields for tag in tagqslist], language_code = request.LANGUAGE_CODE) + transqs = DbpediaFieldsTranslation.objects.filter(master__in = dbpediafields.values(), language_code = request.LANGUAGE_CODE) translations = dict([(trans.master_id,trans.label) for trans in transqs]) - tags = [{'id': tag.id, 'label': tag.label, 'score': tag.nb, 'translated_label': translations.get(tag.dbpedia_fields.id, tag.label) if tag.dbpedia_fields is not None else tag.label} for tag in tagqslist] + tags = [{'id': tag.id, 'label': tag.label, 'score': tag.nb, 'translated_label': translations.get(dbpediafields[tag.id].id, tag.label) if tag.id in dbpediafields else tag.label} for tag in tagqslist] countryqs = countryqs.annotate(nb=Count('includes__tag__taggedsheet')) countries = dict([(country.dbpedia_uri, country.nb) for country in countryqs])