12 from django.shortcuts import get_object_or_404 |
12 from django.shortcuts import get_object_or_404 |
13 from django.views.generic import ListView, DetailView#, View |
13 from django.views.generic import ListView, DetailView#, View |
14 #from django.views.generic.list import MultipleObjectMixin |
14 #from django.views.generic.list import MultipleObjectMixin |
15 from .models import Record |
15 from .models import Record |
16 from .forms import RecordFilterForm |
16 from .forms import RecordFilterForm |
|
17 from .utils import get_labels_for_uris |
17 import logging |
18 import logging |
18 |
19 |
19 |
20 |
20 logger = logging.getLogger(__name__) |
21 logger = logging.getLogger(__name__) |
21 |
22 |
53 slug_field = "uri" # Even if it is useless because we override get_objet |
54 slug_field = "uri" # Even if it is useless because we override get_objet |
54 |
55 |
55 def get_object(self, queryset=None): |
56 def get_object(self, queryset=None): |
56 if "uri" not in self.request.GET: |
57 if "uri" not in self.request.GET: |
57 raise AttributeError(u"Record view must be called uri GET parameter") |
58 raise AttributeError(u"Record view must be called uri GET parameter") |
|
59 return get_object_or_404(Record.objects.select_related("language"), uri=self.request.GET["uri"]) |
|
60 |
|
61 def get_context_data(self, **kwargs): |
|
62 context = DetailView.get_context_data(self, **kwargs) |
|
63 # self.object is the record entry |
|
64 # We get the subjects'labels with the Thesaurus repository |
|
65 uri_list = [s.uri for s in self.object.subjects.all()] |
|
66 uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000", "fr", False) |
|
67 context['subjects_labels'] = uris_labels |
|
68 # We get the themes'labels with the Themes repository |
|
69 uri_list = [s.uri for s in self.object.themes.all()] |
|
70 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Themes", "fr", False) |
|
71 context['themes_labels'] = uris_labels |
|
72 # We get the countries'labels with the Thesaurus repository |
|
73 uri_list = [s.uri for s in self.object.countries.all()] |
|
74 uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000/Countries", "fr", False) |
|
75 context['countries_labels'] = uris_labels |
|
76 # We get the languages'labels with the Languages repository |
|
77 if self.object.language: |
|
78 uri_list = [self.object.language.uri] |
|
79 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", "fr", False) |
|
80 context['language_label'] = uris_labels[self.object.language.uri] |
|
81 # We get the other languages'labels with the Languages repository |
|
82 uri_list = [s.uri for s in self.object.otherLanguages.all()] |
|
83 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", "fr", False) |
|
84 context['otherLanguages_labels'] = uris_labels |
|
85 # We get the project'labels with the Projects repository |
|
86 uri_list = [s.uri for s in self.object.projectNames.all()] |
|
87 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True) |
|
88 context['projects_labels'] = uris_labels |
|
89 # We get the subjectCorporateBodies'labels with the Organizations repository |
|
90 uri_list = [s.uri for s in self.object.subjectCorporateBodies.all()] |
|
91 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True) |
|
92 context['subjectCorporateBodies_labels'] = uris_labels |
|
93 # We get the corporateAuthors'labels with the Organizations repository |
|
94 uri_list = [s.uri for s in self.object.corporateAuthors.all()] |
|
95 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True) |
|
96 context['corporateAuthors_labels'] = uris_labels |
|
97 # We get the recordType'labels with the DocumentType repository |
|
98 if self.object.recordType: |
|
99 uri_list = [self.object.recordType] |
|
100 uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", "fr", False) |
|
101 context['recordType_label'] = uris_labels[self.object.recordType] |
58 |
102 |
59 return get_object_or_404(Record.objects.select_related("language"), uri=self.request.GET["uri"]) |
103 return context |
60 |
104 |