Order correctly, add filters to runners
authorTom Powell <tom@powell.io>
Tue, 30 Oct 2018 07:21:24 +0000 (00:21 -0700)
committerTom Powell <tom@powell.io>
Tue, 30 Oct 2018 07:21:24 +0000 (00:21 -0700)
ui/app.py

index 44cca2c3e512f773cf5a857c06584ca7bf004d42..1bfbdffa4dcd04223f337bce83bab5903bc5c2d0 100644 (file)
--- a/ui/app.py
+++ b/ui/app.py
@@ -28,8 +28,7 @@ nav.register_element('top', Navbar(
 
 headers = {'Private-Token': os.environ.get('GITLAB_TOKEN', '')}
 
-@app.route('/')
-def index():
+def parse_args():
     args = {}
     if request.args:
         if 'status' in request.args:
@@ -41,18 +40,28 @@ def index():
         if 'type' in request.args:
             args['build_type'] = request.args.get('type')
         if 'date' in request.args:
-            try:
-                date = datetime.datetime.strptime(request.args.get('date'), '%Y-%m-%d').date()
-                args['build_date'] = datetime.datetime.strptime(request.args.get('date'), '%Y-%m-%d').date()
-            except ValueError:
-                return "Invalid Date", 400
-    builds = models.Build.query.filter_by(**args).paginate(per_page=20)
+            date = datetime.datetime.strptime(request.args.get('date'), '%Y-%m-%d').date()
+            args['build_date'] = datetime.datetime.strptime(request.args.get('date'), '%Y-%m-%d').date()
+    return args
+
+@app.route('/')
+def index():
+    try:
+        args = parse_args()
+    except ValueError:
+        return "Invalid Date", 400
+    builds = models.Build.query.filter_by(**args).order_by(models.Build.build_date.desc(), models.Build.build_id).paginate(per_page=20)
     return render_template('builds.html', builds=builds)
 
 @app.route('/runners/<string:runner>')
 def runner(runner):
+    try:
+        args = parse_args()
+    except ValueError:
+        return "Invalid Date", 400
     runner = models.Runner.query.filter_by(runner_name=runner).first()
-    builds = models.Build.query.filter_by(build_runner=runner).paginate(per_page=20)
+    args['build_runner'] = runner
+    builds = models.Build.query.filter_by(**args).order_by(models.Build.build_date.desc(), models.Build.build_id).paginate(per_page=20)
     return render_template('runner.html', runner=runner, builds=builds)
 
 @app.route("/runners/")