# HG changeset patch # User Daniele Nicolodi # Date 1313260044 -7200 # Node ID 6d3a309701afd9590133a07854770f6c2d76fd52 # Parent a06d8abe37c14dd167db5692a5d2488891e8a707 Adapt to Flask 0.7. diff -r a06d8abe37c1 -r 6d3a309701af buildout.cfg --- a/buildout.cfg Sat Aug 13 20:26:56 2011 +0200 +++ b/buildout.cfg Sat Aug 13 20:27:24 2011 +0200 @@ -5,7 +5,7 @@ [flask] recipe = zc.recipe.egg eggs = - Flask < 0.7 + Flask WTForms ordereddict argparse diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/__init__.py --- a/src/ltpdarepo/__init__.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/__init__.py Sat Aug 13 20:27:24 2011 +0200 @@ -31,11 +31,10 @@ # return render_template('error.html', error=u'500: Needs upgrade'), 500 -@app.after_request -def after_request(response): +@app.teardown_request +def teardown_request(exception): # close database connection g.db.close() - return response # non authorized error handler @@ -57,8 +56,8 @@ for item in path.split('/')[1:-1]: url.append(item) if item: - parts.append((item, urljoin(url_for('.index'), '/'.join(url)))) - out = ['home' % url_for('.index'), ] + parts.append((item, urljoin(url_for('index'), '/'.join(url)))) + out = ['home' % url_for('index'), ] for name, href in parts[1:]: out.append('%s' % (href, name)) if len(out) > 1: @@ -101,7 +100,7 @@ @app.route('/logout') def logout(): session.pop('username', None) - return redirect(url_for('.index')) + return redirect(url_for('index')) @app.route('/') @@ -116,19 +115,19 @@ from .views.browse import module -app.register_module(module, url_prefix='/browse') +app.register_blueprint(module, url_prefix='/browse') from .views.profile import module -app.register_module(module, url_prefix='/user') +app.register_blueprint(module, url_prefix='/user') from .views.databases import module -app.register_module(module, url_prefix='/manage/databases') +app.register_blueprint(module, url_prefix='/manage/databases') from .views.queries import module -app.register_module(module, url_prefix='/manage/databases') +app.register_blueprint(module, url_prefix='/manage/databases') from .views.users import module -app.register_module(module, url_prefix='/manage/users') +app.register_blueprint(module, url_prefix='/manage/users') def main(): diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/security.py --- a/src/ltpdarepo/security.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/security.py Sat Aug 13 20:27:24 2011 +0200 @@ -61,7 +61,7 @@ url = request.path if url == '/': url = None - return redirect(url_for('.login', next=url)) + return redirect(url_for('login', next=url)) if self.role not in g.identity.roles: abort(403) return func(*args, **kwargs) diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/templates/layout.html --- a/src/ltpdarepo/templates/layout.html Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/templates/layout.html Sat Aug 13 20:27:24 2011 +0200 @@ -4,13 +4,13 @@ {% block title %} {% endblock %} — LTPDA Repository - + {%- block head %}{% endblock %}
-

LTPDA Repository

+

LTPDA Repository

{{ request.host }}
@@ -20,9 +20,9 @@
{% if session.username is defined %} - {{ session.username }} + {{ session.username }} — - logout + logout {% endif %}
diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/templates/query.html --- a/src/ltpdarepo/templates/query.html Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/templates/query.html Sat Aug 13 20:27:24 2011 +0200 @@ -1,8 +1,8 @@ {% extends "objs.html" %} {% block head %} - - + + diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/base.py --- a/src/ltpdarepo/views/base.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/base.py Sat Aug 13 20:27:24 2011 +0200 @@ -1,8 +1,8 @@ -from flask import Module, request, session, redirect, flash, render_template, g +from flask import Blueprint, request, session, redirect, flash, render_template, g from ltpdarepo.security import require, authenticate -app = Module(__name__) +app = Blueprint('base', __name__) @app.route('/login', methods=('GET', 'POST')) diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/browse.py --- a/src/ltpdarepo/views/browse.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Sat Aug 13 20:27:24 2011 +0200 @@ -3,7 +3,7 @@ import datetime from operator import itemgetter -from flask import Module, abort, g, request, render_template, redirect, url_for, json, make_response +from flask import Blueprint, abort, g, request, render_template, redirect, url_for, json, make_response from MySQLdb.cursors import DictCursor from ltpdarepo.security import require, view @@ -144,7 +144,8 @@ return curs.fetchone()[0] -app = Module(__name__, 'browse') + +app = Blueprint('browse', __name__) @app.route('//') diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/databases.py --- a/src/ltpdarepo/views/databases.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/databases.py Sat Aug 13 20:27:24 2011 +0200 @@ -1,4 +1,4 @@ -from flask import Module, abort, g, render_template, request, redirect, url_for, flash +from flask import Blueprint, abort, g, render_template, request, redirect, url_for, flash from MySQLdb.cursors import DictCursor @@ -12,7 +12,7 @@ from ordereddict import OrderedDict -app = Module(__name__, 'manage.databases') +app = Blueprint('manage.databases', __name__) @app.route('/') diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/profile.py --- a/src/ltpdarepo/views/profile.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/profile.py Sat Aug 13 20:27:24 2011 +0200 @@ -1,4 +1,4 @@ -from flask import Module, abort, flash, render_template, request, redirect, url_for +from flask import Blueprint, abort, flash, render_template, request, redirect, url_for from ltpdarepo.security import require, permission from ltpdarepo.form import Form @@ -7,7 +7,7 @@ from ltpdarepo.user import User, IUser, IPassword -app = Module(__name__, 'user') +app = Blueprint('user', __name__) @app.route('/') diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/queries.py --- a/src/ltpdarepo/views/queries.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/queries.py Sat Aug 13 20:27:24 2011 +0200 @@ -1,9 +1,9 @@ -from flask import Module, render_template, g, abort +from flask import Blueprint, render_template, g, abort, redirect, request, json, session, url_for from ltpdarepo.security import require from ltpdarepo.query import Query -app = Module(__name__, 'manage.queries') +app = Blueprint('manage.queries', __name__) @app.route('//queries/') diff -r a06d8abe37c1 -r 6d3a309701af src/ltpdarepo/views/users.py --- a/src/ltpdarepo/views/users.py Sat Aug 13 20:26:56 2011 +0200 +++ b/src/ltpdarepo/views/users.py Sat Aug 13 20:27:24 2011 +0200 @@ -1,4 +1,4 @@ -from flask import Module, abort, flash, g, render_template, request, redirect, url_for +from flask import Blueprint, abort, flash, g, render_template, request, redirect, url_for from ltpdarepo.security import require from ltpdarepo.user import User, IUser @@ -6,7 +6,7 @@ from MySQLdb.cursors import DictCursor -app = Module(__name__, 'manage.users') +app = Blueprint('manage.users', __name__) @app.route('/')