--- a/src/p4l/management/commands/get_country_label.py Wed Sep 04 10:01:38 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.core.management import BaseCommand
-from p4l.models import Country
-from p4l.utils import fill_label_for_model
-
-
-class Command(BaseCommand):
-
- def handle(self, *args, **options):
- fill_label_for_model(Country, 'country', 'http://skos.um.es/unescothes/CS000/Countries')
-
--- a/src/p4l/management/commands/get_language_label.py Wed Sep 04 10:01:38 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.core.management import BaseCommand
-from p4l.models import Language
-from p4l.utils import fill_label_for_model
-
-
-class Command(BaseCommand):
-
- def handle(self, *args, **options):
- fill_label_for_model(Language, 'language', 'http://www.iiep.unesco.org/plan4learning/scheme/Languages')
--- a/src/p4l/management/commands/get_subject_label.py Wed Sep 04 10:01:38 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.core.management import BaseCommand
-from p4l.models import Subject
-from p4l.utils import fill_label_for_model
-
-
-class Command(BaseCommand):
-
- def handle(self, *args, **options):
- fill_label_for_model(Subject, 'subject', 'http://skos.um.es/unescothes/CS000')
-
--- a/src/p4l/management/commands/get_theme_label.py Wed Sep 04 10:01:38 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-from django.core.management import BaseCommand
-from p4l.models import Theme
-from p4l.utils import fill_label_for_model
-
-
-class Command(BaseCommand):
-
- def handle(self, *args, **options):
- fill_label_for_model(Theme, 'theme', 'http://www.iiep.unesco.org/plan4learning/scheme/Themes')
-
--- a/src/p4l/settings.py Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/settings.py Wed Sep 04 10:02:22 2013 +0200
@@ -187,4 +187,12 @@
from config import * # @UnusedWildImport
if not "SRC_BASE_URL" in locals():
- SRC_BASE_URL = BASE_URL + __name__.split('.')[0] + '/'
+ SRC_BASE_URL = BASE_URL + __name__.split('.')[0] + '/'
+if not "LOGIN_URL" in locals():
+ LOGIN_URL = SRC_BASE_URL + 'auth/login/'
+if not "LOGOUT_URL" in locals():
+ LOGOUT_URL = SRC_BASE_URL + 'auth/disconnect/'
+if not "LOGIN_REDIRECT_URL" in locals():
+ LOGIN_REDIRECT_URL = SRC_BASE_URL
+if not "LOGOUT_REDIRECT_URL" in locals():
+ LOGOUT_REDIRECT_URL = SRC_BASE_URL + 'auth/login'
--- a/src/p4l/templates/p4l/p4l_base.html Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/templates/p4l/p4l_base.html Wed Sep 04 10:02:22 2013 +0200
@@ -28,6 +28,15 @@
<a href="{% url 'p4l_home' %}">Plan 4 Learning</a>
</li>
</ul>
+ <ul class="nav navbar-nav" style="float:right;">
+ {% if user.is_authenticated %}
+ <li><a>{{ user.username }}</a></li>
+ {% if user.is_staff %}<li><a href="{% url 'admin:index' %}" >admin</a></li>{% endif %}
+ <li><a href="{% url 'logout' %}?next={% url 'p4l_home' %}" >{% trans 'logout' %}</a></li>
+ {% else %}
+ <li><a href="{% url 'login' %}" >{% trans 'login' %}</a></li>
+ {% endif %}
+ </ul>
</nav>
</div>
{% endblock %}
--- a/src/p4l/templates/p4l/p4l_record_view.html Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/templates/p4l/p4l_record_view.html Wed Sep 04 10:02:22 2013 +0200
@@ -37,15 +37,15 @@
</tr>
<tr>
<td>{% trans 'issns' %}</td>
- <td><ul>{% for i in record.issns.all %}<li>{{ i.issn|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.issns.all %}<li>{{ i.issn|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'isbns' %}</td>
- <td><ul>{% for i in record.isbns.all %}<li>{{ i.isbn|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.isbns.all %}<li>{{ i.isbn|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'document code' %}</td>
- <td><ul>{% for i in record.documentCodes.all %}<li>{{ i.documentCode|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.documentCodes.all %}<li>{{ i.documentCode|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'language' %}</td>
@@ -57,15 +57,19 @@
</tr>
<tr>
<td>{% trans 'titles' %}</td>
- <td><ul>{% for i in record.titles.all %}<li>{{ i.title|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.titles.all %}<li>{{ i.title|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
+ </tr>
+ <tr>
+ <td>{% trans 'abstracts' %}</td>
+ <td><ul>{% for i in record.abstracts.all %}<li>{{ i.abstract|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'added titles' %}</td>
- <td><ul>{% for i in record.addedTitles.all %}<li>{{ i.title|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.addedTitles.all %}<li>{{ i.title|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'titles main document' %}</td>
- <td><ul>{% for i in record.titlesMainDocument.all %}<li>{{ i.title|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.titlesMainDocument.all %}<li>{{ i.title|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'edition statement' %}</td>
@@ -81,6 +85,7 @@
<li>{% trans 'City' %} : {{ i.imprintCity|default:'' }}</li>
<li>{% trans 'Publisher' %} : {{ i.publisher|default:'' }}</li>
<li>{% trans 'Date' %} : {{ i.imprintDate|default:'' }}</li>
+ <li>{% trans 'Language' %} : {{ i.lang|default:'' }}</li>
</ul>
</li>
{% endfor %}
@@ -89,7 +94,7 @@
</tr>
<tr>
<td>{% trans 'collations' %}</td>
- <td><ul>{% for i in record.collations.all %}<li>{{ i.collation|default:'' }}</li>{% endfor %}</ul></td>
+ <td><ul>{% for i in record.collations.all %}<li>{{ i.collation|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
<td>{% trans 'volume issues' %}</td>
@@ -100,6 +105,7 @@
<ul class="list-unstyled">
<li>{% trans 'Volume' %} : {{ i.volume|default:'' }}</li>
<li>{% trans 'Number' %} : {{ i.number|default:'' }}</li>
+ <li>{% trans 'Language' %} : {{ i.lang|default:'' }}</li>
</ul>
</li>
{% endfor %}
@@ -111,17 +117,17 @@
<td><ul>{% for k,v in projects_labels.items %}<li>{{ v }} <small class="text-muted">({{ k }})</small></li>{% endfor %}</ul></td>
</tr>
<tr>
- <td>{% trans 'periodicals' %}</td>{# ajouter langue #}
- <td><ul>{% for i in record.periodicals.all %}<li>{{ i.label|default:'' }}</li>{% endfor %}</ul></td>
+ <td>{% trans 'periodicals' %}</td>
+ <td><ul>{% for i in record.periodicals.all %}<li>{{ i.label|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>{% endfor %}</ul></td>
</tr>
<tr>
- <td>{% trans 'meetings' %}</td>{# ajouter langue #}
+ <td>{% trans 'meetings' %}</td>
<td>
<ul>
{% for i in record.meetings.all %}
<li>
<ul class="list-unstyled">
- <li>{{ i.label|default:'' }}</li>
+ <li>{{ i.label|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>
<li>{% trans 'Number' %} : {{ i.meetingNumber|default:'' }}</li>
<li>{% trans 'Place' %} : {{ i.meetingPlace|default:'' }}</li>
<li>{% trans 'Date' %} : {{ i.meetingDate|default:'' }}</li>
@@ -133,13 +139,13 @@
</td>
</tr>
<tr>
- <td>{% trans 'series' %}</td>{# ajouter langue #}
+ <td>{% trans 'series' %}</td>
<td>
<ul>
{% for i in record.series.all %}
<li>
<ul class="list-unstyled">
- <li>{{ i.title|default:'' }}</li>
+ <li>{{ i.title|default:'' }}{% if i.lang %} <small class="text-muted">({{ i.lang }})</small>{% endif %}</li>
{% if i.volume %}<li>{% trans 'Volume' %} : {{ i.volume|default:'' }}</li>{% endif %}
</ul>
</li>
@@ -160,7 +166,7 @@
<td><ul>{% for k,v in subjectCorporateBodies_labels.items %}<li>{{ v }} <small class="text-muted">({{ k }})</small></li>{% endfor %}</ul></td>
</tr>
<tr>
- <td>{% trans 'subject meetings' %}</td>{# ajouter langue #}
+ <td>{% trans 'subject meetings' %}</td>
<td>
<ul>
{% for i in record.subjectMeetings.all %}
@@ -182,7 +188,7 @@
<td><ul>{% for k,v in corporateAuthors_labels.items %}<li>{{ v }} <small class="text-muted">({{ k }})</small></li>{% endfor %}</ul></td>
</tr>
<tr>
- <td>{% trans 'Urls' %}</td>{# ajouter langue #}
+ <td>{% trans 'Urls' %}</td>
<td>
<ul>
{% for i in record.urls.all %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/p4l/templates/registration/login.html Wed Sep 04 10:02:22 2013 +0200
@@ -0,0 +1,31 @@
+{% extends "p4l/p4l_base.html" %}
+{% load i18n %}
+
+{% block page_title %}{% trans 'login' %}{% endblock %}
+
+{% block content %}
+{% if form.errors %}
+ <p class="error">{% trans "Sorry, that's not a valid username or password." %}</p>
+{% endif %}
+ <form action="{% url 'login' %}" method='post' class="form-horizontal" role="form">
+ {% csrf_token %}
+ <input type="hidden" name="next" value="{% if next %}{{ next }}{% else %}{% url 'p4l_home' %}{% endif %}" />
+ <div class="form-group">
+ <label class="col-lg-2 control-label" for="id_username">{% trans 'Username' %} :</label>
+ <div class="col-lg-10">
+ <input id="id_username" type="text" name="username" maxlength="254" class="form-control" placeholder="{% trans 'Username' %}" required="required">
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="col-lg-2 control-label" for="id_password">{% trans 'Password' %} :</label>
+ <div class="col-lg-10">
+ <input id="id_password" type="password" name="password" class="form-control" placeholder="{% trans 'Password' %}" required="required">
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-lg-offset-2 col-lg-10">
+ <button type="submit" class="btn btn-default">{% trans "login" %}</button>
+ </div>
+ </div>
+ </form>
+{% endblock %}
--- a/src/p4l/urls.py Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/urls.py Wed Sep 04 10:02:22 2013 +0200
@@ -1,12 +1,13 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
+from django.contrib.auth import urls as auth_urls
from p4l.views import RecordListView, RecordDetailView, RecordEditView
admin.autodiscover()
urlpatterns = patterns('',
- # Examples:
url(r'^$', RecordListView.as_view(), name='p4l_home'),
+ url(r'^auth/', include(auth_urls)),
url(r'^record/view$', RecordDetailView.as_view(), name='p4l_record_view'),
url(r'^record/edit/(?P<id>\w+)$', RecordEditView.as_view(), name='p4l_record_edit'),
url(r'^api/', include('p4l.api.urls')),
--- a/src/p4l/utils.py Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/utils.py Wed Sep 04 10:02:22 2013 +0200
@@ -56,7 +56,7 @@
WHERE {
?uri skos:inScheme <%s> .
?uri skos:prefLabel|skos:label ?label .
- FILTER (?uri = $root)
+ FILTER (%s)
}
"""
query_with_acronym = """
@@ -69,7 +69,7 @@
?uri skos:inScheme <%s> .
?uri skos:prefLabel|skos:label ?label .
OPTIONAL { ?uri skos:altLabel ?acro }
- FILTER (?uri = $root)
+ FILTER (%s)
}
"""
if acronyms:
@@ -77,40 +77,45 @@
else:
query = query_without_acronym
res_dict = {}
- for uri in uri_list:
+ # We build the filter string
+ filter_str = ""
+ for i,uri in enumerate(uri_list):
res_dict[uri] = ""
- res = requests.get(
- settings.SPARQL_QUERY_ENDPOINT,
- params={'query':query % scheme_uri, 'timeout':10, '$root' : "<"+uri+">"},
- headers={'accept':'application/sparql-results+json'},
- )
- if not res.ok:
- continue
- elif res.text:
- json_res = res.json()
- if 'results' in json_res and 'bindings' in json_res['results'] and len(json_res['results']['bindings'])>0:
- # json_res['results']['bindings'] has several languages. If we find french, we save the french label.
- # If not, we save the first one.
- tmp_dict = {}
- first_label = None
- # We create a temporary dict with the lang code and the label
- for b in json_res['results']['bindings']:
- if lang:
- if 'label' in b and 'value' in b['label'] and 'xml:lang' in b['label']:
- tmp_dict[b['label']['xml:lang']] = b['label']['value']
- if not first_label:
- first_label = b['label']['value']
+ if i==0:
+ filter_str = "?uri = <" + uri + ">"
+ else:
+ filter_str += " || ?uri = <" + uri + ">"
+ # We request the labels
+ res = requests.get(
+ settings.SPARQL_QUERY_ENDPOINT,
+ params={'query':query % (scheme_uri, filter_str), 'timeout':10},#, '$root' : "<"+uri+">"},
+ headers={'accept':'application/sparql-results+json'},
+ )
+ if res.ok and res.text:
+ json_res = res.json()
+ if 'results' in json_res and 'bindings' in json_res['results'] and len(json_res['results']['bindings'])>0:
+ # json_res['results']['bindings'] has several languages. If we find french, we save the french label.
+ # If not, we save the first one.
+ tmp_dict = {}
+ first_label = None
+ # We create a temporary dict with the lang code and the label
+ for b in json_res['results']['bindings']:
+ if lang:
+ if 'label' in b and 'value' in b['label'] and 'xml:lang' in b['label']:
+ tmp_dict[b['label']['xml:lang']] = b['label']['value']
+ if not first_label:
+ first_label = b['label']['value']
+ else:
+ if 'acro' in b and 'value' in b['acro']:
+ first_label = b['acro']['value'] + " : " + b['label']['value']
else:
- if 'acro' in b and 'value' in b['acro']:
- first_label = b['acro']['value'] + " : " + b['label']['value']
- else:
- first_label = b['label']['value']
+ first_label = b['label']['value']
if lang in tmp_dict or first_label:
if lang in tmp_dict:
label = tmp_dict[lang]
else:
label = first_label
- res_dict[uri] = label
+ res_dict[b['uri']['value']] = label
return res_dict
--- a/src/p4l/views.py Wed Sep 04 10:01:38 2013 +0200
+++ b/src/p4l/views.py Wed Sep 04 10:02:22 2013 +0200
@@ -6,7 +6,9 @@
'''
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, UpdateView
from p4l.forms import RecordFilterForm
from p4l.models import Record
@@ -23,6 +25,9 @@
template_name = "p4l/p4l_home.html"
form_class = RecordFilterForm
+ @method_decorator(login_required)
+ def dispatch(self, *args, **kwargs):
+ return super(RecordListView, self).dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
context = ListView.get_context_data(self, **kwargs)
@@ -49,6 +54,10 @@
template_name = "p4l/p4l_record_view.html"
slug_field = "uri" # Even if it is useless because we override get_objet
+ @method_decorator(login_required)
+ def dispatch(self, *args, **kwargs):
+ return super(RecordDetailView, self).dispatch(*args, **kwargs)
+
def get_object(self, queryset=None):
if "uri" not in self.request.GET:
raise AttributeError(u"Record view must be called uri GET parameter")
@@ -109,7 +118,7 @@
# http_method_names = ['get']
# template_name = 'record_update_form.html'
-class RecordEditView(View):
+class RecordEditView(UpdateView):
model = Record
template_name_suffix = '_update_form'
slug_field = "identifier"