.item_visualization select { width: 200px; }
.item_visualization img { width: 300px; border: solid 1px black; }
+/* Geographic navigator */
+ul.continents, ul.continents ul { list-style: none; margin: 0; padding: 0;}
+ul.continents { margin: 1em 1em; }
+ul.continents ul {margin-left: 0; margin-bottom: 0.9em; padding: 0 1em 1em 0;}
+ul.continents li.name { width: 480px; float: left;}
+ul.continents li.name b { font-size: 120%; font-weight: bold; }
+ul.continents ul li { display: inline; padding-right: 1ex;}
+
/* Styles for tabular listings (stolen from trac) */
table.listing {
clear: both;
Q(creator__icontains=pattern)
)
+ def by_country(self, country):
+ qs = super(MediaCollectionManager, self).get_query_set()
+ return qs.extra(where = ["id IN (SELECT collection_id "
+ "FROM telemeta_item WHERE etat = %s)"],
+ params=[country]);
+
+ def stat_continents(self):
+ from django.db import connection
+ cursor = connection.cursor()
+ cursor.execute("SELECT continent, etat, count(*) AS items_num "
+ "FROM telemeta_collection INNER JOIN telemeta_item "
+ "ON telemeta_collection.id = telemeta_item.collection_id "
+ "WHERE (continent IN "
+ " ('EUROPE', 'OCEANIE', 'ASIE', 'AMERIQUE', 'AFRIQUE')) "
+ "AND etat <> '' "
+ "GROUP BY etat ORDER BY continent, items_num desc;")
+ result_set = cursor.fetchall()
+ stat = {}
+ for continent, country, count in result_set:
+ if stat.has_key(continent):
+ stat[continent].append({'name':country, 'count':count})
+ else:
+ stat[continent] = [{'name':country, 'count':count}]
+
+ keys = stat.keys()
+ keys.sort()
+ ordered = [{'name': k, 'countries': stat[k]} for k in keys]
+ return ordered
+
+
class MediaCollection(models.Model, MediaCore):
"Group related media items"
dc.Element('title', 'title', self.title),
dc.Element('creator', value=creator),
dc.Element('publisher', value=self.collection.publisher),
+ dc.Element('coverage', value=self.etat),
)
return resource
</div>
<div id="menu">
-<a href="{% url telemeta-collections %}">Collections</a> |
-<a href="{% url telemeta-items %}">Items</a> |
+<a href="{% url telemeta-geo-continents %}">Geo Navigator</a> |
+<a href="{% url telemeta-collections %}">All Collections</a> |
+<a href="{% url telemeta-items %}">All Items</a> |
<a href="{% url telemeta-admin %}">Admin</a>
</div>
</div>
{% extends "base.html" %}
{% load telemeta_utils %}
+
{% block content %}
<h3>Collections</h3>
-{% if object_list %}
- <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
-
- {% if has_previous %} <a href="?page={{ previous }}"><<</a> {% endif %}
- {% if has_next %} <a href="?page={{ next }}">>></a> {% endif %}
- </p>
- <ul>
- {% for p in object_list %}
- <li><a href="{% url telemeta-collection-detail p.id|urlencode %}">{{ p.title }}</a>
- </li>
- {% endfor %}
- </ul>
-{% else %}
- <p>No pieces are available.</p>
-{% endif %}
+
+{% with object_list as collections %}
+{% include "inc/collection_list.html" %}
+{% endwith %}
+
{% endblock %}
--- /dev/null
+{% extends "base.html" %}
+{% load telemeta_utils %}
+
+{% block content %}
+<h3>Geographic Navigator</h3>
+{% if continents %}
+<ul class="continents">
+{% for continent in continents %}
+ <li class="name"><b><a href="{% url telemeta-geo-countries continent.name|urlencode %}">{{ continent.name }}</a></b>
+ <ul>
+ {% for country in continent.countries|slice:":10" %}
+ <li class="country_name">
+ <a href="{% url telemeta-geo-country-collections continent.name,country.name|urlencode %}">
+ {{ country.name|lower|capfirst }}</a></li>
+ {% endfor %}
+ {% if continent.countries.10 %}
+ <li><a href="{% url telemeta-geo-countries continent.name|urlencode %}">More..</a></li>
+ {% endif %}
+ </ul>
+ </li>
+{% endfor %}
+</ul>
+{% else %}
+<p>No data</p>
+{% endif %}
+{% endblock %}
--- /dev/null
+{% extends "base.html" %}
+{% load telemeta_utils %}
+
+{% block content %}
+<h3><a href="{% url telemeta-geo-continents %}">WORLD</a> /
+ {{ continent.name }}</h3>
+<ul>
+{% for country in continent.countries %}
+ <li><a href="{% url telemeta-geo-country-collections continent.name,country.name|urlencode %}">
+ {{ country.name|lower|capfirst }} ({{ country.count }})</a></li>
+{% endfor %}
+</ul>
+{% endblock %}
--- /dev/null
+{% extends "base.html" %}
+{% load telemeta_utils %}
+
+{% block content %}
+<h3><a href="{% url telemeta-geo-continents %}">WORLD</a> /
+ <a href="{% url telemeta-geo-countries continent|urlencode %}">{{ continent }}</a>
+ / {{ country }}</h3>
+
+{% with object_list as collections %}
+{% include "inc/collection_list.html" %}
+{% endwith %}
+
+{% endblock %}
--- /dev/null
+{% if collections %}
+ {% if hits %}
+ <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
+
+ {% if has_previous %} <a href="?page={{ previous }}"><<</a> {% endif %}
+ {% if has_next %} <a href="?page={{ next }}">>></a> {% endif %}
+ </p>
+ {% endif %}
+ <ul>
+ {% for p in collections %}
+ <li><a href="{% url telemeta-collection-detail p.id|urlencode %}">{{ p.title }}</a>
+ </li>
+ {% endfor %}
+ </ul>
+{% else %}
+ <p>No collection</p>
+{% endif %}
--- /dev/null
+{% if items %}
+ {% if hits %}
+ <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
+
+ {% if has_previous %} <a href="?page={{ previous }}"><<</a> {% endif %}
+ {% if has_next %} <a href="?page={{ next }}">>></a> {% endif %}
+ </p>
+ {% endif %}
+ <ul>
+ {% for p in items %}
+ <li><a href="{% url telemeta-item-detail p.id %}">{{ p.title }}</a></li>
+ {% endfor %}
+ </ul>
+{% else %}
+ <p>No piece</p>
+{% endif %}
{% block content %}
<h3>Media items</h3>
-{% if object_list %}
- <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
-
- {% if has_previous %} <a href="?page={{ previous }}"><<</a> {% endif %}
- {% if has_next %} <a href="?page={{ next }}">>></a> {% endif %}
- </p>
- <ul>
- {% for p in object_list %}
- <li><a href="{% url telemeta-item-detail p.id %}">{{ p.title }}</a></li>
- {% endfor %}
- </ul>
-{% else %}
- <p>No pieces are available.</p>
-{% endif %}
+{% with object_list as items %}
+{% include "inc/mediaitem_list.html" %}
+{% endwith %}
{% endblock %}
<h3>Search: {{ pattern }}</h3>
{% if collections %}
<h4>Collections</h4>
- <table class="resources-list">
- {% for c in collections %}
- <tr>
- <td>
- <a href="{% url telemeta-collection-detail c.id %}">
- {{ c.title }}
- </a>
- </td>
- <td>
- [{{c.id}}]
- </td>
- </tr>
- {% endfor %}
- </table>
- </ul>
+ {% include "inc/collection_list.html" %}
{% endif %}
{% if items %}
<h4>Items</h4>
- <ul>
- {% for i in items %}
- <li><b>{{ i.title }}</b>
- <a href="{% url telemeta-item-detail i.id %}">View</a>
- <a href="#">Edit</a>
- </li>
- {% endfor %}
- </ul>
+ {% include "inc/mediaitem_list.html" %}
{% endif %}
{% if not collections and not items %}
No result
web_view.update_enumeration_value,
name="telemeta-enumeration-record-update"),
+ # Geographic browsing
+ url(r'geo/$', web_view.list_continents, name="telemeta-geo-continents"),
+ url(r'geo/(?P<continent>[A-Za-z]+)/$', web_view.list_countries,
+ name="telemeta-geo-countries"),
+ url('geo/(?P<continent>[A-Za-z]+)/(?P<country>[-A-Za-z0-9%;.,"& \']+)/$',
+ web_view.list_country_collections,
+ name="telemeta-geo-country-collections"),
+
# CSS+Images (FIXME: for developement only)
(r'^css/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': './telemeta/htdocs/css'}),
#
# Author: Olivier Guilyardi <olivier@samalyse.com>
-import telemeta
+import re
+import os
+
from django.template import Context, loader
from django import template
from django.http import HttpResponse
from django.http import Http404
+from django.shortcuts import render_to_response
+from django.views.generic import list_detail
+from django.conf import settings
+
+import telemeta
from telemeta.models import MediaItem
from telemeta.models import MediaCollection
-from django.shortcuts import render_to_response
-import re
from telemeta.core import *
from telemeta.export import *
from telemeta.visualization import *
-from django.conf import settings
-import os
class WebView(Component):
"""Provide web UI methods"""
context = Context({'item': item, 'host': request.META['HTTP_HOST']})
return HttpResponse(template.render(context), mimetype=mimetype)
+ def list_continents(self, request):
+ continents = MediaCollection.objects.stat_continents()
+ return render_to_response('geo_continents.html',
+ {'continents': continents })
+
+ def list_countries(self, request, continent):
+ continents = MediaCollection.objects.stat_continents()
+ for c in continents:
+ if c["name"] == continent:
+ break
+ if c["name"] != continent:
+ raise Http404
+
+ return render_to_response('geo_countries.html', {'continent': c })
+
+ def list_country_collections(self, request, continent, country):
+ objects = MediaCollection.objects.by_country(country)
+ return list_detail.object_list(request, objects,
+ template_name='geo_country_collections.html', paginate_by=20,
+ extra_context={'country': country, 'continent': continent})
+
+
+