# $Id$
# $HeadURL$
"""Contains functions that maintain/update the cache tables."""
-from xml.etree import ElementTree
from sqlalchemy import schema
from sqlalchemy.sql import select
import formencode
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrsledruncache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrinncache(engine.connect())
"""
metadata = schema.MetaData()
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=1')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
>>> update_wrreportcache(engine.connect())
"""
metadata = schema.MetaData()
wrreportcache = wrmwdb.wrreportcache_table(metadata)
transaction = connection.begin()
- # Delte the datasets we are going to update
+ # Delete the datasets we are going to update
sql_del = wrreportcache.delete()
if not page_id is None: sql_del = sql_del.where(wrreportcache.c.page_id == page_id)
connection.execute(sql_del)
def insert_row(connection, rowlist):
if len(rowlist) == 0: return
- # Build XML
- reports_xml = ElementTree.Element('reports')
- for row in rowlist:
- report_xml = ElementTree.SubElement(reports_xml, 'report')
- report_xml.set('report_id', unicode(row.report_id))
- report_xml.set('date_report', unicode(row.report_date_report))
- report_xml.set('condition', unicode(row.report_condition))
- report_xml.set('author_name', unicode(row.report_author_name))
- report_xml.set('author_username', unicode(row.report_author_username))
- report_xml.text = unicode(row.report_description)
- reports_xml.set('page_id', unicode(row.page_id))
- reports_xml.set('page_title', row.page_title)
- reports_xml = unicode(ElementTree.tostring(reports_xml, 'utf8'), 'utf8') # there is not ElementTree.tounicode())
- # Insert the report(s)
+ # Insert the report
row = dict(rowlist[0])
- row['reports_xml'] = reports_xml
connection.execute(wrreportcache.insert(values=row))
# Select the rows to update
- sql = 'select page_id, page_title, wrreport.id as report_id, date_report as report_date_report, `condition` as report_condition, description as report_description, author_name as report_author_name, if(author_userid is null, null, author_username) as report_author_username from wrreport where {0}`condition` is not null and date_invalid > now() and delete_date is null order by page_id, date_report desc, date_entry desc'.format('' if page_id is None else 'page_id={0} and '.format(page_id))
+ sql = 'select page_id, page_title, wrreport.id as report_id, date_report, `condition`, description, author_name, if(author_userid is null, null, author_username) as author_username from wrreport where {0}`condition` is not null and date_invalid > now() and delete_date is null order by page_id, date_report desc, date_entry desc'.format('' if page_id is None else 'page_id={0} and '.format(page_id))
cursor = connection.execute(sql)
page_id = None
rowlist = []
>>> from sqlalchemy.engine import create_engine
>>> engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0')
- >>> update_wrmapcache(engine.connect())
+ >>> # or: engine = create_engine('mysql://philipp@localhost:3306/philipp_winterrodeln_wiki?charset=utf8&use_unicode=0&passwd=XXXXX')
+ >>> # see: https://sourceforge.net/tracker/?func=detail&aid=2837134&group_id=22307&atid=374932
+ >>> connection = engine.connect()
+ >>> update_wrmapcache(connection)
"""
metadata = schema.MetaData()
page = mwdb.page_table(metadata)
if not point_types.has_key(point_type): raise RuntimeError(u'Unknown point type {0}'.format(point_type))
point_type = point_types[point_type]
sql = u'insert into wrmappointcache (page_id, type, point, label) values (%s, %s, POINT(%s, %s), %s)'
- connection.execute(sql, (sledrun_page.page_id, point_type, lon, lat, None))
+ connection.execute(sql, (sledrun_page.page_id, point_type, lon, lat, label))
# Paths
for path_type, coords in paths:
path_type = path_type.lower()
- path_types = {u'6#ff014e9a': u'sledrun', u'6#ffe98401': u'walkup', u'6#ff7f7fff': u'alternative', u'3#ff000000': u'lift'}
+ path_types = {u'6#ff014e9a': u'sledrun', u'6#ffe98401': u'walkup', u'6#ff7f7fff': u'alternative', u'3#ff000000': u'lift', u'3#ffe1e100': u'recommendedcarroute'}
if not path_types.has_key(path_type): raise RuntimeError(u'Unknown path type {0}'.format(path_type))
path_type = path_types[path_type]
path = u", ".join(["{0} {1}".format(lon, lat) for lon, lat, symbol, title in coords])
path = u'LineString({0})'.format(path)
+ if path_type == u'recommendedcarroute': continue
sql = u'insert into wrmappathcache (path, page_id, type) values (GeomFromText(%s), %s, %s)'
connection.execute(sql, (path, sledrun_page.page_id, path_type))
except RuntimeError as e: