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