Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Added status page.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahume committed Jun 12, 2012
1 parent 0b88186 commit 0d36eb3
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 138 deletions.
3 changes: 2 additions & 1 deletion admin_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from views.admin import AdminHandler
from views.admin import AdminHandler, StatusHandler

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
Expand All @@ -11,6 +11,7 @@ def main():
logging.getLogger().setLevel(logging.DEBUG)
application = webapp.WSGIApplication([
('/admin/urls', AdminHandler),
('/admin/status', StatusHandler),
], debug=True)
util.run_wsgi_app(application)

Expand Down
134 changes: 0 additions & 134 deletions templates/admin.html

This file was deleted.

27 changes: 27 additions & 0 deletions templates/admin/status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "../base.html" %}
{% block title %}Status{% endblock %}

{% block content %}

<h2>Job queue stats</h2>
<table class="table table-striped table-bordered" style="margin-top: 10px;">
<tbody>
<tr><td>Jobs in test queue</td><td>{{ jobs_in_queue }}</td></tr>
<tr><td>WPT tests awaiting results</td><td>{{ tests_awaiting_results }}</td></tr>
</tbody>
</table>

<h2>Total status</h2>
<table class="table table-striped table-bordered" style="margin-top: 10px;">
<tbody>
<tr><td>Total test URLS</td><td>{{ total_urls }}</td></tr>
<tr><td>Total tests completed</td><td>{{ total_tests }}</td></tr>
</tbody>
</table>



</body>
</html>

{% endblock %}
134 changes: 134 additions & 0 deletions templates/admin/urls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{% extends "../base.html" %}
{% block title %}URL Admin{% endblock %}

{% block content %}

<style>
.form-horizontal .controls {
margin-left: 90px;
}
.form-horizontal .control-label {
width: 80px;
}
.form-horizontal input[type="submit"] {
padding-left: 10px;
padding-right: 10px;
}
table form {
margin: 0;
}

</style>

{% if messages %}
<div class="alert alert-success">
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
</div>
{% endif %}

<h2>URLs currently in test</h2>
<table class="table table-striped table-bordered" style="margin-top: 10px;">
<thead>
<tr><th>Name</th><th>URL</th><th>Dashboard</th><th>Schedule Test</th><th>Delete</th></tr>
</thead>
<tbody>
{% for url in urls %}
<tr>
<td>{{ url.name }}</td>
<td><a href="{{ url.url }}">{{ url.url }}</a></td>
<td><a href="/dashboard/{{ url.dashboard }}">{{ url.dashboard }}</a></td>
<td><i class="icon-time"></i> <a href="/schedule/{{ url.key }}">Test</a></td>
<td>
<form method="post" action="/admin/urls">
<i class="icon-trash"></i>
<input type="hidden" name="method" value="delete"><!-- Yay, HTTP -->
<input type="hidden" name="key" value="{{ url.key }}" />
<input type="submit" value="Delete" class="btn btn-mini" />
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>

<div class="row">
<div class="span6">

<h3>Add new URL</h3>
{% ifequal adding 'url' %}
{% ifequal error 'BadValueError' %}
<div class="alert alert-error"><p>All fields are required.</p></div>
{% endifequal %}
{% ifequal error '200' %}
<div class="alert alert-error"><p>Bad URL. Make sure you entered a URL that returns a HTTP 200 code, ie. no redirects, and is on the public internet.</p></div>
{% endifequal %}
{% endifequal %}
<form method="post" action="/admin/urls" class="form-horizontal" style="margin-top: 10px;">
<div class="control-group">
<label class="control-label" for="f-name">Name:</label>
<div class="controls">
<input type="text" name="name" id="f-name" placeholder="Guardian Network Front" value="{{ fields.name }}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="f-url">URL:</label>
<div class="controls">
<input type="text" name="url" id="f-url" placeholder="www.guardian.co.uk" value="{{ fields.url }}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="f-url">Dashboard:</label>
<div class="controls">
<select name="dashboard">
{% for dashboard in dashboards %}
<option value="{{ dashboard.id }}"{% ifequal dashboard.id fields.dashboard %} selected="selected"{%endifequal %}>{{ dashboard.name }}</option>
{% endfor %}
</select>
<p class="help-block">Which dashboard do you want the URL to appear on</p>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="model" value="url" />
<input type="submit" value="Add" class="btn btn-primary" />
</div>
</div>
</form>

</div>
<div class="span6">
<h3>Add new Dashboard</h3>
{% ifequal adding 'dashboard' %}
{% ifequal error 'BadValueError' %}
<div class="alert alert-error"><p>Both fields are required.</p></div>
{% endifequal %}
{% endifequal %}
<form method="post" action="/admin/urls" class="form-horizontal" style="margin-top: 10px;">
<div class="control-group">
<label class="control-label" for="f-dashboard-name">Name:</label>
<div class="controls">
<input type="text" name="dashboard-name" id="f-dashboard-name" placeholder="Discussion" value="{{ fields.dashboardname }}" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="f-dashboard-id">ID:</label>
<div class="controls">
<input type="text" name="dashboard-id" id="f-dashboard-id" placeholder="discussion" value="{{ fields.dashboardid }}" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="model" value="dashboard" />
<input type="submit" value="Add" class="btn btn-primary" />
</div>
</div>
</form>

</div>

</body>
</html>

{% endblock %}
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
{% endfor %}
</ul>
</li>
<li><a href="/admin/urls">Admin</a></li>
<li><a href="/admin/urls">Tests</a></li>
<li><a href="/admin/status">Status</a></li>
</ul>
</div>
</div>
Expand Down
19 changes: 17 additions & 2 deletions views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
import models
from utils import check_http_200, get_messages, add_message

class StatusHandler(webapp.RequestHandler):

def get(self):

context = {
'total_urls': models.Url.all().count(),
'jobs_in_queue': models.UrlTestTask.all().count(),
'tests_awaiting_results': models.TestResult.all().filter('results_received =', False).count(),
'total_tests': models.TestResult.all().count(),
'dashboards': models.Dashboard.all(),
}

self.response.out.write(template.render('templates/admin/status.html', context))



class AdminHandler(webapp.RequestHandler):

Expand All @@ -25,7 +40,7 @@ def get(self):
'messages': get_messages()
}

self.response.out.write(template.render('templates/admin.html', context))
self.response.out.write(template.render('templates/admin/urls.html', context))

def post(self):

Expand Down Expand Up @@ -81,7 +96,7 @@ def post(self):
context['messages'] = get_messages()
logging.debug(context['messages'])

self.response.out.write(template.render('templates/admin.html', context))
self.response.out.write(template.render('templates/admin/urls.html', context))


def delete(self):
Expand Down

0 comments on commit 0d36eb3

Please sign in to comment.