#!/usr/bin/python2.6 # -*- coding: iso-8859-15 -*- import logging from pylons import request, response, session, url, tmpl_context as c from pylons.controllers.util import abort, redirect from pylons.decorators.rest import restrict from wradmin.lib.base import BaseController, render from wradmin.lib.wrgpx import parse_wrgpx, etree, height_profile from pylons.i18n.translation import _, set_lang log = logging.getLogger(__name__) class WrgpxtoolController(BaseController): def index(self): c.validated = False return render('wrgpxtool.html') @restrict('POST') def upload(self): gpxfile = request.POST['gpxfile'] if gpxfile != u'': try: set_lang('de') (gpx, hints) = parse_wrgpx(string = gpxfile.value) c.validation_exception = None c.validation_hints = hints c.validation_ok = len([hint for hint in hints if hint.level > 1]) == 0 session['wrgpx'] = gpx 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 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 except etree.XMLSyntaxError, e: c.validation_exception = e c.validation_hints = [] c.validation_ok = False session['flash'] = u"Die Datei '%s' ist keine gültige GPX 1.1 Datei. :-(" % gpxfile.filename c.validated = True c.filename = gpxfile.filename else: c.validated = False session['flash'] = u"Bitte eine GPX-Datei angeben!" session.save() return render('wrgpxtool.html') def height_profile(self): response.content_type = 'image/png' response.charset = None if session.has_key('wrgpx'): wrgpx = session['wrgpx'] s = height_profile(wrgpx) return s