maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH maposmatic] Add a rendered maps feed


From: Maxime Petazzoni
Subject: [Maposmatic-dev] [PATCH maposmatic] Add a rendered maps feed
Date: Thu, 4 Feb 2010 22:38:50 +0100

This change introduces a RSS feeds for the successfully rendered maps
that still have their files available (status=2), using the Django
syndication framework.

It uses a custom map-feed.html template instead of the map.html in order
to include styling information directly in the HTML an accomodate for
the variable naming from the syndication framework.

This new MapOSMatic maps feed is now available from a traditional RSS
icon link on the maps page.

Signed-off-by: Maxime Petazzoni <address@hidden>
---
 www/maposmatic/feeds.py                |   53 ++++++++++++++++++++++++++++++
 www/maposmatic/models.py               |    4 ++
 www/media/feed.png                     |  Bin 0 -> 1734 bytes
 www/media/style.css                    |    4 ++
 www/templates/maposmatic/all_maps.html |    2 +-
 www/templates/maposmatic/map-feed.html |   55 ++++++++++++++++++++++++++++++++
 www/urls.py                            |    9 +++++
 7 files changed, 126 insertions(+), 1 deletions(-)
 create mode 100644 www/maposmatic/feeds.py
 create mode 100644 www/media/feed.png
 create mode 100644 www/templates/maposmatic/map-feed.html

diff --git a/www/maposmatic/feeds.py b/www/maposmatic/feeds.py
new file mode 100644
index 0000000..38e72e6
--- /dev/null
+++ b/www/maposmatic/feeds.py
@@ -0,0 +1,53 @@
+# coding: utf-8
+
+# maposmatic, the web front-end of the MapOSMatic city map generation system
+# Copyright (C) 2010  David Decotigny
+# Copyright (C) 2010  Frédéric Lehobey
+# Copyright (C) 2010  Pierre Mauduit
+# Copyright (C) 2010  David Mentré
+# Copyright (C) 2010  Maxime Petazzoni
+# Copyright (C) 2010  Thomas Petazzoni
+# Copyright (C) 2010  Gaël Utard
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Feeds for MapOSMatic
+
+from django.contrib.syndication.feeds import Feed
+from django.utils.translation import ugettext_lazy as _
+
+from www.maposmatic import models
+
+class MapsFeed(Feed):
+    """
+    This feeds syndicates the latest successful rendering jobs in MapOSMatic,
+    with their thumbnail, and links to the rendered files.
+    """
+
+    title = _('MapOSMatic maps')
+    link = '/maps/' # We can't use reverse here as the urlpatterns aren't
+                    # defined yet at this point.
+    description = _('The latest successfully rendered maps on MapOSMatic.')
+
+    description_template = 'maposmatic/map-feed.html'
+
+    def items(self):
+        return (models.MapRenderingJob.objects
+                .filter(status=2)
+                .filter(resultmsg='ok')
+                .order_by('-endofrendering_time')[:10])
+
+    def item_title(self, item):
+        return item.maptitle
+
diff --git a/www/maposmatic/models.py b/www/maposmatic/models.py
index dc3b3ce..c166f80 100644
--- a/www/maposmatic/models.py
+++ b/www/maposmatic/models.py
@@ -21,6 +21,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from django.core.urlresolvers import reverse
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
@@ -175,3 +176,6 @@ class MapRenderingJob(models.Model):
         mean_job_rendering_time = waiting_time // progression
         estimated_time_left = mean_job_rendering_time * 
self.current_position_in_queue()
         return datetime.now() + estimated_time_left
