From 91aab3198aeb2f82c2d2817ff84372818c7bc39a Mon Sep 17 00:00:00 2001 From: Li Chaoran Date: Mon, 19 Jun 2023 16:14:08 +0800 Subject: [PATCH] add packages count at homepage Signed-off-by: Li Chaoran --- frontend/coprs_frontend/config/copr.conf | 3 ++- frontend/coprs_frontend/coprs/config.py | 2 ++ frontend/coprs_frontend/coprs/logic/packages_logic.py | 7 +++++++ .../coprs_frontend/coprs/templates/homepage_header.html | 5 ++++- .../coprs_frontend/coprs/views/coprs_ns/coprs_general.py | 5 ++++- pylintrc | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/coprs_frontend/config/copr.conf b/frontend/coprs_frontend/config/copr.conf index c5d59be7d..a1b417d35 100644 --- a/frontend/coprs_frontend/config/copr.conf +++ b/frontend/coprs_frontend/config/copr.conf @@ -171,7 +171,8 @@ HIDE_IMPORT_LOG_AFTER_DAYS = 14 # OIDC_TOKEN_URL="" # OIDC_USERINFO_URL="" - +# Whether to show a total packages count at homepage +# PACKAGES_COUNT = False ############################# ##### DEBUGGING Section ##### diff --git a/frontend/coprs_frontend/coprs/config.py b/frontend/coprs_frontend/coprs/config.py index 03ef16c1a..c135be6b2 100644 --- a/frontend/coprs_frontend/coprs/config.py +++ b/frontend/coprs_frontend/coprs/config.py @@ -175,6 +175,8 @@ class Config(object): # OIDC is opt-in OIDC_LOGIN = False + PACKAGES_COUNT = False + class ProductionConfig(Config): DEBUG = False # SECRET_KEY = "put_some_secret_here" diff --git a/frontend/coprs_frontend/coprs/logic/packages_logic.py b/frontend/coprs_frontend/coprs/logic/packages_logic.py index f364ba55e..84f23d6e7 100644 --- a/frontend/coprs_frontend/coprs/logic/packages_logic.py +++ b/frontend/coprs_frontend/coprs/logic/packages_logic.py @@ -21,6 +21,13 @@ class PackagesLogic(object): + @classmethod + def count(cls): + """ + Get packages count + """ + return models.Package.query.count() + @classmethod def get_by_id(cls, package_id): return models.Package.query.filter(models.Package.id == package_id) diff --git a/frontend/coprs_frontend/coprs/templates/homepage_header.html b/frontend/coprs_frontend/coprs/templates/homepage_header.html index a19219844..99ca6a0a9 100644 --- a/frontend/coprs_frontend/coprs/templates/homepage_header.html +++ b/frontend/coprs_frontend/coprs/templates/homepage_header.html @@ -1,5 +1,8 @@

Copr hosts {{ projects_count |int_with_commas }} projects from
- {{ users_count |int_with_commas }} Fedora users + {{ users_count |int_with_commas }} Fedora users{% if packages_count %} with +
+ {{ packages_count | int_with_commas }} packages + {% endif %}

diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py index f370e86a1..88325a150 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py @@ -45,7 +45,7 @@ from coprs.views.coprs_ns import coprs_ns -from coprs.logic import builds_logic, coprs_logic, actions_logic, users_logic +from coprs.logic import builds_logic, coprs_logic, actions_logic, users_logic, packages_logic from coprs.helpers import generate_repo_url, \ url_for_copr_view, CounterStatType @@ -86,6 +86,8 @@ def coprs_show(page=1): # users_count = models.User.query.count() users_count = users_logic.UsersLogic.get_multiple_with_projects().count() + packages_count = packages_logic.PackagesLogic.count() if app.config.get("PACKAGES_COUNT", False) else None + # flask.g.user is none when no user is logged - showing builds from everyone # TODO: builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 5) takes too much time, optimize sql # users_builds = builds_logic.BuildsLogic.get_recent_tasks(flask.g.user, 5) @@ -100,6 +102,7 @@ def coprs_show(page=1): recent=recent, projects_count=projects_count, users_count=users_count, + packages_count=packages_count, paginator=paginator, tasks_info=ComplexLogic.get_queue_sizes_cached(), users_builds=users_builds, diff --git a/pylintrc b/pylintrc index 97bb61a9c..717d11c85 100644 --- a/pylintrc +++ b/pylintrc @@ -129,7 +129,7 @@ max-attributes=7 min-public-methods=1 # Maximum number of public methods for a class (see R0904). -max-public-methods=20 +max-public-methods=21 [FORMAT]