From 57b736b1df8b6d05698a51fc41b9ed2961d878a1 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 19 May 2023 19:40:03 +0100 Subject: [PATCH] Todo: Add game support status --- app/blueprints/todo/user.py | 39 +++++++++++++++---- app/templates/todo/game_support.html | 58 ++++++++++++++++++++++++++++ app/templates/todo/user.html | 32 +++++++++++++++ 3 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 app/templates/todo/game_support.html diff --git a/app/blueprints/todo/user.py b/app/blueprints/todo/user.py index a035e75d..104d7389 100644 --- a/app/blueprints/todo/user.py +++ b/app/blueprints/todo/user.py @@ -20,7 +20,7 @@ from flask_login import current_user, login_required from sqlalchemy import or_, and_ from app.models import User, Package, PackageState, PackageScreenshot, PackageUpdateConfig, ForumTopic, db, \ - PackageRelease, Permission, NotificationType, AuditSeverity, UserRank + PackageRelease, Permission, NotificationType, AuditSeverity, UserRank, PackageType from app.tasks.importtasks import makeVCSRelease from app.utils import addNotification, addAuditLog @@ -51,6 +51,17 @@ def view_user(username=None): Package.state == PackageState.CHANGES_NEEDED)) \ .order_by(db.asc(Package.created_at)).all() + outdated_packages = user.maintained_packages \ + .filter(Package.state != PackageState.DELETED, + Package.update_config.has(PackageUpdateConfig.outdated_at.isnot(None))) \ + .order_by(db.asc(Package.title)).all() + + missing_game_support = user.maintained_packages.filter( + Package.state != PackageState.DELETED, + Package.type.in_([PackageType.MOD, PackageType.TXP]), + ~Package.supported_games.any()) \ + .order_by(db.asc(Package.title)).all() + packages_with_no_screenshots = user.maintained_packages.filter( ~Package.screenshots.any(), Package.state == PackageState.APPROVED).all() @@ -60,11 +71,6 @@ def view_user(username=None): PackageScreenshot.height < PackageScreenshot.SOFT_MIN_SIZE[1]))) \ .all() - outdated_packages = user.maintained_packages \ - .filter(Package.state != PackageState.DELETED, - Package.update_config.has(PackageUpdateConfig.outdated_at.isnot(None))) \ - .order_by(db.asc(Package.title)).all() - topics_to_add = ForumTopic.query \ .filter_by(author_id=user.id) \ .filter(~ db.exists().where(Package.forums == ForumTopic.topic_id)) \ @@ -77,7 +83,7 @@ def view_user(username=None): return render_template("todo/user.html", current_tab="user", user=user, unapproved_packages=unapproved_packages, outdated_packages=outdated_packages, - needs_tags=needs_tags, topics_to_add=topics_to_add, + missing_game_support=missing_game_support, needs_tags=needs_tags, topics_to_add=topics_to_add, packages_with_no_screenshots=packages_with_no_screenshots, packages_with_small_screenshots=packages_with_small_screenshots, screenshot_min_size=PackageScreenshot.HARD_MIN_SIZE, screenshot_rec_size=PackageScreenshot.SOFT_MIN_SIZE) @@ -127,3 +133,22 @@ def apply_all_updates(username): db.session.commit() return redirect(url_for("todo.view_user", username=username)) + + +@bp.route("/user/game_support/") +@bp.route("/users//game_support/") +@login_required +def all_game_support(username=None): + if username is None: + return redirect(url_for("todo.all_game_support", username=current_user.username)) + + user: User = User.query.filter_by(username=username).one_or_404() + if current_user != user and not current_user.rank.atLeast(UserRank.EDITOR): + abort(403) + + packages = user.maintained_packages.filter( + Package.state != PackageState.DELETED, + Package.type.in_([PackageType.MOD, PackageType.TXP])) \ + .order_by(db.asc(Package.title)).all() + + return render_template("todo/game_support.html", user=user, packages=packages) diff --git a/app/templates/todo/game_support.html b/app/templates/todo/game_support.html new file mode 100644 index 00000000..f49710f8 --- /dev/null +++ b/app/templates/todo/game_support.html @@ -0,0 +1,58 @@ +{% extends "base.html" %} + +{% block title %} + {{ _("Game Support for %(username)s", username=user.display_name) }} +{% endblock %} + +{% block content %} + {{ _("Help") }} +

{{ self.title() }}

+

+ {{ _("You should specify the games supported by your mods and texture packs.") }} + {{ _("Specifying game support makes it easier for players to find your content.") }} +

+ + +
+ {% for package in packages %} +
+
+
+ + + + {{ package.title }} + +
+
+ {% set supported_games = package.getSortedSupportedGames() %} + {% if supported_games %} + {% for support in supported_games %} + + {{ _("%(title)s by %(display_name)s", + title=support.game.title, display_name=support.game.author.display_name) }} + + {% endfor %} + {% else %} + + + {{ _("None listed, assumed to support all games") }} + + + {% endif %} +
+ +
+
+ {% else %} +

{{ _("Nothing to do :)") }}

+ {% endfor %} +
+{% endblock %} diff --git a/app/templates/todo/user.html b/app/templates/todo/user.html index a707d3b3..e954292b 100644 --- a/app/templates/todo/user.html +++ b/app/templates/todo/user.html @@ -63,6 +63,38 @@ {% from "macros/todo.html" import render_outdated_packages %} {{ render_outdated_packages(outdated_packages, current_user) }} +
+ + + {{ _("Help") }} + + + {{ _("See game support for your packages") }} + +

{{ _("Missing Game Support") }}

+ {% if missing_game_support %} +

+ {{ _("You should specify the games supported by your mods and texture packs.") }} + {{ _("Specifying game support makes it easier for players to find your content.") }} +

+ {% endif %} +
+ {% for package in missing_game_support %} + + + + + {{ package.title }} + + + {% else %} +

{{ _("Nothing to do :)") }}

+ {% endfor %} +
+

{{ _("Missing Screenshots") }}