]> git.parisson.com Git - telemeta.git/commitdiff
add geographic navigator, coverage dc mapping to collection + other fixes
authorolivier <>
Sun, 20 May 2007 14:12:24 +0000 (14:12 +0000)
committerolivier <>
Sun, 20 May 2007 14:12:24 +0000 (14:12 +0000)
13 files changed:
telemeta/htdocs/css/telemeta.css
telemeta/models.py
telemeta/templates/base.html
telemeta/templates/collection_list.html
telemeta/templates/geo_continents.html [new file with mode: 0644]
telemeta/templates/geo_countries.html [new file with mode: 0644]
telemeta/templates/geo_country_collections.html [new file with mode: 0644]
telemeta/templates/inc/collection_list.html [new file with mode: 0644]
telemeta/templates/inc/mediaitem_list.html [new file with mode: 0644]
telemeta/templates/mediaitem_list.html
telemeta/templates/search_results.html
telemeta/urls.py
telemeta/views/web.py

index caaaad4e3c504c215a9120f6e1edd4a4a72301b1..8c46e471dadc6740c30056958793615228d5176f 100644 (file)
@@ -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;
index 689dde5bcd09051439749a75dde662160a99ae44..661628b0a62b42cf100f0b9fe2b3590326678f6e 100644 (file)
@@ -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
 
index 0fb1e10e04fadbffcadfc40fec1bdcfe26defb80..7acd536b0b7308f5ccc55fd9060adbd67dd0fe42 100644 (file)
@@ -26,8 +26,9 @@
 </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>
index e02ad1dc8450f396218ccefa014f0a5a995fbacb..6d975df444e83112a6ea28cb379cf48b13825e9d 100644 (file)
@@ -1,20 +1,11 @@
 {% 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 }} 
-    &nbsp;&nbsp;
-    {% if has_previous %} <a href="?page={{ previous }}">&lt;&lt;</a> {% endif %}
-    {% if has_next %} <a href="?page={{ next }}">&gt;&gt;</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 %}
diff --git a/telemeta/templates/geo_continents.html b/telemeta/templates/geo_continents.html
new file mode 100644 (file)
index 0000000..d59e9fa
--- /dev/null
@@ -0,0 +1,26 @@
+{% 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 %}
diff --git a/telemeta/templates/geo_countries.html b/telemeta/templates/geo_countries.html
new file mode 100644 (file)
index 0000000..b7f90a0
--- /dev/null
@@ -0,0 +1,13 @@
+{% 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 %}
diff --git a/telemeta/templates/geo_country_collections.html b/telemeta/templates/geo_country_collections.html
new file mode 100644 (file)
index 0000000..2fc474c
--- /dev/null
@@ -0,0 +1,13 @@
+{% 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 %}
diff --git a/telemeta/templates/inc/collection_list.html b/telemeta/templates/inc/collection_list.html
new file mode 100644 (file)
index 0000000..5a41864
--- /dev/null
@@ -0,0 +1,17 @@
+{% if collections %}
+    {% if hits %}
+    <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
+    &nbsp;&nbsp;
+    {% if has_previous %} <a href="?page={{ previous }}">&lt;&lt;</a> {% endif %}
+    {% if has_next %} <a href="?page={{ next }}">&gt;&gt;</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 %}
diff --git a/telemeta/templates/inc/mediaitem_list.html b/telemeta/templates/inc/mediaitem_list.html
new file mode 100644 (file)
index 0000000..a74c854
--- /dev/null
@@ -0,0 +1,16 @@
+{% if items %}
+    {% if hits %}
+    <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
+    &nbsp;&nbsp;
+    {% if has_previous %} <a href="?page={{ previous }}">&lt;&lt;</a> {% endif %}
+    {% if has_next %} <a href="?page={{ next }}">&gt;&gt;</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 %}
index b05227715049ce347ff919c373bf6c206ed1d27d..d94e3e9661fe6b66eb0561278f56238bae81bef9 100644 (file)
@@ -2,18 +2,7 @@
 
 {% block content %}
 <h3>Media items</h3>
-{% if object_list %}
-    <p>Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
-    &nbsp;&nbsp;
-    {% if has_previous %} <a href="?page={{ previous }}">&lt;&lt;</a> {% endif %}
-    {% if has_next %} <a href="?page={{ next }}">&gt;&gt;</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 %}
index e0aba8bb55919cad96c278abcb5ece0f62393912..45bbe1824d94617e8c68c8a315058a6763aeafd2 100644 (file)
@@ -4,32 +4,11 @@
 <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
index c22bf1facb89266a87f57ca81d3aaa901b9bd7c6..f34442414b2f37a9062b710c5779eda5184755ec 100644 (file)
@@ -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<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'}),
index a59cf9128be560e02bc461b8b41fed575a93a754..f22425f23c7c3eec2705aa712c80fc79a35d8fdc 100644 (file)
@@ -7,20 +7,23 @@
 #
 # 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"""
@@ -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})
+
+        
+