1.1 --- a/eskp.py Mon May 19 10:58:39 2014 +0200
1.2 +++ b/eskp.py Tue May 20 15:45:14 2014 +0200
1.3 @@ -2,15 +2,22 @@
1.4
1.5 import os
1.6 import codecs
1.7 +import vobject
1.8 +import StringIO
1.9 +
1.10 +import qrcode
1.11 +from qrcode.image.pure import PymagingImage
1.12
1.13 from docutils.core import publish_parts
1.14 -from flask import Flask, Response
1.15 +from flask import Flask
1.16 from flask import render_template
1.17 from flask import request
1.18 from flask.ext.babel import gettext as _
1.19 from flask.ext.babel import Babel
1.20 from config import LANGUAGES
1.21
1.22 +import base64
1.23 +
1.24 LANGUAGE_SELECTED = "de"
1.25 #ToDo after engelish is implemented set LANGUAGE_SELECTED = None
1.26
1.27 @@ -22,6 +29,15 @@
1.28
1.29 app.config['BABEL_DEFAULT_LOCALE'] = 'de'
1.30
1.31 +
1.32 +
1.33 +def get_vcard(filename):
1.34 + with codecs.open(filename, 'r', 'utf-8') as f:
1.35 + vcard = f.read()
1.36 + f.close()
1.37 + return vobject.readOne(vcard)
1.38 +
1.39 +
1.40 def get_content(filename, overrides=None):
1.41 content = u""
1.42 filename = os.path.join(ESKP_PATH, filename)
1.43 @@ -64,7 +80,6 @@
1.44
1.45 def modal_info(template, act, title, filename):
1.46 content = get_content(filename)
1.47 - print template
1.48 html = render_template(template, act=act, title=title, content=content, exit=_(u"Close"))
1.49 return html
1.50
1.51 @@ -125,16 +140,43 @@
1.52 return render_template("/eskp.html", act="eskp", content=content, headline=headline)
1.53
1.54
1.55 +def qr_image_data(card):
1.56 + buf= StringIO.StringIO()
1.57 + qr = qrcode.QRCode(
1.58 + version=1,
1.59 + error_correction=qrcode.constants.ERROR_CORRECT_L,
1.60 + box_size=2,
1.61 + border=2,
1.62 + )
1.63 + qr.add_data(card.serialize())
1.64 + qr.make(fit=True)
1.65 + img = qr.make_image()
1.66 + img.save(buf)
1.67 + image = buf.getvalue()
1.68 + return base64.b64encode(image)
1.69 +
1.70 +
1.71 @app.route("/ozoneloss")
1.72 def ozoneloss():
1.73 +
1.74 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss.rst")
1.75 content = get_content(filename)
1.76 - filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_author.rst")
1.77 - author = modal_info("/author_info.html", "author", _(u"Ozoneloss"), filename)
1.78 +
1.79 + vcard_file = os.path.join("vcards", "jug.vcf")
1.80 + author = u""
1.81 + try:
1.82 + card = get_vcard(vcard_file)
1.83 + except IOError:
1.84 + card = None
1.85 + if card is not None:
1.86 + qr_image = qr_image_data(card)
1.87 + author = render_template("/author_info.html", act="author", title=_(u"Ozoneloss"),
1.88 + card=card, image=qr_image, contact=_(u"Contact"), exit=_(u"Close"))
1.89 +
1.90 filename = os.path.join("templates", get_locale(), "rst", "ozoneloss_publications.rst")
1.91 publications = modal_info("/publications_info.html", "publications", _(u"Ozoneloss"), filename)
1.92 return render_template("/ozoneloss.html", act="ozoneloss", content=content,
1.93 - author=author, contact = u"Dr. Jens-Uwe Grooß", publications=publications )
1.94 + author=author,card=card, publications=publications )
1.95
1.96 @app.route("/ozoneloss/clams")
1.97 def ozoneloss_clams():