Mercurial > hg > ltpdarepo
changeset 49:6d3a309701af
Adapt to Flask 0.7.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Sat, 13 Aug 2011 20:27:24 +0200 |
parents | a06d8abe37c1 |
children | cd44da6ece8d |
files | buildout.cfg src/ltpdarepo/__init__.py src/ltpdarepo/security.py src/ltpdarepo/templates/layout.html src/ltpdarepo/templates/query.html src/ltpdarepo/views/base.py src/ltpdarepo/views/browse.py src/ltpdarepo/views/databases.py src/ltpdarepo/views/profile.py src/ltpdarepo/views/queries.py src/ltpdarepo/views/users.py |
diffstat | 11 files changed, 31 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 = ['<a href="%s">home</a>' % url_for('.index'), ] + parts.append((item, urljoin(url_for('index'), '/'.join(url)))) + out = ['<a href="%s">home</a>' % url_for('index'), ] for name, href in parts[1:]: out.append('<a href="%s">%s</a>' % (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():
--- 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)
--- 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 @@ <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{% block title %} {% endblock %} — LTPDA Repository</title> - <link rel="stylesheet" type="text/css" href="{{ url_for('.static', filename='style.css') }}"></link> + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"></link> {%- block head %}{% endblock %} </head> <body> <div class="header"><div> - <h1><a href="{{ url_for('.index') }}">LTPDA Repository</a></h1> + <h1><a href="{{ url_for('index') }}">LTPDA Repository</a></h1> <span>{{ request.host }}</span> </div></div> @@ -20,9 +20,9 @@ <div class="breadcrumbs">{{ request.path|breadcrumbs }}</div> <div class="user"> {% if session.username is defined %} - <a href="{{ url_for('.user.view', username=session.username) }}">{{ session.username }}</a> + <a href="{{ url_for('user.view', username=session.username) }}">{{ session.username }}</a> — - <a href="{{ url_for('.logout') }}">logout</a> + <a href="{{ url_for('logout') }}">logout</a> {% endif %} </div>
--- 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 %} - <script type="text/javascript" src="{{ url_for('.static', filename='jquery.js') }}"></script> - <script type="text/javascript" src="{{ url_for('.static', filename='querywidget.js') }}"></script> + <script type="text/javascript" src="{{ url_for('static', filename='jquery.js') }}"></script> + <script type="text/javascript" src="{{ url_for('static', filename='querywidget.js') }}"></script> <script type="text/javascript"> var criteria = {{ criteria|tojson|safe }}; </script>
--- 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'))
--- 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('/<database>/')
--- 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('/')
--- 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('/<username>')
--- 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('/<database>/queries/')
--- 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('/')