]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/controllers/wrgpxtool.py
Changed encoding to UTF-8.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / wrgpxtool.py
1 #!/usr/bin/python2.6
2 import logging
3
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
7
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
11
12 log = logging.getLogger(__name__)
13
14 class WrgpxtoolController(BaseController):
15
16     def index(self):
17         c.validated = False
18         return render('wrgpxtool.html')
19
20     @restrict('POST')
21     def upload(self):
22         gpxfile = request.POST['gpxfile']
23         if gpxfile != '':
24             try:
25                 set_lang('de')
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
38             c.validated = True
39             c.filename = gpxfile.filename
40         else:
41             c.validated = False
42             session['flash'] = "Bitte eine GPX-Datei angeben!"
43         session.save()
44         return render('wrgpxtool.html')
45     
46     
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)
53             return s