src/p4l/views.py
author cavaliet
Thu, 05 Sep 2013 14:53:00 +0200
changeset 40 cc7149ca6863
parent 38 c4e5bb735ec1
child 43 829d9d4111da
permissions -rw-r--r--
good place for login_required
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     2
'''
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     3
Created on Aug 27, 2013
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     4
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     5
@author: tc
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     6
'''
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     7
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     8
from django.conf import settings
24
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
     9
from django.utils.decorators import method_decorator
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
    10
from django.views.generic import ListView, DetailView
26
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    11
from p4l.forms import RecordFilterForm
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    12
from p4l.models import Record
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    13
from p4l.utils import get_labels_for_uris
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
    14
import json
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    15
import logging
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    16
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    17
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    18
logger = logging.getLogger(__name__)
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    19
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    20
class RecordListView(ListView):
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    21
    
5
62e97cd13730 debug query and enhance display
cavaliet
parents: 4
diff changeset
    22
    queryset = Record.objects.select_related("language").prefetch_related('titles').distinct()  # @UndefinedVariable
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    23
    paginate_by = settings.NB_RECORDS_BY_PAGE
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    24
    template_name = "p4l/p4l_home.html"
4
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    25
    form_class = RecordFilterForm
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    26
    
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    27
    def get_context_data(self, **kwargs):
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    28
        context = ListView.get_context_data(self, **kwargs)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    29
        context['filter_form'] = self.form_class()
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    30
        # Add filter params from GET params
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    31
        filter_params = {}
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    32
        if 'title' in self.request.GET:
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    33
            filter_params['title'] = self.request.GET['title']
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    34
        context['filter_params'] = filter_params
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    35
        return context
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    36
    
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    37
    def get_queryset(self):
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    38
        qs = super(RecordListView, self).get_queryset()
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    39
        filter_form = self.form_class(self.request.GET)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    40
        if filter_form.is_valid():
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    41
            return filter_form.get_filter_qs(qs)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    42
        else:
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    43
            return qs
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    44
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    45
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    46
class RecordDetailView(DetailView):
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    47
    
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    48
    model = Record
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    49
    template_name = "p4l/p4l_record_view.html"
