src/p4l/views.py
changeset 102 53c9233a7684
parent 99 0d54489e8b26
child 113 c05567404888
equal deleted inserted replaced
101:71532a54d1c4 102:53c9233a7684
     2 '''
     2 '''
     3 Created on Aug 27, 2013
     3 Created on Aug 27, 2013
     4 
     4 
     5 @author: tc
     5 @author: tc
     6 '''
     6 '''
     7 
     7 from datetime import datetime
     8 from django.conf import settings
     8 from django.conf import settings
     9 from django.views.generic import ListView, DetailView
     9 from django.views.generic import ListView, DetailView, View
       
    10 from django.shortcuts import redirect, get_object_or_404
    10 from p4l.forms import RecordFilterForm
    11 from p4l.forms import RecordFilterForm
    11 from p4l.models import Record
    12 from p4l.models import Record
    12 from p4l.utils import get_labels_for_uris
    13 from p4l.utils import get_labels_for_uris
    13 import json
    14 import json
    14 import logging
    15 import logging
    93         # We get the recordType'labels with the DocumentType repository
    94         # We get the recordType'labels with the DocumentType repository
    94         if self.object.recordType:
    95         if self.object.recordType:
    95             uri_list = [self.object.recordType]
    96             uri_list = [self.object.recordType]
    96             uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False)
    97             uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False)
    97             context['recordType_label'] = uris_labels[self.object.recordType]
    98             context['recordType_label'] = uris_labels[self.object.recordType]
       
    99         # Here, in the future, there will be the request for audiences thesaurus
       
   100         context['audiences_labels'] = {}
       
   101         #uri_list = [s.uri for s in self.object.audiences.all()]
       
   102         #uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Audiences", lang, False)
       
   103         #context['audiences_labels'] = uris_labels
    98         
   104         
    99         return context
   105         return context
   100 
   106 
   101 class RecordEditView(DetailView):
   107 class RecordEditView(DetailView):
   102     http_method_names = ['get']
   108     http_method_names = ['get']
   173                 'dataurl': settings.SPARQL_QUERY_ENDPOINT,
   179                 'dataurl': settings.SPARQL_QUERY_ENDPOINT,
   174                 'dataquery': settings.SPARQL_TYPE_QUERIES["filter"] % (lang, lang),
   180                 'dataquery': settings.SPARQL_TYPE_QUERIES["filter"] % (lang, lang),
   175                 'datarootquery': settings.SPARQL_TYPE_QUERIES["root"] % lang,
   181                 'datarootquery': settings.SPARQL_TYPE_QUERIES["root"] % lang,
   176                 'datachildsquery': "",
   182                 'datachildsquery': "",
   177                 'datachildcountquery': ""
   183                 'datachildcountquery': ""
       
   184             },
       
   185             'audiences': {
       
   186                 'dataurl': settings.SPARQL_QUERY_ENDPOINT,
       
   187                 'dataquery': settings.SPARQL_AUDIENCE_QUERIES["filter"],
       
   188                 'datarootquery': settings.SPARQL_AUDIENCE_QUERIES["root"],
       
   189                 'datachildsquery': settings.SPARQL_AUDIENCE_QUERIES["childs"],
       
   190                 'datachildcountquery': settings.SPARQL_AUDIENCE_QUERIES["child-count"]
   178             }
   191             }
   179         }
   192         }
   180         context['query_dicts'] = json.dumps(query_dicts)
   193         context['query_dicts'] = json.dumps(query_dicts)
   181         
   194         
   182         # Languages list used in drop down list
   195         # Languages list used in drop down list
   183         context['languages_list'] = json.dumps(settings.LANGUAGES_LIST)
   196         context['languages_list'] = json.dumps(settings.LANGUAGES_LIST)
   184                 
   197                 
   185         return context
   198         return context
   186         
   199 
   187         
   200 
       
   201 class RecordNewView(View):
       
   202     def get(self, request, *args, **kwargs):
       
   203         rec = Record()
       
   204         rec.identifier = "T" + datetime.now().strftime("%Y%m%d%H%M%S")
       
   205         rec.uri = "http://www.iiep.unesco.org/plan4learning/record/" + rec.identifier
       
   206         rec.save()
       
   207         return redirect('p4l_record_edit', rec.identifier)
       
   208 
       
   209 
       
   210 class RecordDeleteView(View):
       
   211     def get(self, request, slug, **kwargs):
       
   212         rec = get_object_or_404(Record, identifier=slug)
       
   213         rec.delete()
       
   214         return redirect('p4l_home')
       
   215