From 294e691e6fe3ee67d7206fb7375fc8e7fcf0bc91 Mon Sep 17 00:00:00 2001 From: olivier <> Date: Sun, 20 May 2007 14:12:24 +0000 Subject: [PATCH] add geographic navigator, coverage dc mapping to collection + other fixes --- telemeta/htdocs/css/telemeta.css | 8 +++++ telemeta/models.py | 31 ++++++++++++++++ telemeta/templates/base.html | 5 +-- telemeta/templates/collection_list.html | 21 ++++------- telemeta/templates/geo_continents.html | 26 ++++++++++++++ telemeta/templates/geo_countries.html | 13 +++++++ .../templates/geo_country_collections.html | 13 +++++++ telemeta/templates/inc/collection_list.html | 17 +++++++++ telemeta/templates/inc/mediaitem_list.html | 16 +++++++++ telemeta/templates/mediaitem_list.html | 17 ++------- telemeta/templates/search_results.html | 25 ++----------- telemeta/urls.py | 8 +++++ telemeta/views/web.py | 36 ++++++++++++++++--- 13 files changed, 177 insertions(+), 59 deletions(-) create mode 100644 telemeta/templates/geo_continents.html create mode 100644 telemeta/templates/geo_countries.html create mode 100644 telemeta/templates/geo_country_collections.html create mode 100644 telemeta/templates/inc/collection_list.html create mode 100644 telemeta/templates/inc/mediaitem_list.html diff --git a/telemeta/htdocs/css/telemeta.css b/telemeta/htdocs/css/telemeta.css index caaaad4e..8c46e471 100644 --- a/telemeta/htdocs/css/telemeta.css +++ b/telemeta/htdocs/css/telemeta.css @@ -46,6 +46,14 @@ a img { border: none; } .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; diff --git a/telemeta/models.py b/telemeta/models.py index 689dde5b..661628b0 100644 --- a/telemeta/models.py +++ b/telemeta/models.py @@ -56,6 +56,36 @@ class MediaCollectionManager(models.Manager): 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" @@ -221,6 +251,7 @@ class MediaItem(models.Model, MediaCore): 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 diff --git a/telemeta/templates/base.html b/telemeta/templates/base.html index 0fb1e10e..7acd536b 100644 --- a/telemeta/templates/base.html +++ b/telemeta/templates/base.html @@ -26,8 +26,9 @@ diff --git a/telemeta/templates/collection_list.html b/telemeta/templates/collection_list.html index e02ad1dc..6d975df4 100644 --- a/telemeta/templates/collection_list.html +++ b/telemeta/templates/collection_list.html @@ -1,20 +1,11 @@ {% extends "base.html" %} {% load telemeta_utils %} + {% block content %}

Collections

-{% if object_list %} -

Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} -    - {% if has_previous %} << {% endif %} - {% if has_next %} >> {% endif %} -

- -{% else %} -

No pieces are available.

-{% endif %} + +{% with object_list as collections %} +{% include "inc/collection_list.html" %} +{% endwith %} + {% endblock %} diff --git a/telemeta/templates/geo_continents.html b/telemeta/templates/geo_continents.html new file mode 100644 index 00000000..d59e9faa --- /dev/null +++ b/telemeta/templates/geo_continents.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% load telemeta_utils %} + +{% block content %} +

Geographic Navigator

+{% if continents %} + +{% else %} +

No data

+{% endif %} +{% endblock %} diff --git a/telemeta/templates/geo_countries.html b/telemeta/templates/geo_countries.html new file mode 100644 index 00000000..b7f90a04 --- /dev/null +++ b/telemeta/templates/geo_countries.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} +{% load telemeta_utils %} + +{% block content %} +

WORLD / + {{ continent.name }}

+ +{% endblock %} diff --git a/telemeta/templates/geo_country_collections.html b/telemeta/templates/geo_country_collections.html new file mode 100644 index 00000000..2fc474c2 --- /dev/null +++ b/telemeta/templates/geo_country_collections.html @@ -0,0 +1,13 @@ +{% extends "base.html" %} +{% load telemeta_utils %} + +{% block content %} +

WORLD / + {{ continent }} + / {{ country }}

+ +{% with object_list as collections %} +{% include "inc/collection_list.html" %} +{% endwith %} + +{% endblock %} diff --git a/telemeta/templates/inc/collection_list.html b/telemeta/templates/inc/collection_list.html new file mode 100644 index 00000000..5a41864d --- /dev/null +++ b/telemeta/templates/inc/collection_list.html @@ -0,0 +1,17 @@ +{% if collections %} + {% if hits %} +

Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} +    + {% if has_previous %} << {% endif %} + {% if has_next %} >> {% endif %} +

+ {% endif %} + +{% else %} +

No collection

+{% endif %} diff --git a/telemeta/templates/inc/mediaitem_list.html b/telemeta/templates/inc/mediaitem_list.html new file mode 100644 index 00000000..a74c8543 --- /dev/null +++ b/telemeta/templates/inc/mediaitem_list.html @@ -0,0 +1,16 @@ +{% if items %} + {% if hits %} +

Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} +    + {% if has_previous %} << {% endif %} + {% if has_next %} >> {% endif %} +

+ {% endif %} + +{% else %} +

No piece

+{% endif %} diff --git a/telemeta/templates/mediaitem_list.html b/telemeta/templates/mediaitem_list.html index b0522771..d94e3e96 100644 --- a/telemeta/templates/mediaitem_list.html +++ b/telemeta/templates/mediaitem_list.html @@ -2,18 +2,7 @@ {% block content %}

Media items

-{% if object_list %} -

Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} -    - {% if has_previous %} << {% endif %} - {% if has_next %} >> {% endif %} -

- -{% else %} -

No pieces are available.

-{% endif %} +{% with object_list as items %} +{% include "inc/mediaitem_list.html" %} +{% endwith %} {% endblock %} diff --git a/telemeta/templates/search_results.html b/telemeta/templates/search_results.html index e0aba8bb..45bbe182 100644 --- a/telemeta/templates/search_results.html +++ b/telemeta/templates/search_results.html @@ -4,32 +4,11 @@

Search: {{ pattern }}

{% if collections %}

Collections

- - {% for c in collections %} - - - - - {% endfor %} -
- - {{ c.title }} - - - [{{c.id}}] -
- + {% include "inc/collection_list.html" %} {% endif %} {% if items %}

Items

- + {% include "inc/mediaitem_list.html" %} {% endif %} {% if not collections and not items %} No result diff --git a/telemeta/urls.py b/telemeta/urls.py index c22bf1fa..f3444241 100644 --- a/telemeta/urls.py +++ b/telemeta/urls.py @@ -100,6 +100,14 @@ urlpatterns = patterns('', 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[A-Za-z]+)/$', web_view.list_countries, + name="telemeta-geo-countries"), + url('geo/(?P[A-Za-z]+)/(?P[-A-Za-z0-9%;.,"& \']+)/$', + web_view.list_country_collections, + name="telemeta-geo-country-collections"), + # CSS+Images (FIXME: for developement only) (r'^css/(?P.*)$', 'django.views.static.serve', {'document_root': './telemeta/htdocs/css'}), diff --git a/telemeta/views/web.py b/telemeta/views/web.py index a59cf912..f22425f2 100644 --- a/telemeta/views/web.py +++ b/telemeta/views/web.py @@ -7,20 +7,23 @@ # # Author: Olivier Guilyardi -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""" @@ -209,6 +212,29 @@ class WebView(Component): 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}) + + + -- 2.39.5