--- a/src/hdalab/views/profile.py Thu Aug 21 15:05:41 2014 +0200
+++ b/src/hdalab/views/profile.py Fri Aug 22 15:02:39 2014 +0200
@@ -24,7 +24,7 @@
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic import TemplateView, View
-from hdabo.models import Tag
+from hdabo.models import Tag, Datasheet, TaggedSheet
from hdalab.models.renkan import HdalabRenkan
from hdalab.views.ajax import filter_generic
from renkanmanager.models import Renkan
@@ -115,15 +115,7 @@
rk = get_object_or_404(Renkan, rk_id=rk_id)
return HttpResponse(rk.content, content_type="application/json")
- # Otherwise we build the datas
- # Get tags and countries
- labels = request.GET.get("label", "").split(",")
- countries = request.GET.get("country", "").split(",")
- # Tags arrive with french label, countries with dbpedia uri
- label_list = [t for t in labels if t!=""]
- country_list = [c for c in countries if c!=""]
- all_tags = Tag.objects.filter( Q(label__in=label_list) | Q(dbpedia_uri__in=country_list) ).select_related("dbpedia_fields", "category")
-
+ # Start dict for renkan json
now = datetime.now().strftime("%Y-%m-%d %H:%M")
content = {
@@ -138,6 +130,72 @@
"users": [],
}
+ # category image dict
+ cat_dict = {u"Créateur": static("hdalab/img/category_creator.png"),
+ u"Datation": static("hdalab/img/category_datation.png"),
+ u"Discipline artistique": static("hdalab/img/category_discipline.png"),
+ u"Localisation": static("hdalab/img/category_localisation.png"),
+ u"Ecole/Mouvement": static("hdalab/img/category_movement.png")}
+
+
+ # Renkan Project ID
+ project_id = unicode(uuid.uuid1())
+
+
+ # If a notice id is set
+ notice_id = request.GET.get("notice", "")
+ if notice_id!="":
+ notice = get_object_or_404(Datasheet, hda_id=notice_id)
+ # We get the ORDERED tags if we display one sheet (case valid = 0 and 1)
+ ordered_tags = TaggedSheet.objects.filter(datasheet=notice).select_related("tag", "tag__dbpedia_fields", "tag__category").order_by('order')[:15]
+ # Prepare Node placer :
+ np = LineNodePlacer()
+ np.init({"datasheet": (1, 1), "tags": (2, len(ordered_tags))})
+ # Place notice :
+ content["nodes"].append({
+ "id": unicode(uuid.uuid1()),
+ "title": notice.title,
+ "description": notice.description,
+ "uri": notice.url,
+ "position": np.get_place("datasheet"),
+ "image": static("hdalab/img/page_icon.png"),
+ "size": 0,
+ "project_id": project_id,
+ "color": None,
+ #"created_by": "roster_user-84fe909f-ba37-48e6-a25f-9d2f129a95b7"
+ })
+
+ for ot in ordered_tags:
+ t = ot.tag
+ 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]
+
+ content["nodes"].append({
+ "id": unicode(uuid.uuid1()),
+ "title": t.label + ((" (" + t.category.label + ")") if t.category else ""),
+ "description": t.dbpedia_uri,
+ "uri": t.dbpedia_uri,
+ "position": np.get_place("tags"),
+ "image": img_url,
+ "size": 0,
+ "project_id": project_id,
+ "color": None,
+ #"created_by": "roster_user-84fe909f-ba37-48e6-a25f-9d2f129a95b7"
+ })
+
+ response = json.dumps(content)
+ return HttpResponse(response, content_type="application/json")
+
+ # Otherwise we build the datas
+ # Get tags and countries
+ labels = request.GET.get("label", "").split(",")
+ countries = request.GET.get("country", "").split(",")
+ # Tags arrive with french label, countries with dbpedia uri
+ label_list = [t for t in labels if t!=""]
+ country_list = [c for c in countries if c!=""]
+ all_tags = Tag.objects.filter( Q(label__in=label_list) | Q(dbpedia_uri__in=country_list) ).select_related("dbpedia_fields", "category")
+
# Get datasheets from ajax filter search
filter_output = filter_generic(request.GET.get('lang',request.LANGUAGE_CODE), None, ",".join(label_list), ",".join(country_list))
@@ -166,13 +224,6 @@
related_tags_dict[c["id"]].append(t["id"])
- 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")
@@ -193,8 +244,6 @@
np = LineNodePlacer()
np.init({"tags": (1, len(all_tags)), "datasheet": (2, len(filter_output["contents"])), "related": (3, len(related_tags))})
- project_id = unicode(uuid.uuid1())
-
for t in all_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: