diff --git a/www/maposmatic/context_processors.py b/www/maposmatic/context_processors.py index ed620951..430a124e 100644 --- a/www/maposmatic/context_processors.py +++ b/www/maposmatic/context_processors.py @@ -38,17 +38,25 @@ def get_latest_blog_posts(): return f.entries[:5] def get_osm_database_last_update(): + """Returns the timestamp of the last PostGIS database update, which is + placed into the maposmatic_admin table in the PostGIS database by the + planet-update incremental update script.""" + + db = gisdb.get() + if db is None: + return None + + cursor = db.cursor() + try: - 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: + cursor.execute("""select last_update from maposmatic_admin""") + last_update = cursor.fetchone() + if last_update is not None and len(last_update) == 1: + return datetime.datetime.strptime(last_update[0], '%Y-%m-%d %H:%M:%S') + except: pass + cursor.close() return None def all(request): diff --git a/www/maposmatic/gisdb.py b/www/maposmatic/gisdb.py index 8f9921dc..2c6415d9 100644 --- a/www/maposmatic/gisdb.py +++ b/www/maposmatic/gisdb.py @@ -40,7 +40,7 @@ def get(): return _DB try: - _DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s'" % + _DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s' connection_timeout=1" % (www.settings.GIS_DATABASE_NAME, www.settings.GIS_DATABASE_USER, www.settings.GIS_DATABASE_HOST, diff --git a/www/media/css/style.css b/www/media/css/style.css index 1cae63d5..2f15bb30 100644 --- a/www/media/css/style.css +++ b/www/media/css/style.css @@ -87,6 +87,11 @@ form#langsel { margin-right: 1em; } +p.error { + color: red; + font-weight: bold; +} + /* Navigation menu */ ul#nav { list-style: none; diff --git a/www/templates/maposmatic/base.html b/www/templates/maposmatic/base.html index 6057e38c..18005500 100644 --- a/www/templates/maposmatic/base.html +++ b/www/templates/maposmatic/base.html @@ -105,9 +105,9 @@

{% trans "OSM database status" %}

{% if osm_date %} -

{% blocktrans with osm_date|timesince:utc_now as date %}Lag of MapOSMatic OSM database: {{ date }}.{% endblocktrans %}

+

{% blocktrans with osm_date|timesince:utc_now as date %}Database is online, last update {{ date }} ago.{% endblocktrans %}

{% else %} -

{% blocktrans %}Lag of MapOSMatic OSM database: unknown.{% endblocktrans %}

+

{% blocktrans %}Could not connect to OSM database!{% endblocktrans %}

{% endif %}