]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/wradmin/controllers/coordtool.py
19336370a7284ca0f2f6a975e2c3f42a30ea1741
[philipp/winterrodeln/wradmin.git] / wradmin / wradmin / controllers / coordtool.py
1 #!/usr/bin/python2.5
2 # -*- coding: iso-8859-15 -*-
3
4 import logging
5
6 from pylons import request, response, session, tmpl_context as c
7 from pylons.controllers.util import abort, redirect_to
8 import formencode
9
10 from wradmin.lib.base import BaseController, render
11 import wradmin.model.validators
12
13 log = logging.getLogger(__name__)
14
15 class CoordtoolController(BaseController):
16
17     def index(self):
18         c.result = None
19         return render('coordtool.html')
20     
21
22     def convert(self):
23         input = request.POST['input']
24         no_elevation = request.POST.has_key('no_elevation')
25         simplify = request.POST.has_key('simplify')
26         swap_latlon = request.POST.has_key('swap_latlon')
27         c.no_geoformat = request.POST.has_key('no_geoformat')
28         c.no_gpxformat = request.POST.has_key('no_gpxformat')
29         c.no_gmapsformat = request.POST.has_key('no_gmapsformat')
30         c.no_geocachingformat = request.POST.has_key('no_geocachingformat')
31         
32         if input is None or len(input.strip()) == 0: 
33             c.result = None
34             return redirect_to(controller='coordtool', action='index')
35         
36         geo = wradmin.model.validators.MultiGeo()
37         try: c.result = geo.to_python(input)
38         except formencode.Invalid, e:
39             session['flash'] = unicode(e)
40             session.save()
41             return redirect_to(controller='coordtool', action='index')
42         
43         if swap_latlon:
44             c.result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in c.result]
45         
46         if no_elevation:
47             c.result = [(longitude, latitude, None) for (longitude, latitude, elevation) in c.result]
48         
49         c.geo_winterrodeln = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_WINTERRODELN)
50         c.geo_gmapplugin = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_GMAPPLUGIN)
51         c.geo_gpx = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_GPX)
52         c.geo_geocaching = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_GEOCACHING)
53         
54         return render('coordtool.html')