diff -r 71532a54d1c4 -r 53c9233a7684 src/p4l/views.py --- a/src/p4l/views.py Fri Sep 20 00:03:31 2013 +0200 +++ b/src/p4l/views.py Fri Sep 20 00:14:42 2013 +0200 @@ -4,9 +4,10 @@ @author: tc ''' - +from datetime import datetime from django.conf import settings -from django.views.generic import ListView, DetailView +from django.views.generic import ListView, DetailView, View +from django.shortcuts import redirect, get_object_or_404 from p4l.forms import RecordFilterForm from p4l.models import Record from p4l.utils import get_labels_for_uris @@ -95,6 +96,11 @@ uri_list = [self.object.recordType] uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False) context['recordType_label'] = uris_labels[self.object.recordType] + # Here, in the future, there will be the request for audiences thesaurus + context['audiences_labels'] = {} + #uri_list = [s.uri for s in self.object.audiences.all()] + #uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Audiences", lang, False) + #context['audiences_labels'] = uris_labels return context @@ -175,6 +181,13 @@ 'datarootquery': settings.SPARQL_TYPE_QUERIES["root"] % lang, 'datachildsquery': "", 'datachildcountquery': "" + }, + 'audiences': { + 'dataurl': settings.SPARQL_QUERY_ENDPOINT, + 'dataquery': settings.SPARQL_AUDIENCE_QUERIES["filter"], + 'datarootquery': settings.SPARQL_AUDIENCE_QUERIES["root"], + 'datachildsquery': settings.SPARQL_AUDIENCE_QUERIES["childs"], + 'datachildcountquery': settings.SPARQL_AUDIENCE_QUERIES["child-count"] } } context['query_dicts'] = json.dumps(query_dicts) @@ -183,5 +196,20 @@ context['languages_list'] = json.dumps(settings.LANGUAGES_LIST) return context - + + +class RecordNewView(View): + def get(self, request, *args, **kwargs): + rec = Record() + rec.identifier = "T" + datetime.now().strftime("%Y%m%d%H%M%S") + rec.uri = "http://www.iiep.unesco.org/plan4learning/record/" + rec.identifier + rec.save() + return redirect('p4l_record_edit', rec.identifier) + + +class RecordDeleteView(View): + def get(self, request, slug, **kwargs): + rec = get_object_or_404(Record, identifier=slug) + rec.delete() + return redirect('p4l_home') \ No newline at end of file