mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Merge branch 'paginate-comments'
This commit is contained in:
commit
edacde48e5
3 changed files with 22 additions and 2 deletions
|
@ -6,6 +6,9 @@ O = 0
|
|||
# Default [P]er [P]age
|
||||
PP = 50
|
||||
|
||||
# Default Comments Per Page
|
||||
COMMENTS_PER_PAGE = 10
|
||||
|
||||
# A whitelist of valid PP values
|
||||
PP_WHITELIST = {50, 100, 250}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
from fastapi import Request
|
||||
from sqlalchemy import and_
|
||||
|
||||
from aurweb import config, db, l10n, util
|
||||
from aurweb import config, db, defaults, l10n, util
|
||||
from aurweb.models import PackageBase, User
|
||||
from aurweb.models.package_comaintainer import PackageComaintainer
|
||||
from aurweb.models.package_comment import PackageComment
|
||||
|
@ -31,6 +31,12 @@ def make_context(request: Request, pkgbase: PackageBase,
|
|||
if not context:
|
||||
context = _make_context(request, pkgbase.Name)
|
||||
|
||||
# Per page and offset.
|
||||
offset, per_page = util.sanitize_params(
|
||||
request.query_params.get("O", defaults.O),
|
||||
request.query_params.get("PP", defaults.COMMENTS_PER_PAGE))
|
||||
context["O"] = offset
|
||||
context["PP"] = per_page
|
||||
context["git_clone_uri_anon"] = config.get("options", "git_clone_uri_anon")
|
||||
context["git_clone_uri_priv"] = config.get("options", "git_clone_uri_priv")
|
||||
context["pkgbase"] = pkgbase
|
||||
|
@ -44,9 +50,12 @@ def make_context(request: Request, pkgbase: PackageBase,
|
|||
|
||||
context["packages_count"] = pkgbase.packages.count()
|
||||
context["keywords"] = pkgbase.keywords
|
||||
context["comments_total"] = pkgbase.comments.order_by(
|
||||
PackageComment.CommentTS.desc()
|
||||
).count()
|
||||
context["comments"] = pkgbase.comments.order_by(
|
||||
PackageComment.CommentTS.desc()
|
||||
)
|
||||
).limit(per_page).offset(offset)
|
||||
context["pinned_comments"] = pkgbase.comments.filter(
|
||||
PackageComment.PinnedTS != 0
|
||||
).order_by(PackageComment.CommentTS.desc())
|
||||
|
|
|
@ -33,6 +33,14 @@
|
|||
<span class="text">{{ "Latest Comments" | tr }}</span>
|
||||
<span class="arrow"></span>
|
||||
</h3>
|
||||
{% set page = ((O / PP) | int) %}
|
||||
{% set pages = ((comments_total / PP) | ceil) %}
|
||||
|
||||
{% if pages > 1 %}
|
||||
<p class="comments-header-nav">
|
||||
{{ page | pager_nav(comments_total, prefix) | safe }}
|
||||
<p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% for comment in comments.all() %}
|
||||
{% include "partials/packages/comment.html" %}
|
||||
|
|
Loading…
Add table
Reference in a new issue