keep on record form. several sparql requests
--- 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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept.
+ ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+ ?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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept ;
+ skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> ;
+ skos:prefLabel ?label .
+ FILTER (lang(?label) = %s).
+ FILTER NOT EXISTS { [skos:narrower ?uri] }
+}
+""",
+'childs' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+ { ?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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT (COUNT(?uri) as ?nb)
+WHERE {
+ ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+ ?root skos:narrower|skos:member ?uri.
+}
+"""
+}
+SPARQL_LANGUAGE_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept.
+ ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Languages> .
+ ?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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept ;
+ skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Languages> ;
+ skos:prefLabel ?label .
+ FILTER (lang(?label) = %s).
+ FILTER NOT EXISTS { [skos:narrower ?uri] }
+}
+"""
+}
+SPARQL_PROJECT_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept.
+ ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> .
+ ?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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept ;
+ skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> ;
+ skos:prefLabel ?label .
+}
+"""
+}
+SPARQL_ORGANIZATION_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept.
+ ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> .
+ ?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:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+ ?uri a skos:Concept ;
+ skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> ;
+ skos:prefLabel ?label .
+}
+"""
+}
REST_FRAMEWORK = {
--- 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';
--- 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({
--- 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 @@
</ul>
<form class="form-inline" role="form">
<div class="form-group col-md-8">
- <input id="id_{{ $id }}" ng-model="addUriText" class="semantic-tree form-control col-md-10" type="text" placeholder="{{'Add a new theme' | translate}}"
+ <input id="id_{{ $id }}" ng-model="addUriText" class="semantic-tree form-control col-md-10" type="text" placeholder="{{ placeholder }}"
data-url="{{ dataurl }}" data-query="{{ dataquery }}" data-root-query="{{ datarootquery }}"
data-childs-query="{{ datachildsquery }}" data-child-count-query="{{ datachildcountquery }}" />
{{ 'or' | translate}}
--- 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 @@
<td>{{record.uri}}</td>
</tr>
<tr>
- <td>{{'identifier' | translate}}</td>
+ <td>{{ 'identifier' | translate}}</td>
<td>{{record.identifier}}</td>
</tr>
<tr>
- <td>{{'subjects' | translate}}</td>
- <td>
- <add-sem-uri list="record.subjects" listname="subjects"></add-sem-uri>
- </td>
+ <td>{{ 'subjects' | translate}}</td>
+ <td><add-sem-uri list="record.subjects" listname="subjects" placeholder="{{'Add a new subject' | translate}}"></add-sem-uri></td>
</tr>
<tr>
- <td>{{'themes' | translate}}</td>
- <td>
- <add-sem-uri list="record.themes" listname="themes"></add-sem-uri>
- </td>
+ <td>{{ 'themes' | translate}}</td>
+ <td><add-sem-uri list="record.themes" listname="themes" placeholder="{{'Add a new theme' | translate}}"></add-sem-uri></td>
</tr>
<tr>
- <td>{{'notes' | translate}}</td>
+ <td>{{ 'countries' | translate}}</td>
+ <td><add-sem-uri list="record.countries" listname="countries" placeholder="{{'Add a new country' | translate}}"></add-sem-uri></td>
+ </tr>
+ <tr>
+ <td>{{ 'notes' | translate}}</td>
<td><textarea id="record-notes-input" class="form-control" ng-model="record.notes"></textarea></td>
</tr>
<tr>
@@ -80,13 +80,113 @@
<td><object-list form-template="isbnForm" disp-template="isbnDisp" object-list="record.isbns" object-fields='["isbn"]'></object-list></td>
</tr>
<tr>
- <td>{{'document code' | translate }}</td>
+ <td>{{ 'document code' | translate }}</td>
<td><object-list form-template="documentCodeForm" disp-template="documentCodeDisp" object-list="record.documentCodes" object-fields='["documentCode"]'></object-list></td>
</tr>
<tr>
- <td>{{'imprints' | translate}}</td>
+ <td>{{ 'language' | translate }}</td>
+ <td><small>#todo WITH SPARQL</small></td>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'other languages' | translate }}</td>
+ <td><add-sem-uri list="record.otherLanguages" listname="languages" placeholder="{{'Add a new language' | translate}}"></add-sem-uri></td>
+ </tr>
+ <tr>
+ <td>{{ 'titles' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'abstracts' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'added titles' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'titles main document' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'edition statement' | translate }}</td>
+ <td><textarea id="record-editionStatement-input" class="form-control" ng-model="record.editionStatement"></textarea></td>
+ </tr>
+ <tr>
+ <td>{{ 'imprints' | translate }}</td>
<td><object-list form-template="imprintForm" disp-template="imprintDisp" object-list="record.imprints" object-fields='["imprintCity","publisher","imprintDate", "lang"]'></object-list></td>
- </tr>
+ </tr>
+ <tr>
+ <td>{{ 'collations' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'volume issues' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'project names' | translate }}</td>
+ <td><add-sem-uri list="record.projectNames" listname="projects" placeholder="{{'Add a new project' | translate}}"></add-sem-uri></td>
+ </tr>
+ <tr>
+ <td>{{ 'periodicals' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'meetings' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'series' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'authors' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'subject persons' | translate }}</td>
+ <td><small>#todo</small>
+</td>
+ </tr>
+ <tr>
+ <td>{{ 'subject corporate bodies' | translate }}</td>
+ <td><add-sem-uri list="record.subjectCorporateBodies" listname="organizations" placeholder="{{'Add a new organization' | translate}}"></add-sem-uri></td>
+ </tr>
+ <tr>
+ <td>{{ 'subject meetings' | translate }}</td>
+ <td><small>#todo</small></td>
+ </tr>
+ <tr>
+ <td>{{ 'corporate authors' | translate }}</td>
+ <td><add-sem-uri list="record.corporateAuthors" listname="organizations" placeholder="{{'Add a new organization' | translate}}"></add-sem-uri></td>
+ </tr>
+ <tr>
+ <td>{{ 'Urls' | translate }}</td>
+ <td><small>#todo</small></td>
+ </tr>
+ <tr>
+ <td>{{ 'record type' | translate }}</td>
+ <td><small>#todo WITH SPARQL</small></td>
+ </tr>
+ <tr>
+ <td>{{ 'is document part' | translate }}</td>
+ <td><small>#todo checkbox</small></td>
+ </tr>
+ <tr>
+ <td>{{ 'is multilingual' | translate }}</td>
+ <td><small>#todo checkbox</small></td>
+ </tr>
</tbody>
</table>
<button ng-click="submitRecord()">{{ 'Save' | translate }}</button>
--- 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
--- 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)