4 from pylons import request, response, session, url, tmpl_context as c
5 from pylons.controllers.util import abort, redirect
6 from pylons.decorators.rest import restrict
8 from wradmin.lib.base import BaseController, render
9 from wradmin.lib.wrgpx import parse_wrgpx, etree, height_profile
10 from pylons.i18n.translation import _, set_lang
12 log = logging.getLogger(__name__)
14 class WrgpxtoolController(BaseController):
18 return render('wrgpxtool.html')
22 gpxfile = request.POST['gpxfile']
26 (gpx, hints) = parse_wrgpx(string = gpxfile.value)
27 c.validation_exception = None
28 c.validation_hints = hints
29 c.validation_ok = len([hint for hint in hints if hint.level > 1]) == 0
30 session['wrgpx'] = gpx
31 if c.validation_ok: session['flash'] = "Die Datei '%s' ist eine gültige GPX 1.1 Datei und entspricht zusätzlich den Winterrodeln Anforderungen (WRGPX). :-)" % gpxfile.filename
32 else: session['flash'] = " Die Datei '%s' ist zwar eine gültige GPX 1.1 Datei, entspricht aber nicht den zusätzlichen Winterrodeln-Anforderungen. :-(" % gpxfile.filename
33 except etree.XMLSyntaxError as e:
34 c.validation_exception = e
35 c.validation_hints = []
36 c.validation_ok = False
37 session['flash'] = "Die Datei '%s' ist keine gültige GPX 1.1 Datei. :-(" % gpxfile.filename
39 c.filename = gpxfile.filename
42 session['flash'] = "Bitte eine GPX-Datei angeben!"
44 return render('wrgpxtool.html')
47 def height_profile(self):
48 response.content_type = 'image/png'
49 response.charset = None
50 if 'wrgpx' in session:
51 wrgpx = session['wrgpx']
52 s = height_profile(wrgpx)