]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/controllers/coordtool.py
coordtool.html now uses jinja2.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / coordtool.py
index 1aefbc947dfca3618f61651279e68ebf19402c9c..9dda22b248977a92c80560a06c99c5f97ae489dc 100644 (file)
@@ -3,8 +3,7 @@ import re
 import xml.dom.minidom as minidom
 from xml.parsers.expat import ExpatError
 from enum import IntEnum
-from flask import request, redirect, url_for, flash
-from wradmin.genshi import render_genshi_template, TemplateContext
+from flask import request, redirect, url_for, flash, render_template
 
 
 class MultiGeo(IntEnum):
@@ -96,41 +95,41 @@ def multigeo_to_string(value, output_format):
 class CoordtoolController:
 
     def index(self):
-        c = TemplateContext()
-        c.result = None
-        return render_genshi_template('coordtool.html', c=c)
+        return render_template('coordtool.html', result=None)
 
     def convert(self):
-        c = TemplateContext()
         assert request.method == 'POST'
         input = request.form['input']
         no_elevation = 'no_elevation' in request.form
         simplify = 'simplify' in request.form
         swap_latlon = 'swap_latlon' in request.form
-        c.no_geoformat = 'no_geoformat' in request.form
-        c.no_gpxformat = 'no_gpxformat' in request.form
-        c.no_gmapsformat = 'no_gmapsformat' in request.form
-        c.no_geocachingformat = 'no_geocachingformat' in request.form
+        no_geoformat = 'no_geoformat' in request.form
+        no_gpxformat = 'no_gpxformat' in request.form
+        no_gmapsformat = 'no_gmapsformat' in request.form
+        no_geocachingformat = 'no_geocachingformat' in request.form
         
         if input is None or len(input.strip()) == 0: 
-            c.result = None
             return redirect(url_for('coordtool_index'))
         
         try:
-            c.result = multigeo_from_string(input, MultiGeo.FORMAT_GUESS)
+            result = multigeo_from_string(input, MultiGeo.FORMAT_GUESS)
         except ValueError as e:
             flash(str(e))
             return redirect(url_for('coordtool_index'))
         
         if swap_latlon:
-            c.result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in c.result]
+            result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in result]
         
         if no_elevation:
-            c.result = [(longitude, latitude, None) for (longitude, latitude, elevation) in c.result]
+            result = [(longitude, latitude, None) for (longitude, latitude, elevation) in result]
         
-        c.geo_winterrodeln = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_WINTERRODELN)
-        c.geo_gmapplugin = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GMAPPLUGIN)
-        c.geo_gpx = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GPX)
-        c.geo_geocaching = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GEOCACHING)
+        geo_winterrodeln = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_WINTERRODELN)
+        geo_gmapplugin = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GMAPPLUGIN)
+        geo_gpx = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GPX)
+        geo_geocaching = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GEOCACHING)
         
-        return render_genshi_template('coordtool.html', c=c)
+        return render_template('coordtool.html', result=result,
+                               no_geoformat=no_geoformat, geo_winterrodeln=geo_winterrodeln,
+                               no_gmapsformat=no_gmapsformat, geo_gmapplugin=geo_gmapplugin,
+                               no_gpxformat=no_gpxformat, geo_gpx=geo_gpx,
+                               no_geocachingformat=no_geocachingformat, geo_geocaching=geo_geocaching)