+
+    def get_absolute_url(self):
+        return reverse('job-by-id', args=[self.id])
diff --git a/www/media/feed.png b/www/media/feed.png
new file mode 100644
index 
0000000000000000000000000000000000000000..7af2a97af4ea157d67c937fa02a925a3be4e9b0a
GIT binary patch
literal 1734
zcmV;%208hOP)<h;3K|address@hidden)
z=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01ejw01ejxLMWSf00007bV*G`2igJz
address@hidden&address@hidden(address@hidden(qz;IW<address@hidden
z6^KAcMF~_WDxfAMMg0O*5&address@hidden>zK$Sp%JfM)KiW3sYGn3e!
address@hidden&7+_RPKKoXy7_U;EgTV5+oNx|%a{&OK|Nwbx$z4q?W1U_*Tyk-H^YQ}ZJy8fg`l
address@hidden;address@hidden(8B2dCy}YH)CU!^Ya?<`)-yuf^4qCFoKa3_u6~0w5v?
zivR*h5QqR0!45=J83&)!-z)PVz;fYv7IFg_Z)|address@hidden;uaDBtZ)Y7G|#3ON(
zMn=J4kRS*FkVV1Rs%$Ri{}}`~b1a~#2Dx+*!zWKX+Os|PDjnER-<E7_IbPq8awdoJ
z;R!E4c)%J6kUD|P(X2N%dZtqlyH74?X>m%!qanDnpc!sk7wl9!tVratg0liho<nMJ
zt7~bo*^VX?_v*=#L3`|`wMg8tIS>bH=;9g3>|w~kgOFeE0Z-)rYjCX?S~474A(}|8
zv+an}qRXC1JI#<V35dEDxOFXXyY2v3L!SB+{uggR4eYG|e>ZSe3}z3u>$chi;cBgn
zoRbm3tcwKf#VcViUJ0E)2LGeyp|ktH6S$TP779ed6#yW}6dY)N^(`8%Lgbzo;PyQW
z5lze+T&v&)0P26Li|address@hidden&address@hidden<atF8$mo`luV4twEsu-lhI)GfMbFnoRp{(DaY
z`Tu-7xMaX`k<Xp01dvPse)(I~Z8cv5xBEWW*RBPuDkdo>A$LCm&hEP;I4cHh7o(%&
z2vT5SUM0r)qwqfb4N8Ar2i3m|0Gk2WG1z^-1+}iaBzTa5;address@hidden|!6M7n
zA>Q{(address@hidden<y1dse1V$sbYJ8D)<`zpv&`=QT`R0o#~ST;&!
zFJJ((PAcL_SS{VKuUZ4QXFX!~zl`|Cci`T#85B)~YS-CMA>aB5c<kgXCZdSk`5f3u
zRt0Abpdvy6OqWj>M3pL_XcG4KA424z9k9C}3>address@hidden<pyQx%*Q
zL+hCV%wphDWk`_(?A|SKZhaPHM*_7^6yfds1$biASnG7IhO>0_TyRxk;bIJ^Q~Th3
zybbd3o8WV&t9wAlZLrtA1g0poVyNOU%J2LN;m(yS*0%*(address@hidden
z1Em6Z=wHx-A47iiIyk)#lxPOkwwi2Qkpk-4A&>3`D~2j$LGdeLHD5O!Xe<etI|V=6
zAA$#EXv5cjMTB(address@hidden|m5m^*C2L?W+YqXK;)8AA@&#i}y!Xcj_}moC
zv#armccFG|0%Xa|b<ZQ<*p)#L=f_am|95k~wF_3NqiPDOYG4Xn)VD({Sp!km9<EVm
z4#R){*M<p^6GLR>#t>address@hidden)&{=ZBBMeeiE^`ksUHz+Yi4|7l3G
address@hidden@!)xna{vae`U<OohytKOvP_#U<%w?cmu2-JTjvm3F5|wfrhTI
zuFHG2nO1DMuseD~kW&9AW`K*k!J0zwIU1Omb85Q2x(TGN54~OH1|Ux#F+r|g9iGq|
zFc}~>3XyCI!I^m$12b5__?hbO_h&PPxBJKTnhw11nlR7)(8)Q^JE=thxSo*$hV}$m
address@hidden)0~n`VG3k%w2F(?fHi{|5Vj3w?b)*IXIVH)h)dy{
z3=zZM`EyX`U7)%SsQhtwU%m}3mErAv`UoaJdovI`2OEc_HgN&td;U?G3vO8$4%TSE
zPDCLKqiH(yaO3YgRxEoe<`$>B-0T*5k(N5!SgMV~oL5fHI>address@hidden
zMB3Ms_`iSyK<$zg&JJZfU+L$?iq{J1;>address@hidden(P%siSeP_V>kb$
zkO>>_{`ILxlTD4=8r$1k+w#G_2d#9lLFN5!db8lS>2dHoGy;d4I&DQ4L<A=hgIyoR
z+0z-Xn9Duhvpx4JW_SJr8|vE#*3V+K$#qu5U1V9#W%+xql<%pMH&{Mj+~EuT;)>S_
c>8ZJI0JCs&1hSI0*Z=?k07*qoM6N<$f?Xsh!~g&Q

literal 0
HcmV?d00001

diff --git a/www/media/style.css b/www/media/style.css
index f24525e..1da6861 100644
--- a/www/media/style.css
+++ b/www/media/style.css
@@ -43,6 +43,10 @@ img {
   -ms-interpolation-mode: bicubic;
 }
 
+img.feedicon {
+  width: 20px;
+}
+
 /* Header */
 #header {
   background-color: #cee5f6;
diff --git a/www/templates/maposmatic/all_maps.html 
b/www/templates/maposmatic/all_maps.html
index ac1b6f9..e940ee5 100644
--- a/www/templates/maposmatic/all_maps.html
+++ b/www/templates/maposmatic/all_maps.html
@@ -34,7 +34,7 @@
   <form action="{% url maps %}" method="post">{{ form.query }}<input 
type="submit" value="{% trans "Search" %}" /></form>
 </div>
 
-<h1><a href="{% url maps %}">{% trans "Maps" %}</a></h1>
+<h1><a href="{% url maps %}">{% trans "Maps" %}</a> <a 
href="/feeds/maps/"><img src="/smedia/feed.png" class="feedicon" title="{% 
trans "MapOSMatic maps feed" %}" /></h1>
 
 <p id="letterpagination" style="margin-bottom: 2em;">
   <a href="{% url maps %}"{% if not current_letter %} class="selectedletter"{% 
endif %}>{% trans "All" %}</a> - {% for l in letters %}<a href="{% url 
maps-by-letter l %}"{% ifequal l current_letter %} class="selectedletter"{% 
endifequal %}>{{ l }}</a>{% if not forloop.last %} - {% endif %}{% endfor %}
diff --git a/www/templates/maposmatic/map-feed.html 
b/www/templates/maposmatic/map-feed.html
new file mode 100644
index 0000000..52f8b72
--- /dev/null
+++ b/www/templates/maposmatic/map-feed.html
@@ -0,0 +1,55 @@
+{% comment %}
+ coding: utf-8
+
+ maposmatic, the web front-end of the MapOSMatic city map generation system
+ Copyright (C) 2010  David Decotigny
+ Copyright (C) 2010  Frédéric Lehobey
+ Copyright (C) 2010  David Mentré
+ Copyright (C) 2010  Maxime Petazzoni
+ Copyright (C) 2010  Thomas Petazzoni
+ Copyright (C) 2010  Gaël Utard
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+{% endcomment %}
+
+
+{% load i18n %}
+
+{% load extratags %}
+
+<table style="width: 100%;"><tbody><tr>
+  <td style="width: 220px; vertical-align: top; text-align: center;">{% if 
obj.get_thumbnail %}<img src="{{ obj.get_thumbnail }}" />{% endif %}</td>
+  <td style="vertical-align: top;">
+    {% if obj.administrative_city %}
+      {% ifnotequal obj.administrative_city obj.maptitle %}<h3>{{ 
obj.administrative_city }}</h3>{% endifnotequal %}
+    {% else %}
+    <h3>({{ obj.lat_upper_left|floatformat:3 }}, {{ 
obj.lon_upper_left|floatformat:3 }}) &rarr;
+        ({{ obj.lat_bottom_right|floatformat:3 }}, {{ 
obj.lon_bottom_right|floatformat:3 }})</h3>
+    {% endif %}
+
+    <p>{% trans "Rendering completed on" %} {{ obj.endofrendering_time|date:"l 
d M Y\, H:i:s" }}.</p>
+
+    {% if obj.has_output_files %}
+    <h4>{% trans "Files: " %}</h4>
+    <ul>
+      <li>{% trans "Map: " %} {% for file in obj.output_files.maps %}<a 
href="{{ file.1 }}" title="{{ file.2 }}">{{ file.0|upper }}</a> ({{ 
file.3|filesizeformat }}){% if not forloop.last %}, {% endif %}{% endfor 
%}.</li>
+      <li>{% trans "Index: " %} {% for file in obj.output_files.indeces %}<a 
href="{{ file.1 }}" title="{{ file.2 }}">{{ file.0|upper }}</a> ({{ 
file.3|filesizeformat }}){% if not forloop.last %}, {% endif %}{% endfor 
%}.</li>
+    </ul>
+    {% else %}
+      {% trans "The generated files are no longer available." %}
+    {% endif %}
+  </td>
+</tr></tbody></table>
+
+
diff --git a/www/urls.py b/www/urls.py
index b677f91..388121c 100644
--- a/www/urls.py
+++ b/www/urls.py
@@ -28,9 +28,14 @@ from django.conf.urls.defaults import *
 # from django.contrib import admin
 # admin.autodiscover()
 
+import maposmatic.feeds
 import maposmatic.views
 import settings
 
+feeds = {
+    'maps': maposmatic.feeds.MapsFeed,
+}
+
 urlpatterns = patterns('',
     url(r'^$', maposmatic.views.index,
         name='main'),
@@ -55,6 +60,10 @@ urlpatterns = patterns('',
     # Internationalization
     (r'^i18n/', include('django.conf.urls.i18n')),
 
+    # Feeds
+    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
+     {'feed_dict': feeds}),
+
     # Static data
     (r'^results/(?P<path>.*)$', 'django.views.static.serve',
      {'document_root': '/tmp/foo/'}),
-- 
1.6.3.3.277.g88938c





reply via email to

[Prev in Thread] Current Thread [Next in Thread]