From e928131809df21560774f9264bed871c9361aac7 Mon Sep 17 00:00:00 2001 From: AaronKable Date: Mon, 8 Jun 2020 17:20:07 +0800 Subject: [PATCH 1/3] make version relevant to an admin --- .../authentication/tests/test_templatetags.py | 19 +++++++--- .../allianceauth/admin-status/overview.html | 38 ++++++++----------- allianceauth/templatetags/admin_status.py | 20 +++++++--- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/allianceauth/authentication/tests/test_templatetags.py b/allianceauth/authentication/tests/test_templatetags.py index 5a999fa3..92db274e 100644 --- a/allianceauth/authentication/tests/test_templatetags.py +++ b/allianceauth/authentication/tests/test_templatetags.py @@ -70,15 +70,16 @@ class TestStatusOverviewTag(TestCase): 'notifications': GITHUB_NOTIFICATION_ISSUES[:5] } mock_current_notifications.return_value = notifications - version_info = { 'latest_major': True, 'latest_minor': True, 'latest_patch': True, + 'latest_beta': False, 'current_version': TEST_VERSION, - 'latest_major_version': '2.0.0', + 'latest_major_version': '2.4.5', 'latest_minor_version': '2.4.0', 'latest_patch_version': '2.4.5', + 'latest_beta_version': '2.4.4a1', } mock_current_version_info.return_value = version_info mock_fetch_celery_queue_length.return_value = 3 @@ -90,10 +91,12 @@ class TestStatusOverviewTag(TestCase): 'latest_major': True, 'latest_minor': True, 'latest_patch': True, + 'latest_beta': False, 'current_version': TEST_VERSION, - 'latest_major_version': '2.0.0', + 'latest_major_version': '2.4.5', 'latest_minor_version': '2.4.0', 'latest_patch_version': '2.4.5', + 'latest_beta_version': '2.4.4a1', 'task_queue_length': 3, } self.assertEqual(result, expected) @@ -146,6 +149,7 @@ class TestVersionTags(TestCase): self.assertEqual(result['latest_major_version'], '2.0.0') self.assertEqual(result['latest_minor_version'], '2.4.0') self.assertEqual(result['latest_patch_version'], '2.4.5') + self.assertEqual(result['latest_beta_version'], '2.4.6a1') @patch(MODULE_PATH + '.admin_status.__version__', TEST_VERSION) @patch(MODULE_PATH + '.admin_status.cache') @@ -174,30 +178,33 @@ class TestLatestsVersion(TestCase): tags = create_tags_list( ['2.1.1', '2.1.0', '2.0.0', '2.1.1a1', '1.1.1', '1.1.0', '1.0.0'] ) - major, minor, patch = _latests_versions(tags) + major, minor, patch, beta = _latests_versions(tags) self.assertEqual(major, Pep440Version('2.0.0')) self.assertEqual(minor, Pep440Version('2.1.0')) self.assertEqual(patch, Pep440Version('2.1.1')) + self.assertEqual(beta, Pep440Version('2.1.1a1')) def test_major_and_minor_not_defined_with_zero(self): tags = create_tags_list( ['2.1.2', '2.1.1', '2.0.1', '2.1.1a1', '1.1.1', '1.1.0', '1.0.0'] ) - major, minor, patch = _latests_versions(tags) + major, minor, patch, beta = _latests_versions(tags) self.assertEqual(major, Pep440Version('2.0.1')) self.assertEqual(minor, Pep440Version('2.1.1')) self.assertEqual(patch, Pep440Version('2.1.2')) + self.assertEqual(beta, Pep440Version('2.1.1a1')) def test_can_ignore_invalid_versions(self): tags = create_tags_list( ['2.1.1', '2.1.0', '2.0.0', '2.1.1a1', 'invalid'] ) - major, minor, patch = _latests_versions(tags) + major, minor, patch, beta = _latests_versions(tags) self.assertEqual(major, Pep440Version('2.0.0')) self.assertEqual(minor, Pep440Version('2.1.0')) self.assertEqual(patch, Pep440Version('2.1.1')) + self.assertEqual(beta, Pep440Version('2.1.1a1')) class TestFetchListFromGitlab(TestCase): diff --git a/allianceauth/templates/allianceauth/admin-status/overview.html b/allianceauth/templates/allianceauth/admin-status/overview.html index 3d6ce5ef..afc4757f 100644 --- a/allianceauth/templates/allianceauth/admin-status/overview.html +++ b/allianceauth/templates/allianceauth/admin-status/overview.html @@ -36,28 +36,8 @@ {{ current_version }}

