]> git.parisson.com Git - telemeta.git/commitdiff
show items and collections lists as tables
authorolivier <>
Tue, 9 Feb 2010 17:40:52 +0000 (17:40 +0000)
committerolivier <>
Tue, 9 Feb 2010 17:40:52 +0000 (17:40 +0000)
19 files changed:
telemeta/htdocs/css/telemeta.css
telemeta/htdocs/js/application.js
telemeta/htdocs/js/resourcemap.js
telemeta/locale/fr/LC_MESSAGES/django.po
telemeta/models/crem.py
telemeta/models/cremquery.py
telemeta/templates/telemeta_default/base.html
telemeta/templates/telemeta_default/collection_detail.html
telemeta/templates/telemeta_default/collection_list.html
telemeta/templates/telemeta_default/country_info.html
telemeta/templates/telemeta_default/geo_country_collections.html
telemeta/templates/telemeta_default/geo_country_items.html
telemeta/templates/telemeta_default/inc/collection_list.html
telemeta/templates/telemeta_default/inc/mediaitem_list.html
telemeta/templates/telemeta_default/mediaitem_detail.html
telemeta/templates/telemeta_default/mediaitem_list.html
telemeta/templatetags/telemeta_utils.py
telemeta/urls.py
telemeta/web/base.py

