diff -r 945b144d68c1 -r cfc090f440d0 src/p4l/views.py --- a/src/p4l/views.py Wed Sep 04 15:18:22 2013 +0200 +++ b/src/p4l/views.py Wed Sep 04 16:17:04 2013 +0200 @@ -7,12 +7,12 @@ from django.conf import settings from django.contrib.auth.decorators import login_required -from django.shortcuts import get_object_or_404 from django.utils.decorators import method_decorator -from django.views.generic import ListView, DetailView, TemplateView +from django.views.generic import ListView, DetailView from p4l.forms import RecordFilterForm from p4l.models import Record from p4l.utils import get_labels_for_uris +import json import logging @@ -108,7 +108,34 @@ return context -class RecordEditView(TemplateView): +class RecordEditView(DetailView): http_method_names = ['get'] template_name = 'p4l/record_update_form.html' + model = Record + slug_field = "identifier" + slug_url_kwarg = "id" + def get_context_data(self, **kwargs): + context = DetailView.get_context_data(self, **kwargs) + # We get the language, "fr" by default + lang = "fr" + if "lang" in self.request.GET: + lang = self.request.GET["lang"] + elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]: + lang = self.request.LANGUAGE_CODE + + uri_labels = get_labels_for_uris([s.uri for s in self.object.subjects.all()], "http://skos.um.es/unescothes/CS000", lang, False) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + + context['uri_labels'] = json.dumps(uri_labels) + + return context + + \ No newline at end of file