src/p4l/views.py
changeset 17 b31a67614f76
parent 8 d10cdb768a03
child 20 fa466993084a
--- a/src/p4l/views.py	Mon Sep 02 11:45:01 2013 +0200
+++ b/src/p4l/views.py	Mon Sep 02 16:26:21 2013 +0200
@@ -14,6 +14,7 @@
 #from django.views.generic.list import MultipleObjectMixin
 from .models import Record
 from .forms import RecordFilterForm
+from .utils import get_labels_for_uris
 import logging
 
 
@@ -55,6 +56,49 @@
     def get_object(self, queryset=None):
         if "uri" not in self.request.GET:
             raise AttributeError(u"Record view must be called uri GET parameter")
+        return get_object_or_404(Record.objects.select_related("language"), uri=self.request.GET["uri"])
+    
+    def get_context_data(self, **kwargs):
+        context = DetailView.get_context_data(self, **kwargs)
+        # self.object is the record entry
+        # We get the subjects'labels with the Thesaurus repository
+        uri_list = [s.uri for s in self.object.subjects.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000", "fr", False)
+        context['subjects_labels'] = uris_labels
+        # We get the themes'labels with the Themes repository
+        uri_list = [s.uri for s in self.object.themes.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Themes", "fr", False)
+        context['themes_labels'] = uris_labels
+        # We get the countries'labels with the Thesaurus repository
+        uri_list = [s.uri for s in self.object.countries.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000/Countries", "fr", False)
+        context['countries_labels'] = uris_labels
+        # We get the languages'labels with the Languages repository
+        if self.object.language:
+            uri_list = [self.object.language.uri]
+            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", "fr", False)
+            context['language_label'] = uris_labels[self.object.language.uri]
+        # We get the other languages'labels with the Languages repository
+        uri_list = [s.uri for s in self.object.otherLanguages.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", "fr", False)
+        context['otherLanguages_labels'] = uris_labels
+        # We get the project'labels with the Projects repository
+        uri_list = [s.uri for s in self.object.projectNames.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True)
+        context['projects_labels'] = uris_labels
+        # We get the subjectCorporateBodies'labels with the Organizations repository
+        uri_list = [s.uri for s in self.object.subjectCorporateBodies.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
+        context['subjectCorporateBodies_labels'] = uris_labels
+        # We get the corporateAuthors'labels with the Organizations repository
+        uri_list = [s.uri for s in self.object.corporateAuthors.all()]
+        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
+        context['corporateAuthors_labels'] = uris_labels
+        # We get the recordType'labels with the DocumentType repository
+        if self.object.recordType:
+            uri_list = [self.object.recordType]
+            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", "fr", False)
+            context['recordType_label'] = uris_labels[self.object.recordType]
         
-        return get_object_or_404(Record.objects.select_related("language"), uri=self.request.GET["uri"])
+        return context