# HG changeset patch # User cavaliet # Date 1378824869 -7200 # Node ID 305f9fcd409bf17d6dd5b0d3352c53b8edb4e496 # Parent da37c87abbfb410c31590789d19aa085029fe4d8 keep on record form. several sparql requests diff -r da37c87abbfb -r 305f9fcd409b src/p4l/settings.py --- a/src/p4l/settings.py Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/settings.py Tue Sep 10 16:54:29 2013 +0200 @@ -295,7 +295,165 @@ ?root skos:narrower|skos:member ?uri. } """ - } +} +SPARQL_COUNTRY_QUERIES = { +'filter' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept. + ?uri skos:inScheme . + ?uri skos:prefLabel ?label. + FILTER (lang(?label) = %s). + ?uri skos:prefLabel ?lab. + FILTER regex (str(?lab), ?reg, 'i'). + FILTER (lang (?lab) = %s). + BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place). + BIND (STRLEN(STR(?lab)) AS ?len) +} +ORDER BY ?place ?len ?lab +""", +'root' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept ; + skos:inScheme ; + skos:prefLabel ?label . + FILTER (lang(?label) = %s). + FILTER NOT EXISTS { [skos:narrower ?uri] } +} +""", +'childs' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri skos:inScheme . + { ?uri a ?type + FILTER (?type = skos:Collection || ?type = skos:Concept) }. + ?root skos:narrower|skos:member ?uri. + ?uri skos:prefLabel|rdfs:label ?label. + FILTER (lang(?label) = %s). +} +""", +'child-count' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT (COUNT(?uri) as ?nb) +WHERE { + ?uri skos:inScheme . + ?root skos:narrower|skos:member ?uri. +} +""" +} +SPARQL_LANGUAGE_QUERIES = { +'filter' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept. + ?uri skos:inScheme . + ?uri skos:prefLabel ?label. + FILTER (lang(?label) = %s). + ?uri skos:prefLabel ?lab. + FILTER regex (str(?lab), ?reg, 'i'). + FILTER (lang (?lab) = %s). + BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place). + BIND (STRLEN(STR(?lab)) AS ?len) +} +ORDER BY ?place ?len ?lab +""", +'root' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept ; + skos:inScheme ; + skos:prefLabel ?label . + FILTER (lang(?label) = %s). + FILTER NOT EXISTS { [skos:narrower ?uri] } +} +""" +} +SPARQL_PROJECT_QUERIES = { +'filter' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept. + ?uri skos:inScheme . + ?uri skos:prefLabel ?label. + ?uri skos:prefLabel ?lab. + FILTER regex (str(?lab), ?reg, 'i'). + BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place). + BIND (STRLEN(STR(?lab)) AS ?len) +} +ORDER BY ?place ?len ?lab +""", +'root' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept ; + skos:inScheme ; + skos:prefLabel ?label . +} +""" +} +SPARQL_ORGANIZATION_QUERIES = { +'filter' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept. + ?uri skos:inScheme . + ?uri skos:prefLabel ?label. + ?uri skos:prefLabel ?lab. + FILTER regex (str(?lab), ?reg, 'i'). + BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place). + BIND (STRLEN(STR(?lab)) AS ?len) +} +ORDER BY ?place ?len ?lab +""", +'root' : """ +PREFIX skos: +PREFIX rdf: +PREFIX owl: +PREFIX rdfs: +SELECT DISTINCT ?uri ?label +WHERE { + ?uri a skos:Concept ; + skos:inScheme ; + skos:prefLabel ?label . +} +""" +} REST_FRAMEWORK = { diff -r da37c87abbfb -r 305f9fcd409b src/p4l/static/p4l/js/p4l.js --- a/src/p4l/static/p4l/js/p4l.js Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/static/p4l/js/p4l.js Tue Sep 10 16:54:29 2013 +0200 @@ -123,6 +123,7 @@ scope: { listname:"@", list:"=", + placeholder:"@", }, templateUrl: function(tElement, tAttrs) { return context.urls.base_static+'p4l/templates/addSemanticUriForm.html'; diff -r da37c87abbfb -r 305f9fcd409b src/p4l/static/p4l/js/semantictree.js --- a/src/p4l/static/p4l/js/semantictree.js Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/static/p4l/js/semantictree.js Tue Sep 10 16:54:29 2013 +0200 @@ -104,20 +104,22 @@ var uri = b[i]["uri"]["value"]; // We test if the uri has childs. var nb = 0; - $.ajax({ - url:url, - data:{ - query: child_count_query, - $root: "<"+uri+">" - }, - headers: { - Accept: "application/sparql-results+json;charset=UTF-8" - }, - async: false, - success:function(json_count){ - nb = parseInt(json_count["results"]["bindings"][0]["nb"]["value"]); - } - }); + if(child_count_query && child_count_query!=""){ + $.ajax({ + url:url, + data:{ + query: child_count_query, + $root: "<"+uri+">" + }, + headers: { + Accept: "application/sparql-results+json;charset=UTF-8" + }, + async: false, + success:function(json_count){ + nb = parseInt(json_count["results"]["bindings"][0]["nb"]["value"]); + } + }); + } // nb of child > 0 : state closed if yes, no state if not. if(nb>0){ mytree.push({ diff -r da37c87abbfb -r 305f9fcd409b src/p4l/static/p4l/templates/addSemanticUriForm.html --- a/src/p4l/static/p4l/templates/addSemanticUriForm.html Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/static/p4l/templates/addSemanticUriForm.html Tue Sep 10 16:54:29 2013 +0200 @@ -4,7 +4,7 @@
- {{ 'or' | translate}} diff -r da37c87abbfb -r 305f9fcd409b src/p4l/templates/p4l/record_update_form.html --- a/src/p4l/templates/p4l/record_update_form.html Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/templates/p4l/record_update_form.html Tue Sep 10 16:54:29 2013 +0200 @@ -52,23 +52,23 @@ {{record.uri}} - {{'identifier' | translate}} + {{ 'identifier' | translate}} {{record.identifier}} - {{'subjects' | translate}} - - - + {{ 'subjects' | translate}} + - {{'themes' | translate}} - - - + {{ 'themes' | translate}} + - {{'notes' | translate}} + {{ 'countries' | translate}} + + + + {{ 'notes' | translate}} @@ -80,13 +80,113 @@ - {{'document code' | translate }} + {{ 'document code' | translate }} - {{'imprints' | translate}} + {{ 'language' | translate }} + #todo WITH SPARQL + + + + {{ 'other languages' | translate }} + + + + {{ 'titles' | translate }} + #todo + + + + {{ 'abstracts' | translate }} + #todo + + + + {{ 'added titles' | translate }} + #todo + + + + {{ 'titles main document' | translate }} + #todo + + + + {{ 'edition statement' | translate }} + + + + {{ 'imprints' | translate }} - + + + {{ 'collations' | translate }} + #todo + + + + {{ 'volume issues' | translate }} + #todo + + + + {{ 'project names' | translate }} + + + + {{ 'periodicals' | translate }} + #todo + + + + {{ 'meetings' | translate }} + #todo + + + + {{ 'series' | translate }} + #todo + + + + {{ 'authors' | translate }} + #todo + + + + {{ 'subject persons' | translate }} + #todo + + + + {{ 'subject corporate bodies' | translate }} + + + + {{ 'subject meetings' | translate }} + #todo + + + {{ 'corporate authors' | translate }} + + + + {{ 'Urls' | translate }} + #todo + + + {{ 'record type' | translate }} + #todo WITH SPARQL + + + {{ 'is document part' | translate }} + #todo checkbox + + + {{ 'is multilingual' | translate }} + #todo checkbox + diff -r da37c87abbfb -r 305f9fcd409b src/p4l/templates/p4l/translations.html --- a/src/p4l/templates/p4l/translations.html Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/templates/p4l/translations.html Tue Sep 10 16:54:29 2013 +0200 @@ -1,5 +1,10 @@ {% load i18n %} {% trans 'Add' %} +{% trans 'Save' %} {% trans 'Add a new subject' %} -{% trans 'Save' %} \ No newline at end of file +{% trans 'Add a new theme' %} +{% trans 'Add a new country' %} +{% trans 'Add a new language' %} +{% trans 'Add a new project' %} +{% trans 'Add a new organisation' %} \ No newline at end of file diff -r da37c87abbfb -r 305f9fcd409b src/p4l/views.py --- a/src/p4l/views.py Tue Sep 10 12:14:52 2013 +0200 +++ b/src/p4l/views.py Tue Sep 10 16:54:29 2013 +0200 @@ -141,6 +141,34 @@ 'datarootquery': settings.SPARQL_THEME_QUERIES["root"] % lang, 'datachildsquery': settings.SPARQL_THEME_QUERIES["childs"] % lang, 'datachildcountquery': settings.SPARQL_THEME_QUERIES["child-count"] + }, + 'countries' : { + 'dataurl': settings.SPARQL_QUERY_ENDPOINT, + 'dataquery': settings.SPARQL_COUNTRY_QUERIES["filter"] % (lang, lang), + 'datarootquery': settings.SPARQL_COUNTRY_QUERIES["root"] % lang, + 'datachildsquery': settings.SPARQL_COUNTRY_QUERIES["childs"] % lang, + 'datachildcountquery': settings.SPARQL_COUNTRY_QUERIES["child-count"] + }, + 'languages' : { + 'dataurl': settings.SPARQL_QUERY_ENDPOINT, + 'dataquery': settings.SPARQL_LANGUAGE_QUERIES["filter"] % (lang, lang), + 'datarootquery': settings.SPARQL_LANGUAGE_QUERIES["root"] % lang, + 'datachildsquery': "", + 'datachildcountquery': "" + }, + 'projects' : { + 'dataurl': settings.SPARQL_QUERY_ENDPOINT, + 'dataquery': settings.SPARQL_PROJECT_QUERIES["filter"], + 'datarootquery': settings.SPARQL_PROJECT_QUERIES["root"], + 'datachildsquery': "", + 'datachildcountquery': "" + }, + 'organizations' : { + 'dataurl': settings.SPARQL_QUERY_ENDPOINT, + 'dataquery': settings.SPARQL_ORGANIZATION_QUERIES["filter"], + 'datarootquery': settings.SPARQL_ORGANIZATION_QUERIES["root"], + 'datachildsquery': "", + 'datachildcountquery': "" } } context['query_dicts'] = json.dumps(query_dicts)