diff -r 1c2c8e16bdbe -r a3b1046639f3 src/hdalab/views/profile.py --- a/src/hdalab/views/profile.py Thu Aug 21 13:01:38 2014 +0200 +++ b/src/hdalab/views/profile.py Thu Aug 21 15:05:41 2014 +0200 @@ -164,7 +164,30 @@ related_tags.append({"label": t["label"], "thumbnail":thumbnail_url, "id":t["id"]}) all_labels.append(t["label"]) related_tags_dict[c["id"]].append(t["id"]) - #return HttpResponse(json.dumps({"t":related_tags_label}, indent=2), content_type="application/json") + + + cat_dict = {u"Créateur": static("hdalab/img/category_creator.png"), + u"Datation": static("hdalab/img/category_datation"), + u"Discipline artistique": static("hdalab/img/category_discipline"), + u"Localisation": static("hdalab/img/category_localisation"), + u"Ecole/Mouvement": static("hdalab/img/category_movement")} + + + # If possible, we search a dbpedia_fields thumbnail or category thumbnail for related tags + r_tags = [t["label"] for t in related_tags if t["thumbnail"] is None or t["thumbnail"]=="" ] + r_tags = Tag.objects.filter( label__in=r_tags ).select_related("dbpedia_fields", "category") + r_tags_dict = {} + for t in r_tags: + img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None + if img_url is None and t.category is not None: + img_url = cat_dict[t.category.label] + if img_url: + r_tags_dict[t.label] = img_url + # Populate related_tags with found image urls + for t in related_tags: + if (t["thumbnail"] is None or t["thumbnail"]=="") and (t["label"] in r_tags_dict): + t["thumbnail"] = r_tags_dict[t["label"]] + # Prepare Node placer : np = LineNodePlacer() @@ -172,17 +195,10 @@ project_id = unicode(uuid.uuid1()) - cat_dict = {u"Créateur":"category_creator", - u"Datation":"category_datation", - u"Discipline artistique":"category_discipline", - u"Localisation": "category_localisation", - u"Ecole/Mouvement":"category_movement"} - for t in all_tags: - logger.debug(t.category) img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None if img_url is None and t.category is not None: - img_url = static("hdalab/img/" + cat_dict[t.category.label] + ".png") + img_url = cat_dict[t.category.label] content["nodes"].append({ "id": unicode(uuid.uuid1()),