]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
coordtool.html now uses jinja2.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 27 Dec 2017 22:31:24 +0000 (22:31 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 27 Dec 2017 22:31:24 +0000 (22:31 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wradmin/trunk@2765 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/controllers/coordtool.py
wradmin/templates/coordtool.html

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)
index 3e5792ef4008eb9b4b2b00a881b0444a3589e17e..8e3f1b75e542c10362a3f0143ae80a4f576482c2 100644 (file)
@@ -1,66 +1,73 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
-                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
-    xmlns:py="http://genshi.edgewall.org/"
-    xmlns:xi="http://www.w3.org/2001/XInclude">
-<xi:include href="master.html" />
-
-<head>
-    <title>Koordinaten-Rechner</title>
-</head>
-
-<body>
+{% extends "master.html" %}
+{% block title %}Koordinaten-Rechner{% endblock %}
 
+{% block content %}
 <h2>Koordinaten-Rechner</h2>
 
-<p py:if="not c.result">Werkzeug für die Koordinatenumrechnung. Das Quellformat braucht nicht angegeben zu werden, es sollte automatisch erkannt werden. Wenn mehr als eine Koordinate gleichzeitig umgerechnet werden soll, dann bitte pro Zeile eine Koordinate angeben.</p>
+{% if not result %}
+<p>Werkzeug für die Koordinatenumrechnung. Das Quellformat braucht nicht angegeben zu werden, es sollte automatisch erkannt werden. Wenn mehr als eine Koordinate gleichzeitig umgerechnet werden soll, dann bitte pro Zeile eine Koordinate angeben.</p>
+{% endif %}
 
-<h3 py:if="c.result and not c.no_geoformat">Winterrodeln-Format</h3>
-<p py:if="c.result and not c.no_geoformat">
-    <py:for each="line in c.result">${c.geo_winterrodeln([line])}<br/></py:for>
+{% if result and not no_geoformat %}
+<h3>Winterrodeln-Format</h3>
+<p>
+    {% for line in result %}
+    {{geo_winterrodeln([line])}}<br/>
+    {% endfor %}
 </p>
+{% endif %}
 
-<h3 py:if="c.result and not c.no_gmapsformat">Google Maps Plugin Format</h3>
-<p py:if="c.result and not c.no_gmapsformat">
-    <py:for each="line in c.result">${c.geo_gmapplugin([line])}<br/></py:for>
+{% if result and not no_gmapsformat %}
+<h3>Google Maps Plugin Format</h3>
+<p>
+    {% for line in result %}
+    {{geo_gmapplugin([line])}}<br/>
+    {% endfor %}
 </p>
+{% endif %}
 
-<h3 py:if="c.result and not c.no_gpxformat">GPX Format</h3>
-<p py:if="c.result and not c.no_gpxformat">
-    <py:for each="line in c.result">${c.geo_gpx([line])}<br/></py:for>
+{% if result and not no_gpxformat %}
+<h3>GPX Format</h3>
+<p>
+    {% for line in result %}
+    {{geo_gpx([line])}}<br/>
+    {% endfor %}
 </p>
+{% endif %}
 
-<h3 py:if="c.result and not c.no_geocachingformat">Geocaching-Format</h3>
-<p py:if="c.result and not c.no_geocachingformat">
-    <py:for each="line in c.result">${c.geo_geocaching([line])}<br/></py:for>
+{% if result and not no_geocachingformat %}
+<h3>Geocaching-Format</h3>
+<p>
+    {% for line in result %}
+    {{geo_geocaching([line])}}<br/>
+    {% endfor %}
 </p>
+{% endif %}
 
-<form action="${h.url(controller='coordtool', action='convert')}" method="post">
+<form action="{{url_for('coordtool_convert')}}" method="post">
 <table>
     <tr><th></th><th>Beispiel</th></tr>
-       <tr><td><textarea name="input" cols="80" rows="10"/></td>
+    <tr><td><textarea name="input" cols="80" rows="10"></textarea></td>
     <td>
         <p>47.222134 N 11.467211 E<br/>
            47.222143 N 11.467209 E<br/>
            47.222153 N 11.467210 E</p>
-        <p>N 47° 14.912 E 011° 27.432<br/>
-           N 47° 14.925 E 011° 27.439<br/>
-           N 47° 14.936 E 011° 27.440</p>
+        <p>N 47° 14.912 E 011° 27.432<br/>
+           N 47° 14.925 E 011° 27.439<br/>
+           N 47° 14.936 E 011° 27.440</p>
         <p>47.232922, 11.452239<br/>
            47.233008, 11.452201<br/>
            47.233810, 11.452150</p>
     </td></tr>
-    <tr><td><input type="checkbox" name="no_elevation" />Höhe weglassen</td><td></td></tr>
+    <tr><td><input type="checkbox" name="no_elevation" />Höhe weglassen</td><td></td></tr>
     <tr><td><input type="checkbox" name="simplify" /> Weg vereinfachen <em>(noch nicht implementiert)</em></td><td></td></tr>
-    <tr><td><input type="checkbox" name="swap_latlon" />Geogr. Länge und Breite vertauschen</td><td></td></tr>
+    <tr><td><input type="checkbox" name="swap_latlon" />Geogr. Länge und Breite vertauschen</td><td></td></tr>
     <tr><td><input type="checkbox" name="no_geoformat" /> Zielformat <strong>&lt;geo&gt;</strong> auslassen</td><td>47.222134 N 11.467211 E</td></tr>
     <tr><td><input type="checkbox" name="no_gpxformat" /> Zielformat <strong>&lt;GPX&gt;</strong> auslassen</td><td>&lt;trkpt lat="47.181289" lon="11.408827"&gt;&lt;ele&gt;1090.57&lt;/ele&gt;&lt;/trkpt&gt;</td></tr>
     <tr><td><input type="checkbox" name="no_gmapsformat" /> Zielformat <strong>Google Maps Plugin</strong> auslassen</td><td>47.232922, 11.452239</td></tr>
-    <tr><td><input type="checkbox" name="no_geocachingformat" /> Zielformat <strong>Geocaching</strong> auslassen</td><td>N 47° 14.029 E 011° 27.129</td></tr>
+    <tr><td><input type="checkbox" name="no_geocachingformat" /> Zielformat <strong>Geocaching</strong> auslassen</td><td>N 47° 14.029 E 011° 27.129</td></tr>
     <tr><td><input type="submit" value="Konvertieren"/></td><td></td></tr>
 </table>
 </form>
 
-</body>
-</html>
+{% endblock %}