index 48f155422e98ab78e327a8584f6f39bf93d35ac1..a77ee55cb9c759b627e7872b767408a1568968aa 100644 (file)
@@ -520,7 +520,6 @@ dl.dublincore dd.caption {
     margin-top: .7em;\r
     margin-bottom: .3em;\r
     padding: .3em 0;\r
-    float: left;\r
     font-size: .9em;\r
     background-color: #fff;\r
     border-bottom: 1px solid #aaa;\r
@@ -563,8 +562,12 @@ table.instruments tbody td {
 table.listing {\r
     clear: both;\r
     border-spacing: 0;\r
+}\r
+\r
+.fullpage table.listing {\r
     width: 100%;\r
 }\r
+\r
 table.listing th {\r
     text-align: left;\r
     padding: 0 14em .1em 0;\r
@@ -611,3 +614,5 @@ table.listing tbody tr { border-top: 1px solid #ddd }
 table.listing tbody tr.even { background-color: #fcfcfc }\r
 table.listing tbody tr.odd { background-color: #f7f7f7 }\r
 table.listing tbody tr:hover { background: #f7f8fa !important }\r
+\r
+\r
index 22e5fffe321dc00c9ac62fb82d692611412b4e75..f94f4cd8c914177a5916149b8d51a4536a5cc426 100644 (file)
@@ -8,5 +8,7 @@ function foldInfoBlocks() {
     });\r
 }\r
 \r
-$(document).ready(foldInfoBlocks);\r
+$(document).ready(function() {\r
+    foldInfoBlocks();\r
+});\r
 \r
index 0fcd16a52105bcbbd3f935d914e02b9d95a33a61..b3fbdfda974cff46444a75793abbd841917030eb 100644 (file)
@@ -76,6 +76,7 @@ function ResourceMap(list, cfg) {
         
         $.get(uri, function(data) {
             info.html(data);
+            //marker.openInfoWindowHtml(info.get(0));
         });
     }
 
index 7e0c28f317628a3af41ee83bb1930c1887e788c5..d7f681b859117cf681037470a8444e91be76b3f7 100644 (file)
@@ -205,8 +205,8 @@ msgid "location"
 msgstr "lieu"
 
 #: models/crem.py:296
-msgid "location comment"
-msgstr "commentaire lieu"
+msgid "location details"
+msgstr "prĂ©cisions lieu"
 
 #: models/crem.py:298 models/crem.py:710
 msgid "population / social group"
index 4c75f2a23372d49dd3747f8fd49cd7c98e5dab20..e80d8a0e02509c8bd3e35234ea8e8b8f72ba142c 100755 (executable)
@@ -160,8 +160,8 @@ class MediaCollection(MediaResource):
     creator               = CharField(_('depositor / contributor'))
     booklet_author        = CharField(_('author of published notice'))
     booklet_description   = TextField(_('related documentation'))
-    collector             = CharField(_('collector'))
-    collector_is_creator  = BooleanField(_('collector identical to depositor'))
+    collector             = CharField(_('recordist'))
+    collector_is_creator  = BooleanField(_('recordist identical to depositor'))
     publisher             = WeakForeignKey('Publisher', related_name="collections", 
                                            verbose_name=_('publisher / status'))     
     is_published          = BooleanField(_('published'))
@@ -293,7 +293,7 @@ class MediaItem(MediaResource):
     recorded_from_date    = DateField(_('recording date (from)'))
     recorded_to_date      = DateField(_('recording date (until)'))
     location              = WeakForeignKey('Location', verbose_name=_('location'))
-    location_comment      = CharField(_('location comment'))
+    location_comment      = CharField(_('location details'))
     ethnic_group          = WeakForeignKey('EthnicGroup', related_name="items", 
                                            verbose_name=_('population / social group'))
     title                 = CharField(_('title'), required=True)
@@ -305,11 +305,12 @@ class MediaItem(MediaResource):
     external_references   = TextField(_('published reference'))
     moda_execut           = CharField(_('moda_execut'))
     copied_from_item      = WeakForeignKey('self', related_name="copies", verbose_name=_('copy of'))
-    collector             = CharField(_('recorded by'))
+    collector             = CharField(_('recordist'))
+    collector_from_collection = BooleanField(_('recordist as in collection'))
     cultural_area         = CharField(_('cultural area'))
     generic_style         = WeakForeignKey('GenericStyle', related_name="items", 
                                            verbose_name=_('generic name'))
-    collector_selection   = CharField(_('collector selection'))
+    collector_selection   = CharField(_('recordist selection'))
     creator_reference     = CharField(_('reference'))
     comment               = TextField(_('comment'))
     file                  = FileField(_('file'), upload_to='items/%Y/%m/%d', db_column="filename")
index bb13949e95a9bc8f0605bbd91decc9ef771fdc78..1165d7ba4c58f77f40699b0b1bed202292ad64d3 100644 (file)
@@ -105,13 +105,9 @@ class MediaCollectionQuerySet(CoreQuerySet):
         )
 
     def by_location(self, location):
-        "Find collections by country"
+        "Find collections by location"
         return self.filter(Q(items__location=location) | Q(items__location__in=location.descendants())).distinct()
     
-    def by_continent(self, continent):
-        "Find collections by continent"
-        return self.filter(items__location__type="continent", items__location=continent).distinct()
-
     def by_recording_year(self, from_year, to_year=None):
         "Find collections by recording year"
         if to_year is None:
@@ -134,6 +130,17 @@ class MediaCollectionQuerySet(CoreQuerySet):
         "Find collections between two dates"
         return self._by_change_time('collection', from_time, until_time)
 
+    def virtual(self, *args):
+        qs = self
+        for f in args:
+            if f == 'apparent_collector':
+                qs = qs.extra(select={f: 'IF(media_collections.collector_is_creator, '
+                                         'media_collections.creator, media_collections.collector)'})
+            else:
+                raise Exception("Unsupported virtual field: %s" % f)
+
+        return qs                
+
 class MediaCollectionManager(CoreManager):
     "Manage collection queries"
 
@@ -141,6 +148,10 @@ class MediaCollectionManager(CoreManager):
         "Return the collection query"
         return MediaCollectionQuerySet(self.model)
 
+    def enriched(self):
+        "Query set with additional virtual fields such as apparent_collector"
+        return self.get_query_set().virtual('apparent_collector')
+
     def quick_search(self, *args, **kwargs):
         return self.get_query_set().quick_search(*args, **kwargs)
     quick_search.__doc__ = MediaCollectionQuerySet.quick_search.__doc__
@@ -149,10 +160,6 @@ class MediaCollectionManager(CoreManager):
         return self.get_query_set().by_location(*args, **kwargs)
     by_location.__doc__ = MediaCollectionQuerySet.by_location.__doc__
 
-    def by_continent(self, *args, **kwargs):
-        return self.get_query_set().by_continent(*args, **kwargs)
-    by_continent.__doc__ = MediaCollectionQuerySet.by_continent.__doc__
-
     def by_recording_year(self, *args, **kwargs):
         return self.get_query_set().by_recording_year(*args, **kwargs)
     by_recording_year.__doc__ = MediaCollectionQuerySet.by_recording_year.__doc__
@@ -286,6 +293,43 @@ class MediaItemQuerySet(CoreQuerySet):
             
         return countries                    
 
+    def virtual(self, *args):
+        qs = self
+        need_collection = False
+        related = []
+        for f in args:
+            if f == 'apparent_collector':
+                related.append('collection')
+                qs = qs.extra(select={f: 
+                    'IF(collector_from_collection, '
+                        'IF(media_collections.collector_is_creator, '
+                           'media_collections.creator, '
+                           'media_collections.collector),'
+                        'media_items.collector)'})
+            elif f == 'country_or_continent':
+                from telemeta.models import Location
+                related.append('location')
+                qs = qs.extra(select={f:
+                    'IF(locations.type = ' + str(Location.COUNTRY) + ' '
+                    'OR locations.type = ' + str(Location.CONTINENT) + ',' 
+                    'locations.name, '
+                    '(SELECT l2.name FROM location_relations AS r INNER JOIN locations AS l2 '
+                    'ON r.ancestor_location_id = l2.id '
+                    'WHERE r.location_id = media_items.location_id AND l2.type = ' + str(Location.COUNTRY) + ' ))'
+                })
+            else:
+                raise Exception("Unsupported virtual field: %s" % f)
+
+        if related:
+            qs = qs.select_related(*related)
+
+        return qs                
+
+    def ethnic_groups(self):
+        return self.filter(ethnic_group__isnull=False) \
+               .values_list('ethnic_group__name', flat=True) \
+               .distinct().order_by('ethnic_group__name')        
+
 class MediaItemManager(CoreManager):
     "Manage media items queries"
 
@@ -293,6 +337,10 @@ class MediaItemManager(CoreManager):
         "Return media query sets"
         return MediaItemQuerySet(self.model)
 
+    def enriched(self):
+        "Query set with additional virtual fields such as apparent_collector and country_or_continent"
+        return self.get_query_set().virtual('apparent_collector', 'country_or_continent')
+
     def quick_search(self, *args, **kwargs):
         return self.get_query_set().quick_search(*args, **kwargs)
     quick_search.__doc__ = MediaItemQuerySet.quick_search.__doc__
index 9685a7bc79db239a7aa7f8be992ed0fa3e558e1f..d2beb6c66610d1cc132433101f790610f5681f66 100644 (file)
@@ -12,6 +12,7 @@
 <![endif]-->
 {% endblock %}
 <script src="{% url telemeta-js "jquery.js" %}" type="text/javascript"></script>
+<script src="{% url telemeta-js "application.js" %}" type="text/javascript"></script>
 {% block extra_javascript %}{% endblock %}
 </head>
 {% load i18n %}
index 8e18a3e6ed560a967a6a7cbc58a061ca68a6b395..bf95a9f619d082dd1871929d8e2fa032c5297f35 100644 (file)
@@ -3,7 +3,6 @@
 {% load i18n %}\r
 \r
 {% block extra_javascript %}\r
-<script src="{% url telemeta-js "application.js" %}" type="text/javascript"></script>\r
 <script src="{% url telemeta-js "swfobject.js" %}" type="text/javascript"></script>\r
 {% endblock %}\r
 \r
         {% endblock technical_data %}\r
         </div>\r
         <h4>Items</h4>\r
-        {% with collection.items.all as items %}\r
+        {% with collection.items.enriched as items %}\r
             {% include "telemeta/inc/mediaitem_list.html" %}\r
         {% endwith %}\r
         <!--\r
index 35a21eda8d7d01bc0ad9541f149bf0960bbf9dff..b37aae1a710c0eb7b872de453f0be79ac691cc05 100644 (file)
@@ -5,7 +5,9 @@
 <h3>Collections</h3>
 
 {% with object_list as collections %}
+<div class="fullpage">
 {% include "telemeta/inc/collection_list.html" %}
+</div>
 {% endwith %}
 
 {% endblock %}
index feaf87e036edb93863d727f8ba2d1245f582ad62..0783deeab673e95f29e1fd06664c5ae6a8f29d3e 100644 (file)
@@ -2,6 +2,7 @@
 {% load i18n %}
 
 <h2>{{ country }}</h2>
+<p>
 <a href="{% url telemeta-geo-country-items continent.flatname,country.flatname %}">
 {{ country.items|resources_num }}
 </a>
@@ -9,3 +10,14 @@
 <a href="{% url telemeta-geo-country-collections continent.flatname,country.flatname %}">
 {{ country.collections|resources_num }}
 </a>
+</p>
+<!--
+{% with country.items.all.ethnic_groups as ethnic_groups %}
+{% if ethnic_groups %}
+<p>
+<b>{% trans "Populations / Social groups" %}:</b>
+{{ ethnic_groups|join:', ' }}
+</p>
+{% endif %}
+{% endwith %}
+-->
index 3eb96d175db3eef93d3c9b2c739b15e2a54384f1..16d985c86b7a389bca4fc4f4ed197d760a664aa1 100644 (file)
@@ -8,7 +8,9 @@
   / {{ country }}</h3>
 
 {% with object_list as collections %}
+<div class="fullpage">
 {% include "telemeta/inc/collection_list.html" %}
+</div>
 {% endwith %}
 
 {% endblock %}
index fae0887401a112b36ee20403f92310f677817c93..4f4f95a84b2fb53defe7638e21d31f27efd0f920 100644 (file)
@@ -8,7 +8,9 @@
   / {{ country }}</h3>
 
 {% with object_list as items %}
+<div class="fullpage">
 {% include "telemeta/inc/mediaitem_list.html" %}
+</div>
 {% endwith %}
 
 {% endblock %}
index 294036bd4ba68dcef3dcaebec1836ebd64c33f97..642ba3eb2a5d873021562d8200272307b96c44f6 100644 (file)
@@ -1,19 +1,30 @@
 {% load telemeta_utils %}
+{% load i18n %}
 {% if collections %}
-    {% if hits %}
-    <p class="pagination">Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
-    &nbsp;&nbsp;
-    {% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
-    {% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
-    </p>
-    {% endif %}
-    <ul>
-    {% for p in collections %}
-        <li><a href="{% url telemeta-collection-detail p.public_id %}">{{ p }}</a>
-            </li>
-    {% endfor %}
-    {% if more_collections %} <li>[...]</li> {% endif %}
-    </ul>
+{% if hits %}
+<p class="pagination">Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
+&nbsp;&nbsp;
+{% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
+{% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
+</p>
+{% endif %}
+<table class="listing">
+<tr>
+    <th class="highlight">{% trans "Title" %}</th>
+    <th>{% field_label "MediaCollection" "creator" %}</th>
+    <th>{% trans "Recordist" %}</th>
+</tr>
+{% for collection in collections %}
+<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
+    <td class="highlight">
+        <a href="{% url telemeta-collection-detail collection.public_id %}">{{ collection }}</a>
+    </td>
+    <td>{{ collection.creator }}</td>
+    <td>{{ collection.apparent_collector }}</td>
+</tr>
+{% endfor %}
+</table>
 {% else %}
-    <p>No collection</p>
+    <p>{% trans "No collection" %}</p>
 {% endif %}
+
index a7ab7d71cb032546c3611b32a4d9918b75696ce8..8d8f5a73d5cd8d8011a984d7ebe673d1a714e803 100644 (file)
@@ -1,18 +1,30 @@
 {% load telemeta_utils %}
+{% load i18n %}
 {% if items %}
-    {% if hits %}
-    <p class="pagination">Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
-    &nbsp;&nbsp;
-    {% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
-    {% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
-    </p>
-    {% endif %}
-    <ul>
-    {% for p in items %}
-        <li><a href="{% url telemeta-item-detail p.public_id %}">{{ p }}</a></li>
-    {% endfor %}
-    {% if more_items %} <li>[...]</li> {% endif %}
-    </ul>
+{% if hits %}
+<p class="pagination">Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }} 
+&nbsp;&nbsp;
+{% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %}
+{% if has_next %} <a href="?page={{ next }}&amp;{{criteria|build_query_string}}">&gt;&gt;</a> {% endif %}
+</p>
+{% endif %}
+<table class="listing">
+<tr>
+    <th class="highlight">{% trans "Title" %}</th>
+    <th>{% trans "Recordist" %}</th>
+    <th>{% trans "Country/Continent" %}</th>
+</tr>
+{% for item in items %}
+<tr {% if not forloop.counter0|divisibleby:"2" %}class="odd"{% endif %}>
+    <td class="highlight">
+        <a href="{% url telemeta-item-detail item.public_id %}">{{ item }}</a>
+    </td>
+    <td>{{ item.apparent_collector }}</td>
+    <td>{{ item.country_or_continent|default:'&nbsp;' }}</td>
+</tr>
+{% endfor %}
+</table>
 {% else %}
-    <p>No item</p>
+    <p>{% trans "No item" %}</p>
 {% endif %}
+
index 001301b19da3899011fcb09f6e6e2a451e9c759d..70277b472047bb0a83ea08f6a736dc194ea64ffc 100644 (file)
@@ -10,7 +10,6 @@
 {% endblock %}\r
 {% block extra_javascript %}\r
 \r
-<script src="{% url telemeta-js "application.js" %}" type="text/javascript"></script>\r
 <script src="{% url telemeta-js "wz_jsgraphics.js" %}" type="text/javascript"></script>\r
 <script src="{% url telemeta-js "soundmanager2.js" %}" type="text/javascript"></script>\r
 <script src="{% url telemeta-timeside "src/timeside.js" %}" type="text/javascript"></script>\r
index 341d25d7de7281ebb70da0fca4590c7c63365cdb..8a4a28fe07afeb69ad7a1af719f98a01fad7f23b 100644 (file)
@@ -1,8 +1,13 @@
 {% extends "telemeta/base.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
 
 {% block content %}
 <h3>Media items</h3>
 {% with object_list as items %}
+<div class="fullpage">
 {% include "telemeta/inc/mediaitem_list.html" %}
+</div>
 {% endwith %}
+
 {% endblock %}
index 6223703e21ab98c086eef568ba139a24025e478b..bf9e7c06acb35dbfc33796fcacd9404fd3644345 100644 (file)
@@ -171,6 +171,15 @@ def field_label(model, field):
             
     return capfirst(unicode(model.field_label(field)))
 
+@register.simple_tag
+def field_value(object, member):
+    value = getattr(object, member)
+    try:
+        value = value()
+    except TypeError:
+        pass
+    return value
+
 @register.filter
 def is_none(value):
     return value is None
@@ -189,3 +198,10 @@ def resources_num(value):
 
     return label
     
+@register.filter
+def split(value, sep=','):
+    return value.split(sep)
+
+@register.simple_tag
+def variable_link(object, url_name, url_key):
+    return reverse(url_name, args=[field_value(object, url_key)])
index 51668b0e0ebcceeda79f3ac8d2e79d117c2491b9..078464913ea8230bc323093a9f658209f0cf9e11 100644 (file)
@@ -48,8 +48,8 @@ comp_mgr = ComponentManager()
 web_view = WebView(comp_mgr)
 
 # query sets for Django generic views
-all_items = { 'queryset': MediaItem.objects.all(), }
-all_collections = { 'queryset': MediaCollection.objects.all(), }
+all_items = { 'queryset': MediaItem.objects.enriched(), }
+all_collections = { 'queryset': MediaCollection.objects.enriched(), }
 
 # ID's regular expressions
 export_extensions = "|".join(web_view.list_export_extensions())
index 9236ad7e14dbec30298da742067299bddb64e076..3911c7e27ac04fa72d5f5aa7f8667d4c19cb1d0b 100644 (file)
@@ -360,7 +360,7 @@ class WebView(Component):
     def list_country_collections(self, request, continent, country):
         continent = Location.objects.by_flatname(continent)[0]
         country = Location.objects.by_flatname(country)[0]
-        objects = MediaCollection.objects.by_location(country)
+        objects = MediaCollection.objects.enriched().by_location(country)
         return list_detail.object_list(request, objects, 
             template_name='telemeta/geo_country_collections.html', paginate_by=20,
             extra_context={'country': country, 'continent': continent})
@@ -368,7 +368,7 @@ class WebView(Component):
     def list_country_items(self, request, continent, country):
         continent = Location.objects.by_flatname(continent)[0]
         country = Location.objects.by_flatname(country)[0]
-        objects = MediaItem.objects.by_location(country)
+        objects = MediaItem.objects.enriched().by_location(country)
         return list_detail.object_list(request, objects, 
             template_name='telemeta/geo_country_items.html', paginate_by=20,
             extra_context={'country': country, 'continent': continent})