maposmatic-dev
[Top][All Lists]
Advanced

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

[Maposmatic-dev] [PATCH] Fix UTC offset in GIS data base lag calculation


From: Maxime Petazzoni
Subject: [Maposmatic-dev] [PATCH] Fix UTC offset in GIS data base lag calculation
Date: Thu, 26 Apr 2012 14:32:10 -0700

Signed-off-by: Maxime Petazzoni <address@hidden>
---
 www/maposmatic/context_processors.py |   18 ++++++++------
 www/templates/maposmatic/base.html   |   45 +++++++++++++++++-----------------
 2 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/www/maposmatic/context_processors.py 
b/www/maposmatic/context_processors.py
index dc9cc9a..b8fb9b7 100644
--- a/www/maposmatic/context_processors.py
+++ b/www/maposmatic/context_processors.py
@@ -38,16 +38,17 @@ def get_latest_blog_posts():
 
 def get_osm_database_last_update():
     try:
-        f = open(www.settings.GIS_DATABASE_LAG_FILE)
+        with open(www.settings.GIS_DATABASE_LAG_FILE) as f:
+            try:
+                return datetime.datetime.strptime(
+                    '%s' % f.read().strip(),
+                    '%Y-%m-%d %H:%M:%S')
+            except ValueError:
+                pass
     except IOError:
-        return None
+        pass
 
-    s = f.readline().strip()
-    try:
-        d = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")
-    except ValueError:
-        return None
-    return d
+    return None
 
 def all(request):
     # Do not add the useless overhead of parsing blog entries when generating
@@ -68,6 +69,7 @@ def all(request):
         'blogposts': get_latest_blog_posts(),
         'MAPOSMATIC_DAEMON_RUNNING': www.settings.is_daemon_running(),
         'osm_date': get_osm_database_last_update(),
+        'utc_now': datetime.datetime.utcnow(),
         'DEBUG': www.settings.DEBUG,
         'paypal_lang_code': paypal_lang_code,
         'paypal_country_code': paypal_country_code,
diff --git a/www/templates/maposmatic/base.html 
b/www/templates/maposmatic/base.html
index dd7c71e..6057e38 100644
--- a/www/templates/maposmatic/base.html
+++ b/www/templates/maposmatic/base.html
@@ -87,29 +87,30 @@
       </td>
 
       <td id="meta">
-       <div id="bdonate">
-         <h3>{% trans "Donate to MapOSMatic" %}</h3>
-
-         <form action="https://www.paypal.com/cgi-bin/webscr"; method="post" 
style="float: right; margin-left: 5px;">
-           <input type="hidden" name="cmd" value="_s-xclick"/>
-           <input type="hidden" name="hosted_button_id" value="YQPBAUM3JW8T2"/>
-           <input type="hidden" name="country" 
value="{{paypal_country_code}}"/>
-           <input type="image" 
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/btn/btn_donate_LG.gif";
 border="0" name="submit" alt="PayPal — The safer, easier way to pay online."/>
-           <img alt="" border="0" 
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/scr/pixel.gif"; 
width="1" height="1"/>
-         </form>
-
-         <p>{% blocktrans %}You can donate to help us improve the service. See 
our <a href="/donate">donation</a> page.{% endblocktrans %}</p>
-
-       </div>
-
-       <div id="bosmtimestamp">
-         <h3>{% trans "OSM database status" %}</h3>
-         {% if osm_date %}
-          <p>{% blocktrans with osm_date|timesince as date %}Lag of MapOSMatic 
OSM database: {{ date }}.{% endblocktrans %}</p>
-         {% else %}
+        <div id="bdonate">
+          <h3>{% trans "Donate to MapOSMatic" %}</h3>
+
+          <form action="https://www.paypal.com/cgi-bin/webscr"; method="post" 
style="float: right; margin-left: 5px;">
+            <input type="hidden" name="cmd" value="_s-xclick"/>
+            <input type="hidden" name="hosted_button_id" 
value="YQPBAUM3JW8T2"/>
+            <input type="hidden" name="country" 
value="{{paypal_country_code}}"/>
+            <input type="image" 
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/btn/btn_donate_LG.gif";
 border="0" name="submit" alt="PayPal — The safer, easier way to pay online."/>
+            <img alt="" border="0" 
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/scr/pixel.gif"; 
width="1" height="1"/>
+          </form>
+
+          <p>{% blocktrans %}You can donate to help us improve the service. 
See our <a href="/donate">donation</a> page.{% endblocktrans %}</p>
+
+        </div>
+
+        <div id="bosmtimestamp">
+          <h3>{% trans "OSM database status" %}</h3>
+          {% if osm_date %}
+          <p>{% blocktrans with osm_date|timesince:utc_now as date %}Lag of 
MapOSMatic OSM database: {{ date }}.{% endblocktrans %}</p>
+          {% else %}
           <p>{% blocktrans %}Lag of MapOSMatic OSM database: unknown.{% 
endblocktrans %}</p>
-         {% endif %}
-       </div>
+          {% endif %}
+        </div>
+
         <div id="bmap">
           <h3>{% trans "Random map" %}</h3>
           {% if randommap %}<p class="randommap">
-- 
1.7.10




reply via email to

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