]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/wradmin/controllers/wrgpxtool.py
26f564f8100132cad1a8a858b0411e05eebb854d
[philipp/winterrodeln/wradmin.git] / wradmin / wradmin / controllers / wrgpxtool.py
1 #!/usr/bin/python2.5
2 # -*- coding: iso-8859-15 -*-
3
4 import logging
5
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
9
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
13
14 log = logging.getLogger(__name__)
15
16 class WrgpxtoolController(BaseController):
17
18     def index(self):
19         c.validated = False
20         return render('wrgpxtool.html')
21
22     @restrict('POST')
23     def upload(self):
24         gpxfile = request.POST['gpxfile']
25         if gpxfile != u'':
26             try:
27                 set_lang('de')
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
40             c.validated = True
41             c.filename = gpxfile.filename
42         else:
43             c.validated = False
44             session['flash'] = u"Bitte eine GPX-Datei angeben!"
45         session.save()
46         return render('wrgpxtool.html')
47     
48     
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)
55             return s