Skip to content

Commit

Permalink
add packages count at homepage
Browse files Browse the repository at this point in the history
Signed-off-by: Li Chaoran <[email protected]>
  • Loading branch information
pkking authored and praiskup committed Jun 20, 2023
1 parent 6857443 commit 91aab31
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion frontend/coprs_frontend/config/copr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####
Expand Down
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/coprs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions frontend/coprs_frontend/coprs/logic/packages_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion frontend/coprs_frontend/coprs/templates/homepage_header.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<h2>
Copr hosts <span>{{ projects_count |int_with_commas }}</span> projects from
<br>
<span>{{ users_count |int_with_commas }}</span> Fedora users
<span>{{ users_count |int_with_commas }}</span> Fedora users{% if packages_count %} with
<br>
<span>{{ packages_count | int_with_commas }}</span> packages
{% endif %}
</h2>
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 91aab31

Please sign in to comment.