# encoding=utf8
from flask import *
from sailing import app
from sailing.core import core
from sailing.database.training_tasks import db_training_tasks
from sailing.database.training_tasks_images import db_training_tasks_images
from flask_weasyprint import HTML, render_pdf
import sys
reload(sys)
sys.setdefaultencoding('utf8')
@app.route("/training_tasks/<id>.pdf")
def training_tasks_pdf(id):
return render_pdf(url_for('training_tasks', id=id))
@app.route("/training_tasks/", methods=['GET'])
def training_tasks():
if request.args.get('id'):
try:
int(request.args.get('id'))
except:
return redirect("/training_tasks/")
dbdata = db_training_tasks.query.filter(db_training_tasks.id==request.args.get('id')).first()
if not dbdata:
return redirect("/training_tasks/")
templateData = {
"title_suf": dbdata.title,
"id": request.args.get('id'),
"content": dbdata.content
}
templateData.update(core)
dbimages = db_training_tasks_images.query.filter(db_training_tasks_images.id_task==request.args.get('id')).all()
if len(dbimages) != 0:
return render_template("training_tasks.html", dbimages=dbimages, **templateData)
else:
return render_template("training_tasks.html", **templateData)
else:
templateData = {
"title_suf": "Training Tasks"
}
templateData.update(core)
dbdata_all = db_training_tasks.query.all()
return render_template("training_home.html", dbdata=dbdata_all, **templateData)
@app.route("/training_plan/", methods=['GET'])
def training_plan():
templateData = {
"title_suf": "Training Plan"
}
templateData.update(core)
return render_template("training_plan_home.html", **templateData)
127.0.0.1 - - [15/Jul/2016 15:55:18] "GET /training_tasks/1.pdf HTTP/1.0" 500 -
Traceback (most recent call last):
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/daniel/sailing.systems/sailing/training.py", line 15, in training_tasks_pdf
return render_pdf(url_for('training_tasks', id=id))
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask_weasyprint/__init__.py", line 208, in render_pdf
html = HTML(html)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask_weasyprint/__init__.py", line 182, in HTML
return _wrapper(weasyprint.HTML, *args, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/flask_weasyprint/__init__.py", line 165, in _wrapper
return class_(guess, *args, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/weasyprint/__init__.py", line 92, in __init__
namespaceHTMLElements=False)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/html5lib/html5parser.py", line 35, in parse
return p.parse(doc, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/html5lib/html5parser.py", line 235, in parse
self._parse(stream, False, None, *args, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/html5lib/html5parser.py", line 85, in _parse
self.tokenizer = _tokenizer.HTMLTokenizer(stream, parser=self, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/html5lib/_tokenizer.py", line 36, in __init__
self.stream = HTMLInputStream(stream, **kwargs)
File "/home/daniel/sailing.systems/venv/lib/python2.7/site-packages/html5lib/_inputstream.py", line 151, in HTMLInputStream
return HTMLBinaryInputStream(source, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'encoding'