Commit 4ca106d9 authored by eric's avatar eric
Browse files

Allow to multiple authors and alphabetised authors.

Using the natural_join template tag,

    Authors: Royer, Élodie
    Authors: Gourmel, Yoann

Renders as:

    Yoann Gourmel & Élodie Royer

(sorting in django templates: http://blog.ionelmc.ro/2013/10/26/django-dictsort-template-tag/ )
parent 0c81c271
......@@ -45,18 +45,26 @@ We then use python to construct a list that is easy to use in a template, someth
[
{
"date": "2012-06-02T00:00:00",
"title": "The Play/ザ・プレイ",
"href": "http://127.0.0.1:8000/r/06_Elodie_Royer_Yoann_Gourmel_The_Play_FR.md",
"license": "http://creativecommons.org/licenses/by-nd/3.0/fr/",
"author": "Élodie Royer et Yoann Gourmel"
"language": "fr",
"author": "Mayer, Bernadette",
"title": "Utopia",
"href": "http://127.0.0.1:8000/r/B_Bernadette-Mayer_Utopia_FR.md",
"authors": [
"Mayer, Bernadette"
],
"date": "2014-10-10T00:00:00"
},
{
"date": "2014-10-02T00:00:00",
"href": "http://127.0.0.1:8000/r/B_Bernadette-Mayer_Utopia_FR.md",
"author": "Bernadette Mayer",
"license": "",
"title": "Utopia"
"license": "http://creativecommons.org/licenses/by-nd/3.0/fr/",
"language": "fr",
"author": "Gourmel, Yoann",
"title": "The Play/ザ・プレイ",
"href": "http://127.0.0.1:8000/r/06_Elodie_Royer_Yoann_Gourmel_The_Play_FR.md",
"authors": [
"Royer, Élodie",
"Gourmel, Yoann"
],
"date": "2012-06-10T00:00:00"
}
]
......@@ -101,8 +109,13 @@ def query_results_to_template_articles(query_results):
current_uri = uri
if key in short_names:
new_key = short_names[key]
article[new_key] = value
if key == "http://purl.org/dc/terms/creator":
if 'authors' not in article:
article['authors'] = []
article['authors'].append(value)
else:
new_key = short_names[key]
article[new_key] = value
template_articles.append(article)
......
......@@ -17,7 +17,7 @@
{% block content %}
<ul>{% for article in articles %}
<li class="{{ article.language }}">{{ article.author }} <a href="{{ article.href }}">{{ article.title }}</a></li>
<li class="{{ article.language }}">{{ article.authors|dictsort:"lower"|natural_join:'&' }} <a href="{{ article.href }}">{{ article.title }}</a></li>
{% endfor %}</ul>
{% endblock %}
......
......@@ -4,7 +4,7 @@
{% block title %}
<header>
{% if meta.authors %}
<p class="authors" property="dc:creator">{{ meta.authors|natural_join:'et' }}</p>
<p class="authors">{{ meta.authors|dictsort:"lower"|natural_join:'&' }}</p>
{% endif %}
<h1>
{% ifequal pad.display_name|slugify "00md" %}
......@@ -22,7 +22,9 @@
{% block head_meta %}{% if meta %}
{% if meta.title %}<meta property="dc:title" content="{{ meta.title|natural_join:'et' }}" />{% endif %}
{% if meta.authors %}{% for author in meta.authors %}<meta property="dc:creator" content="{{ author }}" />
{% endfor %}{% endif %}
{% if meta.title %}<meta property="dc:title" content="{{ meta.title.0 }}" />{% endif %}
{% if meta.language %}{% for language in meta.language %}<meta property="dc:language" content="{{ language|lower }}" />{% endfor %}{% endif %}
......
......@@ -7,6 +7,18 @@ from django.utils.safestring import mark_safe
register = template.Library()
def un_alphabetise(name):
"""
>>> un_alphabetise("Turkle, Sherry")
"Sherry Turkle"
>>> un_alphabetise("Sherry Turkle")
"Sherry Turkle"
"""
try:
name, prefix = name.split(',')
return prefix.strip() + ' ' + name.strip()
except ValueError:
return name
@register.filter
def natural_join(val, cjn="and"):
......@@ -34,7 +46,7 @@ def natural_join(val, cjn="and"):
except AttributeError:
return repr(object)
val = [to_string(object) for object in val]
val = [un_alphabetise(to_string(object)) for object in val]
return " ".join((", ".join(val[0:-1]), "%s %s" % (cjn, val[-1]))) if len(val) > 1 else val[0]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment