[llvm-commits] [zorg] r125900 - in /zorg/trunk/llvmlab/llvmlab/ui: frontend/views.py templates/add_machine.html templates/machines.html
Daniel Dunbar
daniel at zuster.org
Fri Feb 18 08:42:40 PST 2011
Author: ddunbar
Date: Fri Feb 18 10:42:40 2011
New Revision: 125900
URL: http://llvm.org/viewvc/llvm-project?rev=125900&view=rev
Log:
llvmlab: Add admin page to add a machine.
Added:
zorg/trunk/llvmlab/llvmlab/ui/templates/add_machine.html
Modified:
zorg/trunk/llvmlab/llvmlab/ui/frontend/views.py
zorg/trunk/llvmlab/llvmlab/ui/templates/machines.html
Modified: zorg/trunk/llvmlab/llvmlab/ui/frontend/views.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/frontend/views.py?rev=125900&r1=125899&r2=125900&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/frontend/views.py (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/frontend/views.py Fri Feb 18 10:42:40 2011
@@ -6,11 +6,15 @@
from flask import session
from flask import url_for
from flask import current_app
-frontend = flask.Module(__name__)
+
+import llvmlab
+import llvmlab.machine
###
# Top-level Information
+frontend = flask.Module(__name__)
+
@frontend.route('/')
def index():
return render_template("index.html")
@@ -25,6 +29,44 @@
###
# Machine Management
+
+ at frontend.route('/add_machine', methods=['GET', 'POST'])
+def add_machine():
+ # Check that we have an active user.
+ user = current_app.get_active_user()
+ if user is None:
+ abort(401)
+
+ # Check that the user has authority to access the lab.
+ if not user.has_lab_access():
+ abort(401)
+
+ # If this isn't a post request, return the template.
+ if request.method != 'POST':
+ return render_template("add_machine.html", error=None)
+
+ # Validate the entry data.
+ id = request.form['id']
+ hostname = request.form['hostname']
+ if id in current_app.config.data.machines:
+ return render_template("add_machine.html",
+ error='machine "%s" already exists' % id)
+ if hostname in set(m.hostname
+ for m in current_app.config.data.machines.values()):
+ return render_template("add_machine.html",
+ error='hostname "%s" already used' % hostname)
+
+ # Add the machine record.
+ machine = llvmlab.machine.Machine(id, hostname, user.id)
+ current_app.config.data.machines[machine.id] = machine
+ flask.flash('Added machine "%s"!' % machine.id)
+
+ # Save the application data.
+ current_app.save_data()
+ flask.flash('Saved data!')
+
+ return redirect(url_for("admin"))
+
@frontend.route('/machines')
def machines():
return render_template("machines.html")
Added: zorg/trunk/llvmlab/llvmlab/ui/templates/add_machine.html
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/templates/add_machine.html?rev=125900&view=auto
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/templates/add_machine.html (added)
+++ zorg/trunk/llvmlab/llvmlab/ui/templates/add_machine.html Fri Feb 18 10:42:40 2011
@@ -0,0 +1,17 @@
+{% extends "layout.html" %}
+{% block title %}users{% endblock %}
+{% block body %}
+
+<h2>Add Machine</h2>
+{% if error %}
+<p class=error><strong>Error:</strong> {{ error }}
+{% endif %}
+<form action="{{ url_for('add_machine') }}" method="POST">
+<dl>
+ <dt>ID:</dt><dd><input type="text" name="id"></dd>
+ <dt>Hostname:</td><dd><input type="text" name="hostname"></dd>
+ <dd><input type=submit value=Submit></dd>
+</dl>
+</form>
+
+{% endblock %}
Modified: zorg/trunk/llvmlab/llvmlab/ui/templates/machines.html
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/llvmlab/llvmlab/ui/templates/machines.html?rev=125900&r1=125899&r2=125900&view=diff
==============================================================================
--- zorg/trunk/llvmlab/llvmlab/ui/templates/machines.html (original)
+++ zorg/trunk/llvmlab/llvmlab/ui/templates/machines.html Fri Feb 18 10:42:40 2011
@@ -17,7 +17,8 @@
<tr>
<td>{{ id }}</td>
<td>{{ machine.hostname }}</td>
- <td><a href="{{ url_for('user', machine.admin) }}">{{ machine.admin }}</td>
+ <td><a href="{{ url_for('user', username=machine.admin) }}">{{
+ machine.admin }}</td>
</tr>
{% endfor %}
</table>
More information about the llvm-commits
mailing list