Download:
child 293:085ce95c6d95
parent 291:76a67e1a5c73
292:7b640cb27fe2
Anton Shestakov <av6@dwimlabs.net>, Mon, 18 Sep 2017 15:45:42 +0800
viewer: show a solid color dot on check page to bring attention to the result

4 файлов изменено, 39 вставок(+), 0 удалений(-) [+]
candolint/handlers.py file | annotate | diff | comparison | revisions
templates/check.html file | annotate | diff | comparison | revisions
tests/test_viewer.py file | annotate | diff | comparison | revisions
viewer.py file | annotate | diff | comparison | revisions
--- a/candolint/handlers.py Mon Sep 18 14:27:41 2017 +0800
+++ b/candolint/handlers.py Mon Sep 18 15:45:42 2017 +0800
@@ -225,5 +225,31 @@
self.render('status.svg', width=width, parts=parts, height=20)
+class DotHandler(BaseHandler):
+ def get(self, domain, user, name, check_num):
+ project = get_project_or_404(domain, user, name)
+ checks = (Check
+ .select(*Check.get_light_fields())
+ .where(Check.project == project))
+ if check_num != 'latest':
+ checks = checks.where(Check.ordinal == check_num)
+ branch = self.get_argument('branch', None)
+ if branch is not None:
+ checks = checks.join(Change).where(Change.branch == branch)
+ check = checks.first()
+ if check is None:
+ color = 'transparent'
+ elif not check.success:
+ color = '#777'
+ elif check.errors:
+ color = '#da314b'
+ elif check.warnings:
+ color = '#faa732'
+ else:
+ color = '#8cc14c'
+ self.set_header('Content-Type', 'image/svg+xml; charset=utf-8')
+ self.render('dot.svg', color=color)
+
+
class ErrorHandler(BaseHandler, BaseErrorHandler):
pass
--- a/templates/check.html Mon Sep 18 14:27:41 2017 +0800
+++ b/templates/check.html Mon Sep 18 15:45:42 2017 +0800
@@ -19,6 +19,7 @@
<dd>{{ check.get_duration() }}</dd>
<dt>Result:</dt>
<dd>
+ <img src="{{ project.get_url() }}/{{ check.ordinal }}/dot.svg" alt="Check Result">
{% if check.success %}
{{ locale.translate('{} error', '{} errors', check.errors).format(check.errors) }},
{{ locale.translate('{} warning', '{} warnings', check.warnings).format(check.warnings) }}
--- a/tests/test_viewer.py Mon Sep 18 14:27:41 2017 +0800
+++ b/tests/test_viewer.py Mon Sep 18 15:45:42 2017 +0800
@@ -185,3 +185,14 @@
assert root.attrib['height'] == '20'
text = [el.text for el in root.findall('./svg:g/svg:text', ns)]
assert text[::2] == ['lint', '1 error', '1 warning']
+
+ def test_dot(self):
+ response = self.fetch('/example.com/alice/test-viewer/latest/dot.svg')
+ assert response.code == 200
+ root = ElementTree.fromstring(response.body)
+ ns = {'svg': 'http://www.w3.org/2000/svg'}
+ assert root.tag == '{http://www.w3.org/2000/svg}svg'
+ assert root.attrib.get('height') == '12'
+ circles = root.findall('./svg:circle', ns)
+ assert len(circles) == 1
+ assert circles[0].attrib.get('fill').startswith('#')
--- a/viewer.py Mon Sep 18 14:27:41 2017 +0800
+++ b/viewer.py Mon Sep 18 15:45:42 2017 +0800
@@ -20,6 +20,7 @@
(project_re, h.ProjectHandler),
(project_re + r'/atom', h.AtomHandler),
(project_re + r'/(\d+|latest)(?:/(raw))?', h.CheckHandler),
+ (project_re + r'/(\d+|latest)/dot\.svg', h.DotHandler),
(project_re + r'/(\d+|latest)/compare/(\d+|latest)', h.CompareHandler),
(project_re + r'/status\.svg', h.StatusHandler),
(r'.*', h.ErrorHandler, {'status_code': 404})