# HG changeset patch # User cavaliet # Date 1404813786 -7200 # Node ID eb479baeb2bf28501b95ed9b9f2e0a612b8b1e6b # Parent 0bb9c29cd41db92c1b454965a393c132a9a398c4 renkan first step with tag and datasheet nodes diff -r 0bb9c29cd41d -r eb479baeb2bf src/hdalab/static/hdalab/js/gomina.js --- a/src/hdalab/static/hdalab/js/gomina.js Thu Jul 03 12:47:04 2014 +0200 +++ b/src/hdalab/static/hdalab/js/gomina.js Tue Jul 08 12:03:06 2014 +0200 @@ -231,14 +231,14 @@ }); // modif renkan var url_renkan = $("#renkan-link").attr("href"); - console.log("url_renkan", url_renkan); url_renkan = ((url_renkan.lastIndexOf("?")>=0) ? (url_renkan.substr(0, url_renkan.lastIndexOf("?"))) : url_renkan) + "?"; - console.log("url_renkan", url_renkan); if (_cl) { - url_renkan += "countries="; + url_renkan += "country="; _htmFilters += _(_curView.country).map(function(_t, _i) { + // dbpedia uri for renkan url + url_renkan += "," + ( (typeof gomNs.countries == "object" && typeof gomNs.countries[_t] == "object") ? _t : decodeURIComponent(_t.match('[^/]+$')[0]).replace('_',' ')); + // label for interface var country_label = ( (typeof gomNs.countries == "object" && typeof gomNs.countries[_t] == "object") ? gomNs.countries[_t].properties.labels[gomNs.languageCode] : decodeURIComponent(_t.match('[^/]+$')[0]).replace('_',' ')); - url_renkan += "," + country_label; return '
  • '+gettext('Pays :')+' ' + country_label + ''+gettext('Tag :')+' ' diff -r 0bb9c29cd41d -r eb479baeb2bf src/hdalab/templates/renkan_edit.html --- a/src/hdalab/templates/renkan_edit.html Thu Jul 03 12:47:04 2014 +0200 +++ b/src/hdalab/templates/renkan_edit.html Tue Jul 08 12:03:06 2014 +0200 @@ -83,7 +83,7 @@ language: "fr" }); Rkns.jsonIO(_renkan, { - url: "{% url 'renkan_get_put' %}" + url: "{% url 'renkan_get_put' %}" + window.location.search }); }; diff -r 0bb9c29cd41d -r eb479baeb2bf src/hdalab/views/ajax.py --- a/src/hdalab/views/ajax.py Thu Jul 03 12:47:04 2014 +0200 +++ b/src/hdalab/views/ajax.py Tue Jul 08 12:03:06 2014 +0200 @@ -261,6 +261,14 @@ max_tag_order = int(request.GET.get('mto', '12')) content_count = request.GET.get('contentcount', 12) tag_count = request.GET.get('tagcount', 30) + + outputstr = filter_generic(lang, periode, label, country, contentlist, max_tag_order, content_count, tag_count) + + return HttpResponse(content=outputstr, mimetype='application/json') + + +def filter_generic(lang="fr-fr", periode=None, label=None, country=None, contentlist=None, max_tag_order=12, content_count=12, tag_count=30): + no_translate_langs = [ 'fr' ] key_parts = ("filter",lang,periode,label,country,contentlist,max_tag_order,content_count,tag_count) @@ -428,8 +436,10 @@ output = {'count': cont_count, 'contents': contenus, 'tags':tags, 'sparkline':yearchange, 'countries':countries, 'disciplines':disciplines, 'tagtranslations': tag_translations} outputstr = json.dumps(output) cache.set(cache_key, outputstr) - - return HttpResponse(content=outputstr, mimetype='application/json') + + return outputstr + + def subtree(tree): MAX_TAG_ORDER = 16 diff -r 0bb9c29cd41d -r eb479baeb2bf src/hdalab/views/renkan.py --- a/src/hdalab/views/renkan.py Thu Jul 03 12:47:04 2014 +0200 +++ b/src/hdalab/views/renkan.py Tue Jul 08 12:03:06 2014 +0200 @@ -4,12 +4,15 @@ @author: tc ''' +from datetime import datetime from django.conf import settings +from django.db.models import Q from django.http.response import HttpResponse from django.views.generic import View from django.views.decorators.csrf import csrf_exempt +from hdabo.models import Tag, Datasheet, TaggedSheet +from hdalab.views.ajax import filter_generic import json -import itertools import uuid import logging @@ -23,12 +26,74 @@ return super(RenkanGetPut, self).dispatch(*args, **kwargs) def get(self, request): - file_path = settings.JSON_TEST_PATH - content = open(file_path,"r") + #file_path = settings.JSON_TEST_PATH + #content = open(file_path,"r") + + now = datetime.now().strftime("%Y-%m-%d %H:%M") + + content = { + "id": unicode(uuid.uuid1()), + "title": "Renkan généré " + now, + "description": "(empty description)", + "created": now, + "updated": now, + "nodes": [], + "edges": [], + "views": [], + "users": [], + } + + # 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) ) + + project_id = unicode(uuid.uuid1()) - return HttpResponse(content, content_type="application/json") + for i,t in enumerate(all_tags): + content["nodes"].append({ + "id": unicode(uuid.uuid1()), + "title": t.label, + "description": t.dbpedia_uri, + "uri": t.dbpedia_uri, + "position": { + "x": 0, + "y": 100*i + }, + "image": None, + "size": 0, + "project_id": project_id, + #"created_by": "roster_user-84fe909f-ba37-48e6-a25f-9d2f129a95b7" + }) + + # Get datasheets from ajax filter search + filter_output = filter_generic(request.GET.get('lang',request.LANGUAGE_CODE), None, ",".join(label_list), ",".join(country_list)) + filter_output = json.loads(filter_output) + for i,c in enumerate(filter_output["contents"]): + content["nodes"].append({ + "id": unicode(uuid.uuid1()), + "title": c["title"], + "description": c["description"], + "uri": c["url"], + "position": { + "x": 200, + "y": 100*i - 50 + }, + "image": None, + "size": 0, + "project_id": project_id, + #"created_by": "roster_user-84fe909f-ba37-48e6-a25f-9d2f129a95b7" + }) + + + + return HttpResponse(json.dumps(content), content_type="application/json") def put(self, request): - return HttpResponse("OK") + return HttpResponse("OK") +