From 3218c808e87206983c4eb3ce4faceddbcc0f7aa3 Mon Sep 17 00:00:00 2001 From: Maksudul Haque Date: Thu, 21 Feb 2019 03:03:21 +0600 Subject: [PATCH] #4036 Updated build list to include an alert state (#5222) * Updated build list to include an alert state * Docstring issue fixed. * Template filter name changed. * Logic Moved to Models * Lint issue Fixed. --- media/css/core.css | 8 +++++ readthedocs/builds/models.py | 8 +++++ readthedocs/rtd_tests/tests/test_builds.py | 31 +++++++++++++++++++ .../templates/core/build_list_detailed.html | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/media/css/core.css b/media/css/core.css index 44d0dbc70..d07a81ec1 100644 --- a/media/css/core.css +++ b/media/css/core.css @@ -702,6 +702,14 @@ p.build-missing { font-size: .8em; color: #9d9a55; margin: 0 0 3px; } #footer label { color: #BCC1C3; font-weight: normal; } #footer input[type="text"], #footer input[type="email"] { padding: 4px; font-size: 12px; line-height: 16px; margin-bottom: 5px } +/* Warning Icon for Build List triggered */ +.module-item.col-span a span.icon-warning:before { + font-family: FontAwesome; + font-size: .9em; + padding-right: .3em; + font-weight: normal; + content: "\f071"; +} /* utils */ diff --git a/readthedocs/builds/models.py b/readthedocs/builds/models.py index d9c25e265..88673e71e 100644 --- a/readthedocs/builds/models.py +++ b/readthedocs/builds/models.py @@ -2,6 +2,7 @@ """Models for the builds app.""" +import datetime import logging import os.path import re @@ -31,6 +32,7 @@ from .constants import ( BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, + BUILD_STATE_TRIGGERED, BUILD_TYPES, LATEST, NON_REPOSITORY_VERSIONS, @@ -629,6 +631,12 @@ class Build(models.Model): """Return if build has a finished state.""" return self.state == BUILD_STATE_FINISHED + @property + def is_stale(self): + """Return if build state is triggered & date more than 5m ago.""" + mins_ago = timezone.now() - datetime.timedelta(minutes=5) + return self.state == BUILD_STATE_TRIGGERED and self.date < mins_ago + class BuildCommandResultMixin: diff --git a/readthedocs/rtd_tests/tests/test_builds.py b/readthedocs/rtd_tests/tests/test_builds.py index afdbe46a3..e7e05bb0d 100644 --- a/readthedocs/rtd_tests/tests/test_builds.py +++ b/readthedocs/rtd_tests/tests/test_builds.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- +import datetime import os import mock from django.test import TestCase from django_dynamic_fixture import fixture, get +from django.utils import timezone from readthedocs.builds.models import Build, Version from readthedocs.doc_builder.config import load_yaml_config @@ -531,3 +533,32 @@ class BuildModelTests(TestCase): build_two.save() self.assertEqual(build_two._config, {}) self.assertEqual(build_two.config, {}) + + def test_build_is_stale(self): + now = timezone.now() + + build_one = get( + Build, + project=self.project, + version=self.version, + date=now - datetime.timedelta(minutes=8), + state='finished' + ) + build_two = get( + Build, + project=self.project, + version=self.version, + date=now - datetime.timedelta(minutes=6), + state='triggered' + ) + build_three = get( + Build, + project=self.project, + version=self.version, + date=now - datetime.timedelta(minutes=2), + state='triggered' + ) + + self.assertFalse(build_one.is_stale) + self.assertTrue(build_two.is_stale) + self.assertFalse(build_three.is_stale) diff --git a/readthedocs/templates/core/build_list_detailed.html b/readthedocs/templates/core/build_list_detailed.html index ee5bb8c44..4f574b55b 100644 --- a/readthedocs/templates/core/build_list_detailed.html +++ b/readthedocs/templates/core/build_list_detailed.html @@ -4,7 +4,7 @@ {% for build in build_qs %}