[llvm-commits] [zorg] r130211 - in /zorg/trunk/lnt/lnt/server/ui: templates/index.html templates/layout.html views.py
Daniel Dunbar
daniel at zuster.org
Tue Apr 26 10:47:46 PDT 2011
Author: ddunbar
Date: Tue Apr 26 12:47:46 2011
New Revision: 130211
URL: http://llvm.org/viewvc/llvm-project?rev=130211&view=rev
Log:
LNT/Flask: Add a decorator for defining per-db routes.
Modified:
zorg/trunk/lnt/lnt/server/ui/templates/index.html
zorg/trunk/lnt/lnt/server/ui/templates/layout.html
zorg/trunk/lnt/lnt/server/ui/views.py
Modified: zorg/trunk/lnt/lnt/server/ui/templates/index.html
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/ui/templates/index.html?rev=130211&r1=130210&r2=130211&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/ui/templates/index.html (original)
+++ zorg/trunk/lnt/lnt/server/ui/templates/index.html Tue Apr 26 12:47:46 2011
@@ -3,7 +3,7 @@
{% block title %}Overview{% endblock %}
{% block body %}
-{% if db_info.showGeneral %}
+{% if g.db_info.showGeneral %}
<hr>
<h3>General Database Access</h3>
Modified: zorg/trunk/lnt/lnt/server/ui/templates/layout.html
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/ui/templates/layout.html?rev=130211&r1=130210&r2=130211&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/ui/templates/layout.html (original)
+++ zorg/trunk/lnt/lnt/server/ui/templates/layout.html Tue Apr 26 12:47:46 2011
@@ -30,7 +30,7 @@
<tr>
<td>
<strong>
- [{{ db_name }}]
+ [{{ g.db_name }}]
</strong>
</td>
<td style="text-align:right;">
Modified: zorg/trunk/lnt/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/ui/views.py?rev=130211&r1=130210&r2=130211&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/ui/views.py (original)
+++ zorg/trunk/lnt/lnt/server/ui/views.py Tue Apr 26 12:47:46 2011
@@ -3,6 +3,7 @@
import flask
from flask import abort
from flask import current_app
+from flask import g
from flask import redirect
from flask import render_template
from flask import request
@@ -38,25 +39,43 @@
#####
# Per-Database Routes
- at frontend.route('/')
- at frontend.route('/db_<name>')
- at frontend.route('/db_<name>/')
-def index(name = None):
- name = name or "default"
- db_info = current_app.old_config.databases.get(name)
- return render_template("index.html", db_name=name, db_info=db_info)
+# Decorator for implementing per-database routes.
+def db_route(rule, **options):
+ """
+ LNT specific route for endpoints which always refer to some database
+ object.
+
+ This decorator handles adding the routes for both the default and explicit
+ database, as well as initializing the global database information objects.
+ """
+ def decorator(f):
+ def wrap(db_name = None, **args):
+ # Initialize the database parameters on the app globals object.
+ g.db_name = db_name or "default"
+ g.db_info = current_app.old_config.databases.get(g.db_name)
+ if g.db_info is None:
+ abort(404)
+
+ return f(**args)
+
+ frontend.add_url_rule(rule, f.__name__, wrap, **options)
+ frontend.add_url_rule("/db_<db_name>" + rule,
+ f.__name__, wrap, **options)
+
+ return wrap
+ return decorator
+
+ at db_route('/')
+def index():
+ return render_template("index.html")
###
# Database Actions
- at frontend.route('/browse')
-def browse(name = None):
- name = name or "default"
- db_info = current_app.old_config.databases.get(name)
+ at db_route('/browse')
+def browse():
raise NotImplementedError
- at frontend.route('/submitRun')
-def submit_run(name = None):
- name = name or "default"
- db_info = current_app.old_config.databases.get(name)
+ at db_route('/submitRun')
+def submit_run():
raise NotImplementedError
More information about the llvm-commits
mailing list