From d4344eb9fa0b0e64ba749673ce1494859732b5ac Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Mar 13 2018 13:27:49 +0000 Subject: [frontend] add status_icon for build_id And don't cache the "in_progress" icon, which is soon to be replaced by skip/success/fail icon. --- diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py index 760edb2..906bf8c 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py @@ -18,7 +18,8 @@ from coprs.logic import coprs_logic from coprs.logic.builds_logic import BuildsLogic from coprs.logic.complex_logic import ComplexLogic -from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr +from coprs.views.misc import (login_required, page_not_found, req_with_copr, + req_with_copr, send_build_icon) from coprs.views.coprs_ns import coprs_ns from coprs.exceptions import (ActionInProgressException, @@ -33,6 +34,11 @@ def copr_build_redirect(build_id): return flask.redirect(helpers.copr_url("coprs_ns.copr_build", copr, build_id=build_id)) +@coprs_ns.route("/build//status_image.png") +def copr_build_icon(build_id): + return send_build_icon(BuildsLogic.get_by_id(int(build_id)).first()) + + ################################ Build detail ################################ @coprs_ns.route("///build//") diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py index 45690bd..a547cb5 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py @@ -6,10 +6,9 @@ from flask import send_file from coprs import db from coprs import forms from coprs import helpers -from coprs.models import Package, Build from coprs.views.coprs_ns import coprs_ns from coprs.views.coprs_ns.coprs_builds import render_add_build_scm, render_add_build_pypi, render_add_build_custom -from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr +from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr, send_build_icon from coprs.logic.complex_logic import ComplexLogic from coprs.logic.packages_logic import PackagesLogic from coprs.logic.users_logic import UsersLogic @@ -42,19 +41,7 @@ def copr_package_icon(copr, package_name): except ObjectNotFound: return send_file("static/status_images/bad_url.png", mimetype='image/png') - last_build = package.last_build() - if last_build: - if last_build.state in ["importing", "pending", "starting", "running"]: - return send_file("static/status_images/in_progress.png", mimetype='image/png') - - if last_build.state in ["succeeded", "skipped"]: - return send_file("static/status_images/succeeded.png", mimetype='image/png') - - if last_build.state == "failed": - return send_file("static/status_images/failed.png", mimetype='image/png') - - else: - return send_file("static/status_images/unknown.png", mimetype='image/png') + return send_build_icon(package.last_build()) @coprs_ns.route("///packages/rebuild-all/", methods=["GET", "POST"]) diff --git a/frontend/coprs_frontend/coprs/views/misc.py b/frontend/coprs_frontend/coprs/views/misc.py index 8f86d67..6505b7d 100644 --- a/frontend/coprs_frontend/coprs/views/misc.py +++ b/frontend/coprs_frontend/coprs/views/misc.py @@ -7,6 +7,7 @@ from functools import wraps, partial from netaddr import IPAddress, IPNetwork import re import flask +from flask import send_file from openid_teams.teams import TeamsRequest @@ -392,3 +393,28 @@ def render_migration_report(coprs, user=None, group=None): user=user, group=group, coprs=coprs) + + +def send_build_icon(build): + if not build: + return send_file("static/status_images/unknown.png", + mimetype='image/png') + + if build.state in ["importing", "pending", "starting", "running"]: + # The icon is about to change very soon, disable caches: + # https://help.github.com/articles/about-anonymized-image-urls/ + response = send_file("static/status_images/in_progress.png", + mimetype='image/png') + response.headers['Cache-Control'] = 'no-cache' + return response + + if build.state in ["succeeded", "skipped"]: + return send_file("static/status_images/succeeded.png", + mimetype='image/png') + + if build.state == "failed": + return send_file("static/status_images/failed.png", + mimetype='image/png') + + return send_file("static/status_images/unknown.png", + mimetype='image/png')