2022-02-01 22:22:28 +01:00
|
|
|
# ContentDB
|
|
|
|
# Copyright (C) 2022 rubenwardy
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from flask import render_template, abort
|
|
|
|
from sqlalchemy.orm import joinedload
|
|
|
|
|
|
|
|
from . import bp
|
|
|
|
from app.utils import is_package_page
|
2023-06-19 20:32:36 +02:00
|
|
|
from app.models import Package, PackageType, PackageState, db, PackageRelease
|
2022-02-01 22:22:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/packages/<author>/<name>/hub/")
|
|
|
|
@is_package_page
|
|
|
|
def game_hub(package: Package):
|
|
|
|
if package.type != PackageType.GAME:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
def join(query):
|
|
|
|
return query.options(
|
|
|
|
joinedload(Package.license),
|
|
|
|
joinedload(Package.media_license))
|
|
|
|
|
2023-06-27 21:41:07 +02:00
|
|
|
query = Package.query.filter(Package.supported_games.any(game=package, supports=True), Package.state==PackageState.APPROVED)
|
2022-02-01 22:22:28 +01:00
|
|
|
count = query.count()
|
|
|
|
|
|
|
|
new = join(query.order_by(db.desc(Package.approved_at))).limit(4).all()
|
|
|
|
pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all()
|
|
|
|
pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(8).all()
|
|
|
|
high_reviewed = join(query.order_by(db.desc(Package.score - Package.score_downloads))) \
|
|
|
|
.filter(Package.reviews.any()).limit(4).all()
|
|
|
|
|
|
|
|
updated = db.session.query(Package).select_from(PackageRelease).join(Package) \
|
2023-06-27 21:41:07 +02:00
|
|
|
.filter(Package.supported_games.any(game=package, supports=True), Package.state==PackageState.APPROVED) \
|
2024-06-22 16:18:58 +02:00
|
|
|
.order_by(db.desc(PackageRelease.created_at)) \
|
2022-02-01 22:22:28 +01:00
|
|
|
.limit(20).all()
|
|
|
|
updated = updated[:4]
|
|
|
|
|
|
|
|
return render_template("packages/game_hub.html", package=package, count=count,
|
2023-01-12 20:48:18 +01:00
|
|
|
new=new, updated=updated, pop_mod=pop_mod, pop_txp=pop_txp,
|
2022-02-01 22:22:28 +01:00
|
|
|
high_reviewed=high_reviewed)
|