src/p4l/views.py
changeset 38 c4e5bb735ec1
parent 35 544bc92e6fe7
child 40 cc7149ca6863
equal deleted inserted replaced
37:7ff73789a851 38:c4e5bb735ec1
    12 from p4l.forms import RecordFilterForm
    12 from p4l.forms import RecordFilterForm
    13 from p4l.models import Record
    13 from p4l.models import Record
    14 from p4l.utils import get_labels_for_uris
    14 from p4l.utils import get_labels_for_uris
    15 import json
    15 import json
    16 import logging
    16 import logging
       
    17 from p4l.semantictree.forms.forms import SubjectForm
       
    18 from django.utils.safestring import mark_safe
    17 
    19 
    18 
    20 
    19 logger = logging.getLogger(__name__)
    21 logger = logging.getLogger(__name__)
    20 
    22 
    21 class RecordListView(ListView):
    23 class RecordListView(ListView):
   130         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.otherLanguages.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False))
   132         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.otherLanguages.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False))
   131         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.projectNames.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True))
   133         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.projectNames.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True))
   132         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.subjectCorporateBodies.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
   134         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.subjectCorporateBodies.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
   133         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.corporateAuthors.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
   135         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.corporateAuthors.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
   134         uri_labels.update(get_labels_for_uris([self.object.recordType] if self.object.recordType else [], "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False))
   136         uri_labels.update(get_labels_for_uris([self.object.recordType] if self.object.recordType else [], "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False))
   135 
       
   136         context['uri_labels'] = json.dumps(uri_labels)
   137         context['uri_labels'] = json.dumps(uri_labels)
   137         
   138         
       
   139         context['subjects_query_dict'] = json.dumps({
       
   140                             'data-url': settings.SPARQL_QUERY_ENDPOINT,
       
   141                             'data-query':  
       
   142 """
       
   143 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   144 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   145 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   146 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   147 SELECT DISTINCT ?uri ?label
       
   148 WHERE {
       
   149     ?uri a skos:Concept.
       
   150     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   151     ?uri skos:prefLabel ?label.
       
   152     FILTER (lang(?label) = ?language).
       
   153     ?uri skos:prefLabel ?lab.
       
   154     FILTER regex (str(?lab), ?reg, 'i').
       
   155     FILTER (lang (?lab) = ?language).
       
   156     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   157     BIND (STRLEN(STR(?lab)) AS ?len)
       
   158 }
       
   159 ORDER BY ?place ?len ?lab
       
   160 """,
       
   161                             'data-root-query':
       
   162 """
       
   163 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   164 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   165 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   166 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   167 SELECT DISTINCT ?uri ?label
       
   168 WHERE {
       
   169     ?uri a skos:Collection ;
       
   170     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
   171     rdfs:label ?label .
       
   172     FILTER (lang(?label) = ?language). 
       
   173     FILTER NOT EXISTS { [skos:member ?uri] }
       
   174 }
       
   175 """,
       
   176                             'data-childs-query':
       
   177 """
       
   178 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   179 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   180 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   181 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   182 SELECT DISTINCT ?uri ?label
       
   183 WHERE {
       
   184   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   185   { ?uri a ?type
       
   186     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   187   ?root skos:narrower|skos:member ?uri.
       
   188   ?uri skos:prefLabel|rdfs:label ?label.
       
   189   FILTER (lang(?label) = ?language).
       
   190 }
       
   191 """,
       
   192                             'data-child-count-query':
       
   193 """
       
   194 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   195 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   196 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   197 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   198 SELECT (COUNT(?uri) as ?nb)
       
   199 WHERE {
       
   200     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   201     ?root skos:narrower|skos:member ?uri.
       
   202 }
       
   203 """
       
   204                             })
       
   205         
   138         return context
   206         return context
   139         
   207         
   140         
   208