-
  • -
    {% trans "Latest Major" %}
    -

    - - - {{ latest_major_version }} - - {% if not latest_major %}
    {% trans "Update available" %}{% endif %} -

    -
  • -
  • -
    {% trans "Latest Minor" %}
    -

    - - - {{ latest_minor_version }} - - {% if not latest_minor %}
    {% trans "Update available" %}{% endif %} -

    -
  • -
  • -
    {% trans "Latest Patch" %}
    +
  • +
    {% trans "Latest Version" %}

    @@ -66,6 +46,20 @@ {% if not latest_patch %}
    {% trans "Update available" %}{% endif %}

  • +
  • +
    {% trans "Latest Pre-Release" %}
    +

    + {% if latest_beta %} + + + {{ latest_beta_version }} + + {% if not latest_patch %}
    {% trans "Pre-Release available" %}{% endif %} + {% else %} + {% trans "No Current Pre-Release" %} + {% endif %} +

    +
  • diff --git a/allianceauth/templatetags/admin_status.py b/allianceauth/templatetags/admin_status.py index 808a69be..0508747b 100644 --- a/allianceauth/templatetags/admin_status.py +++ b/allianceauth/templatetags/admin_status.py @@ -95,7 +95,7 @@ def _current_version_summary() -> dict: logger.exception('Error while getting gitlab release tags') return {} - latest_major_version, latest_minor_version, latest_patch_version = \ + latest_major_version, latest_minor_version, latest_patch_version, latest_beta_version = \ _latests_versions(tags) current_version = Pep440Version(__version__) @@ -105,15 +105,21 @@ def _current_version_summary() -> dict: current_version >= latest_minor_version if latest_minor_version else False has_latest_patch = \ current_version >= latest_patch_version if latest_patch_version else False + has_current_beta = \ + current_version.base_version <= latest_beta_version.base_version \ + and latest_major_version.base_version <= latest_beta_version.base_version \ + if latest_beta_version else False response = { 'latest_major': has_latest_major, 'latest_minor': has_latest_minor, 'latest_patch': has_latest_patch, + 'latest_beta': has_current_beta, 'current_version': str(current_version), 'latest_major_version': str(latest_major_version), 'latest_minor_version': str(latest_minor_version), - 'latest_patch_version': str(latest_patch_version) + 'latest_patch_version': str(latest_patch_version), + 'latest_beta_version': str(latest_beta_version) } return response @@ -128,14 +134,18 @@ def _latests_versions(tags: list) -> tuple: Non-compliant tags will be ignored """ versions = list() + betas = list() for tag in tags: try: version = Pep440Version(tag.get('name')) except InvalidVersion: pass else: - if not version.is_prerelease: + if version.is_prerelease or version.is_devrelease: + betas.append(version) + else: versions.append(version) + latest_version = latest_patch_version = max(versions) latest_major_version = min([ @@ -145,8 +155,8 @@ def _latests_versions(tags: list) -> tuple: v for v in versions if v.major == latest_version.major and v.minor == latest_version.minor ]) - - return latest_major_version, latest_minor_version, latest_patch_version + latest_beta_version = max(betas) + return latest_major_version, latest_minor_version, latest_patch_version, latest_beta_version def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES): From c75de07c2ecf8f799a15d6a97cb5b8043f2fbdad Mon Sep 17 00:00:00 2001 From: AaronKable Date: Mon, 8 Jun 2020 20:47:05 +0800 Subject: [PATCH 2/3] Only show Pre-Release when available --- .../templates/allianceauth/admin-status/overview.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/allianceauth/templates/allianceauth/admin-status/overview.html b/allianceauth/templates/allianceauth/admin-status/overview.html index afc4757f..4a4a2d06 100644 --- a/allianceauth/templates/allianceauth/admin-status/overview.html +++ b/allianceauth/templates/allianceauth/admin-status/overview.html @@ -46,20 +46,18 @@ {% if not latest_patch %}
    {% trans "Update available" %}{% endif %}

    -
  • + {% if latest_beta %} +
  • {% trans "Latest Pre-Release" %}

    - {% if latest_beta %} {{ latest_beta_version }} - {% if not latest_patch %}
    {% trans "Pre-Release available" %}{% endif %} - {% else %} - {% trans "No Current Pre-Release" %} - {% endif %} +
    {% trans "Pre-Release available" %}

  • + {% endif %} From b7d7f7b8ce91bb92f6cc6037a7f62e53ea9aca09 Mon Sep 17 00:00:00 2001 From: AaronKable Date: Thu, 11 Jun 2020 10:47:05 +0800 Subject: [PATCH 3/3] latest stable --- allianceauth/templates/allianceauth/admin-status/overview.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/allianceauth/templates/allianceauth/admin-status/overview.html b/allianceauth/templates/allianceauth/admin-status/overview.html index 4a4a2d06..f246dbed 100644 --- a/allianceauth/templates/allianceauth/admin-status/overview.html +++ b/allianceauth/templates/allianceauth/admin-status/overview.html @@ -37,7 +37,7 @@

  • -
    {% trans "Latest Version" %}
    +
    {% trans "Latest Stable" %}