--- a/candolint/handlers.py Mon Sep 18 14:27:41 2017 +0800
+++ b/candolint/handlers.py Mon Sep 18 15:45:42 2017 +0800
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)
+ .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)
+ checks = checks.join(Change).where(Change.branch == branch)
+ elif not check.success:
+ self.set_header('Content-Type', 'image/svg+xml; charset=utf-8')
+ self.render('dot.svg', color=color)
class ErrorHandler(BaseHandler, BaseErrorHandler):
--- a/templates/check.html Mon Sep 18 14:27:41 2017 +0800
+++ b/templates/check.html Mon Sep 18 15:45:42 2017 +0800
<dd>{{ check.get_duration() }}</dd>
+ <img src="{{ project.get_url() }}/{{ check.ordinal }}/dot.svg" alt="Check Result">
{{ 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
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']
+ 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
(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})