[llvm-commits] [zorg] r125864 - in /zorg/trunk/llvmlab/llvmlab/ui: app.py views.py
Daniel Dunbar
daniel at zuster.org
Fri Feb 18 08:40:50 PST 2011
Author: ddunbar
Date: Fri Feb 18 10:40:50 2011
New Revision: 125864
URL: http://llvm.org/viewvc/llvm-project?rev=125864&view=rev
Log:
llvmlab: Move routes into separate module.
Added:
zorg/trunk/llvmlab/llvmlab/ui/views.py
Modified:
zorg/trunk/llvmlab/llvmlab/ui/app.py
Modified: zorg/trunk/llvmlab/llvmlab/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/app.py?rev=125864&r1=125863&r2=125864&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/app.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/app.py Fri Feb 18 10:40:50 2011
@@ -2,10 +2,10 @@
import os
import flask
-from flask import redirect, render_template, request, session, url_for
import llvmlab.data
import llvmlab.user
+import llvmlab.ui.views
class LLVMLabApp(flask.Flask):
def __init__(self, name):
@@ -53,45 +53,8 @@
# Load the LLVM-Lab database.
app.load_data()
-###
-# Routing
-
- at app.route('/')
-def index():
- return render_template("index.html")
-
- at app.route('/favicon.ico')
-def favicon_ico():
- return redirect(url_for('static', filename='favicon.ico'))
-
- at app.route('/users')
-def users():
- return render_template("users.html")
-
- at app.route('/login', methods=['GET', 'POST'])
-def login():
- # If this isn't a post request, return the login template.
- if request.method != 'POST':
- return render_template("login.html", error=None)
-
- # Authenticate the user.
- username = request.form['username']
- if not app.authenticate_login(username, request.form['password']):
- return render_template("login.html",
- error="Invalid login")
-
- # Log the user in.
- session['logged_in'] = True
- session['active_user'] = username
- flask.flash('You were logged in as "%s"!' % username)
- return redirect(url_for("index"))
-
- at app.route('/logout')
-def logout():
- session.pop('logged_in', None)
- session.pop('active_user', None)
- flask.flash('You were logged out!')
- return redirect(url_for("index"))
+# Load the application routes.
+app.register_module(llvmlab.ui.views.ui)
###
Added: zorg/trunk/llvmlab/llvmlab/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/views.py?rev=125864&view=auto
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/views.py (added)
+++ zorg/trunk/llvmlab/llvmlab/ui/views.py Fri Feb 18 10:40:50 2011
@@ -0,0 +1,46 @@
+import flask
+from flask import redirect
+from flask import render_template
+from flask import request
+from flask import session
+from flask import url_for
+from flask import current_app
+from flask import Module
+ui = Module('app.py')
+
+ at ui.route('/')
+def index():
+ return render_template("index.html")
+
+ at ui.route('/favicon.ico')
+def favicon_ico():
+ return redirect(url_for('static', filename='favicon.ico'))
+
+ at ui.route('/users')
+def users():
+ return render_template("users.html")
+
+ at ui.route('/login', methods=['GET', 'POST'])
+def login():
+ # If this isn't a post request, return the login template.
+ if request.method != 'POST':
+ return render_template("login.html", error=None)
+
+ # Authenticate the user.
+ username = request.form['username']
+ if not current_app.authenticate_login(username, request.form['password']):
+ return render_template("login.html",
+ error="Invalid login")
+
+ # Log the user in.
+ session['logged_in'] = True
+ session['active_user'] = username
+ flask.flash('You were logged in as "%s"!' % username)
+ return redirect(url_for("index"))
+
+ at ui.route('/logout')
+def logout():
+ session.pop('logged_in', None)
+ session.pop('active_user', None)
+ flask.flash('You were logged out!')
+ return redirect(url_for("index"))
More information about the llvm-commits
mailing list