--- a/src/p4l/static/p4l/js/p4l.js Wed Sep 04 15:18:22 2013 +0200
+++ b/src/p4l/static/p4l/js/p4l.js Wed Sep 04 16:17:04 2013 +0200
@@ -9,6 +9,7 @@
app.controller("RecordCtrl", function($scope, Api, context){
$scope.record = Api.record.get({recordId: context.record_id});
+ $scope.uriLabels = context.uri_labels;
});
app.config(['$routeProvider', function($routeProvider) {
--- a/src/p4l/templates/p4l/record_update_form.html Wed Sep 04 15:18:22 2013 +0200
+++ b/src/p4l/templates/p4l/record_update_form.html Wed Sep 04 16:17:04 2013 +0200
@@ -11,7 +11,8 @@
<script type="text/javascript">
angular.module("recordApp")
.value('context', {
- record_id: "{{id}}",
+ record_id: "{{record.identifier}}",
+ uri_labels: JSON.parse('{{uri_labels | safe}}'),
urls: {
record_api: "{% url 'record-detail' identifier=':recordId' %}".replace("\%3A",":")
}
@@ -20,12 +21,33 @@
{% endblock %}
{% block content %}
+{% verbatim %}
<div ng-app="recordApp" ng-controller="RecordCtrl">
-{% verbatim %}
-<p>identifier <input name="identifier" ng-model="record.identifier"/></p>
+<table class="table record-table">
+ <thead>
+ <tr><td>property</td><td>value</td></tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>URI</td>
+ <td>{{record.uri}}</td>
+ </tr>
+ <tr>
+ <td>identifier</td>
+ <td>{{record.identifier}}</td>
+ </tr>
+ <tr>
+ <td>subjects</td>
+ <td>
+ <ul ng-repeat="subject in record.subjects">
+ <li>{{uriLabels[subject]}} <small class="text-muted">({{subject}})</small></li>
+ </ul>
+ </td>
+ </tr>
+ </tbody>
+</table>
+</div>
{% endverbatim %}
-</div>
-
<div class="row">
<div class="col-md-12 text-right">
<a href="?uri={{ record.uri }}&lang=fr" alt="FR" /><img src="{% static 'p4l/img/blank.gif' %}" class="flag flag-fr" alt="FR" /></a>
--- a/src/p4l/utils.py Wed Sep 04 15:18:22 2013 +0200
+++ b/src/p4l/utils.py Wed Sep 04 16:17:04 2013 +0200
@@ -77,14 +77,14 @@
else:
query = query_without_acronym
res_dict = {}
+ if not uri_list:
+ return res_dict
# We build the filter string
filter_str = ""
for i,uri in enumerate(uri_list):
res_dict[uri] = ""
- if i==0:
- filter_str = "?uri = <" + uri + ">"
- else:
- filter_str += " || ?uri = <" + uri + ">"
+ filter_str += (" || ?uri = <" + uri + ">") if i else ("?uri = <" + uri + ">")
+
# We request the labels
res = requests.get(
settings.SPARQL_QUERY_ENDPOINT,
--- 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