#!/usr/bin/python2.6 # -*- coding: iso-8859-15 -*- import logging from pylons import request, response, session, url, tmpl_context as c from pylons.controllers.util import abort, redirect import formencode from wradmin.lib.base import BaseController, render import wrpylib.wrvalidators log = logging.getLogger(__name__) class CoordtoolController(BaseController): def index(self): c.result = None return render('coordtool.html') def convert(self): input = request.POST['input'] no_elevation = request.POST.has_key('no_elevation') simplify = request.POST.has_key('simplify') swap_latlon = request.POST.has_key('swap_latlon') c.no_geoformat = request.POST.has_key('no_geoformat') c.no_gpxformat = request.POST.has_key('no_gpxformat') c.no_gmapsformat = request.POST.has_key('no_gmapsformat') c.no_geocachingformat = request.POST.has_key('no_geocachingformat') if input is None or len(input.strip()) == 0: c.result = None return redirect(url(controller='coordtool', action='index')) geo = wrpylib.wrvalidators.MultiGeo() try: c.result = geo.to_python(input) except formencode.Invalid, e: session['flash'] = unicode(e) session.save() return redirect(url(controller='coordtool', action='index')) if swap_latlon: c.result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in c.result] if no_elevation: c.result = [(longitude, latitude, None) for (longitude, latitude, elevation) in c.result] c.geo_winterrodeln = wrpylib.wrvalidators.MultiGeo(output_format = geo.FORMAT_WINTERRODELN) c.geo_gmapplugin = wrpylib.wrvalidators.MultiGeo(output_format = geo.FORMAT_GMAPPLUGIN) c.geo_gpx = wrpylib.wrvalidators.MultiGeo(output_format = geo.FORMAT_GPX) c.geo_geocaching = wrpylib.wrvalidators.MultiGeo(output_format = geo.FORMAT_GEOCACHING) return render('coordtool.html')