--- a/viewer.py Sat Jun 18 18:56:40 2016 +0800
+++ b/viewer.py Sat Jun 18 22:30:42 2016 +0800
+from peewee import DoesNotExist
from tornado.escape import json_decode
from tornado.ioloop import IOLoop
from tornado.options import define, options
-from tornado.web import Application, RequestHandler, URLSpec
+from tornado.web import Application, HTTPError, RequestHandler, URLSpec
from candolint import uimodules
from candolint.models import database, Project, Change, Check
define('debug', metavar='True|False', default=False, type=bool)
+def get_or_404(query, *args, **kwargs):
+ return query.get(*args, **kwargs)
class BaseHandler(RequestHandler):
class ProjectHandler(BaseHandler):
def get(self, domain, user, name):
- project = Project.select().where(
+ pq = Project.select().where(
Project.domain == domain,
Project.user == (user if user != '-' else None),
- Project.name == name).get()
+ project = get_or_404(pq)
class CheckHandler(BaseHandler):
def get(self, domain, user, name, check_num):
- project = Project.select().where(
+ pq = Project.select().where(
Project.domain == domain,
Project.user == (user if user != '-' else None),
- Project.name == name).get()
+ project = get_or_404(pq)
if check_num == 'latest':
- check = Check.get(project=project)
+ check = get_or_404(Check, project=project)
- check = Check.get(project=project, ordinal=check_num)
+ check = get_or_404(Check, project=project, ordinal=check_num)
lines = json_decode(check.lines)
self.render('check.html', project=project, check=check, lines=lines)
class StatusHandler(BaseHandler):
def get(self, domain, user, name):
- project = Project.select().where(
+ pq = Project.select().where(
Project.domain == domain,
Project.user == (user if user != '-' else None),
- Project.name == name).get()
- check = Check.get(project=project)
+ project = get_or_404(pq)
+ check = get_or_404(Check, project=project)
parts = [('#555', 30, 14.5, 'lint')]
parts.append(('#777', 62, 30.5, 'unknown'))