Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #52 from warunsl/add-template-for-logs
Browse files Browse the repository at this point in the history
Add template for tree log view
  • Loading branch information
catlee committed Nov 17, 2014
2 parents ccfb73e + f4378e9 commit 4464faa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
18 changes: 10 additions & 8 deletions treestatus/app.py
Expand Up @@ -22,6 +22,7 @@

import logging
log = logging.getLogger(__name__)
TREE_SUMMARY_LOG_LIMIT = 5


class Status:
Expand Down Expand Up @@ -435,8 +436,9 @@ def get_tree(tree):
if is_json():
return wrap_json_headers(t)

resp = make_response(render_template('tree.html', tree=t, logs=status.get_logs(tree),
loads=loads, token=get_token()))
resp = make_response(render_template('tree.html', tree=t,
logs=status.get_logs(tree, limit=TREE_SUMMARY_LOG_LIMIT),
loads=loads, token=get_token()))
resp.headers['Cache-Control'] = 'max-age=30'
resp.headers['Vary'] = 'Cookie'
if '?nc' in request.url:
Expand All @@ -450,16 +452,16 @@ def get_logs(tree):
if not t:
flask.abort(404)

if request.args.get('all') == '1':
if is_json() and request.args.get('all') == '1':
logs = status.get_logs(tree, limit=None)
else:
resp = wrap_json_headers(dict(logs=logs))
elif is_json():
logs = status.get_logs(tree)

if is_json():
resp = wrap_json_headers(dict(logs=logs))
else:
resp = make_response(dumps(logs, indent=2))
resp.headers['Content-Type'] = 'text/plain'
logs = status.get_logs(tree, limit=None)
resp = make_response(render_template('treelogs.html', tree=t, logs=logs,
loads=loads, token=get_token()))
resp.headers['Cache-Control'] = 'max-age=30'
return resp

Expand Down
2 changes: 1 addition & 1 deletion treestatus/templates/tree.html
Expand Up @@ -94,7 +94,7 @@ <h2>Modify this tree</h2>
</div>
{% endif -%}
<div id="tableWrapper">
<h2 id="previous">History</h2>
<h2 id="previous">Summary</h2>
<table class="history">
<thead>
<tr>
Expand Down
80 changes: 80 additions & 0 deletions treestatus/templates/treelogs.html
@@ -0,0 +1,80 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{{tree.tree}} - {{tree.status}}</title>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
</head>
<body>
<div id="container">
<div id = "main">
<span class="atRight">
{% if 'REMOTE_USER' in request.environ: -%}
{{request.environ['REMOTE_USER']}}
<a class="loginout" href="/logout">Logout</a>
{% else: -%}
<a class="loginout" href="/login">Login</a>
{% endif -%}
</span>
<h1><a href="/">TreeStatus</a></h1>
<h2>{{tree.tree}} is <span class="{{tree.status.lower().replace(" ", "_")}}">{{tree.status.upper()}}</span></h2><br/>
{% if tree.reason: -%}
<h2>Reason: {{tree.reason|e|linkbugs}}</h2>
{% endif -%}
{% if tree.message_of_the_day -%}
<h3>{{tree.message_of_the_day|e|linkbugs}}</h3>
{% endif -%}
<div id="tableWrapper">
<h2 id="previous">History</h2>
<table class="history">
<thead>
<tr>
<th class="tableWho">User</th>
<th class="tableWhen">Time</th>
<th class="tableState">Action</th>
<th class="tableReason">Reason</th>
<th class="tableTags">Tags</th>
</tr>
</thead>
<tbody>
{% for log in logs: -%}
<tr>
<td class="tableWho">
{% if 'REMOTE_USER' in request.environ: -%}
{{log.who}}
{% else -%}
{{log.who|obfuscate}}
{% endif -%}
</td>
<td class="tableWhen">
{{log.when}}
</td>
<td class="tableState">
{{log.action}}
</td>
<td class="tableReason">
{{log.reason|e|linkbugs}}
</td>
<td class="tableTags">
{{", ".join(log.tags)}}
</td>
</tr>
{% endfor -%}
</tbody>
</table>
</div>
</div>
<div id="footer">
<span class="footerWrapper">
<a href="/">All trees</a>
<a href="/help">Help</a>
<a href="https://github.com/mozilla/treestatus">Source</a>
{% if 'REMOTE_USER' in request.environ: -%}
<a href="/logout">Logout</a>
{% else: -%}
<a href="/login">Login</a>
{% endif -%}
</span>
</div>
</div>
</body>
</html>

0 comments on commit 4464faa

Please sign in to comment.