30
a84e31f1f223 update record view with slug
cavaliet
parents: 29
diff changeset
    50
    slug_field = "identifier"
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    51
    
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    52
    def get_context_data(self, **kwargs):
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    53
        context = DetailView.get_context_data(self, **kwargs)
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    54
        # We get the language, "fr" by default
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    55
        lang = "fr"
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    56
        if "lang" in self.request.GET:
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    57
            lang = self.request.GET["lang"]
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    58
        elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]:
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    59
            lang = self.request.LANGUAGE_CODE
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    60
        # self.object is the record entry
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    61
        # We get the subjects'labels with the Thesaurus repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    62
        uri_list = [s.uri for s in self.object.subjects.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    63
        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    64
        context['subjects_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    65
        # We get the themes'labels with the Themes repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    66
        uri_list = [s.uri for s in self.object.themes.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    67
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Themes", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    68
        context['themes_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    69
        # We get the countries'labels with the Thesaurus repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    70
        uri_list = [s.uri for s in self.object.countries.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    71
        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000/Countries", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    72
        context['countries_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    73
        # We get the languages'labels with the Languages repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    74
        if self.object.language:
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    75
            uri_list = [self.object.language.uri]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    76
            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    77
            context['language_label'] = uris_labels[self.object.language.uri]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    78
        # We get the other languages'labels with the Languages repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    79
        uri_list = [s.uri for s in self.object.otherLanguages.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    80
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    81
        context['otherLanguages_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    82
        # We get the project'labels with the Projects repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    83
        uri_list = [s.uri for s in self.object.projectNames.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    84
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    85
        context['projects_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    86
        # We get the subjectCorporateBodies'labels with the Organizations repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    87
        uri_list = [s.uri for s in self.object.subjectCorporateBodies.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    88
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    89
        context['subjectCorporateBodies_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    90
        # We get the corporateAuthors'labels with the Organizations repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    91
        uri_list = [s.uri for s in self.object.corporateAuthors.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    92
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    93
        context['corporateAuthors_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    94
        # We get the recordType'labels with the DocumentType repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    95
        if self.object.recordType:
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    96
            uri_list = [self.object.recordType]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    97
            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    98
            context['recordType_label'] = uris_labels[self.object.recordType]
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    99
        
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   100
        return context
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
   101
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   102
class RecordEditView(DetailView):
29
3a3b90b1abb2 Correction after rebase/merge
ymh <ymh.work@gmail.com>
parents: 27
diff changeset
   103
    http_method_names = ['get']
3a3b90b1abb2 Correction after rebase/merge
ymh <ymh.work@gmail.com>
parents: 27
diff changeset
   104
    template_name = 'p4l/record_update_form.html'
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   105
    model = Record
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   106
    slug_field = "identifier"
26
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   107
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   108
    def get_context_data(self, **kwargs):
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   109
        context = DetailView.get_context_data(self, **kwargs)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   110
        # We get the language, "fr" by default
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   111
        lang = "fr"
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   112
        if "lang" in self.request.GET:
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   113
            lang = self.request.GET["lang"]
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   114
        elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]:
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   115
            lang = self.request.LANGUAGE_CODE
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   116
        
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   117
        uri_labels = get_labels_for_uris([s.uri for s in self.object.subjects.all()], "http://skos.um.es/unescothes/CS000", lang, False)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   118
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.themes.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Themes", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   119
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.countries.all()], "http://skos.um.es/unescothes/CS000/Countries", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   120
        uri_labels.update(get_labels_for_uris([self.object.language.uri] if self.object.language else [], "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   121
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   122
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   123
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   124
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   125
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   126
        context['uri_labels'] = json.dumps(uri_labels)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   127
        
38
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   128
        context['subjects_query_dict'] = json.dumps({
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   129
                            'data-url': settings.SPARQL_QUERY_ENDPOINT,
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   130
                            'data-query':  
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   131
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   132
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   133
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   134
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   135
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   136
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   137
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   138
    ?uri a skos:Concept.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   139
    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   140
    ?uri skos:prefLabel ?label.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   141
    FILTER (lang(?label) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   142
    ?uri skos:prefLabel ?lab.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   143
    FILTER regex (str(?lab), ?reg, 'i').
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   144
    FILTER (lang (?lab) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   145
    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   146
    BIND (STRLEN(STR(?lab)) AS ?len)
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   147
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   148
ORDER BY ?place ?len ?lab
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   149
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   150
                            'data-root-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   151
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   152
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   153
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   154
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   155
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   156
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   157
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   158
    ?uri a skos:Collection ;
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   159
    skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
40
cc7149ca6863 good place for login_required
cavaliet
parents: 38
diff changeset
   160
    skos:prefLabel|rdfs:label ?label .
38
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   161
    FILTER (lang(?label) = ?language). 
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   162
    FILTER NOT EXISTS { [skos:member ?uri] }
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   163
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   164
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   165
                            'data-childs-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   166
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   167
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   168
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   169
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   170
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   171
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   172
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   173
  ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   174
  { ?uri a ?type
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   175
    FILTER (?type = skos:Collection || ?type = skos:Concept) }.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   176
  ?root skos:narrower|skos:member ?uri.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   177
  ?uri skos:prefLabel|rdfs:label ?label.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   178
  FILTER (lang(?label) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   179
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   180
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   181
                            'data-child-count-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   182
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   183
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   184
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   185
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   186
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   187
SELECT (COUNT(?uri) as ?nb)
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   188
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   189
    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   190
    ?root skos:narrower|skos:member ?uri.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   191
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   192
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   193
                            })
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   194
        
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   195
        return context
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   196
        
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   197