From 447f3e2d5b0570583ef4f521491dc6863ec7f33c Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 29 Jul 2021 19:34:47 +0100 Subject: [PATCH] Add modname uniqueness page --- app/blueprints/packages/packages.py | 40 ++++++++++++++----- app/templates/macros/package_approval.html | 14 +++++-- app/templates/packages/similar.html | 45 ++++++++++++++++++++++ app/templates/packages/view.html | 38 +----------------- 4 files changed, 87 insertions(+), 50 deletions(-) create mode 100644 app/templates/packages/similar.html diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index ef2daed..4399267 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -122,22 +122,22 @@ def view(package): current_user in package.maintainers or package.checkPerm(current_user, Permission.APPROVE_NEW)) - packages_modnames = None - similar_topics = None + conflicting_modnames = None if show_similar and package.type != PackageType.TXP: - packages_modnames = Package.query.filter(Package.id != package.id, - Package.state != PackageState.DELETED) \ - .filter(Package.provides.any(PackageProvides.c.metapackage_id.in_([p.id for p in package.provides]))) \ - .order_by(db.desc(Package.score)) \ + conflicting_modnames = db.session.query(MetaPackage.name) \ + .filter(MetaPackage.id.in_([ mp.id for mp in package.provides ])) \ + .filter(MetaPackage.packages.any(Package.id != package.id)) \ .all() - similar_topics = ForumTopic.query \ - .filter_by(name=package.name) \ + conflicting_modnames += db.session.query(ForumTopic.name) \ + .filter(ForumTopic.name.in_([ mp.name for mp in package.provides ])) \ .filter(ForumTopic.topic_id != package.forums) \ .filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \ .order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \ .all() + conflicting_modnames = set([x[0] for x in conflicting_modnames]) + packages_uses = None if package.type == PackageType.MOD: packages_uses = Package.query.filter( @@ -183,7 +183,7 @@ def view(package): return render_template("packages/view.html", package=package, releases=releases, packages_uses=packages_uses, - packages_modnames=packages_modnames, similar_topics=similar_topics, + conflicting_modnames=conflicting_modnames, review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl, threads=threads.all(), has_review=has_review) @@ -577,3 +577,25 @@ def alias_create_edit(package: Package, alias_id: int = None): def share(package): return render_template("packages/share.html", package=package, tabs=get_package_tabs(current_user, package), current_tab="share") + + +@bp.route("/packages///similar/") +@is_package_page +def similar(package): + packages_modnames = {} + for metapackage in package.provides: + packages_modnames[metapackage] = Package.query.filter(Package.id != package.id, + Package.state != PackageState.DELETED) \ + .filter(Package.provides.any(PackageProvides.c.metapackage_id == metapackage.id)) \ + .order_by(db.desc(Package.score)) \ + .all() + + similar_topics = ForumTopic.query \ + .filter_by(name=package.name) \ + .filter(ForumTopic.topic_id != package.forums) \ + .filter(~ db.exists().where(Package.forums == ForumTopic.topic_id)) \ + .order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \ + .all() + + return render_template("packages/similar.html", package=package, + packages_modnames=packages_modnames, similar_topics=similar_topics) diff --git a/app/templates/macros/package_approval.html b/app/templates/macros/package_approval.html index b281ae9..db46f4e 100644 --- a/app/templates/macros/package_approval.html +++ b/app/templates/macros/package_approval.html @@ -1,4 +1,4 @@ -{% macro render_banners(package, current_user, topic_error, topic_error_lvl, show_modname_warning) -%} +{% macro render_banners(package, current_user, topic_error, topic_error_lvl, conflicting_modnames) -%}
@@ -82,10 +82,16 @@
{% endif %} -{% if show_modname_warning %} +{% if conflicting_modnames %}
- Please make sure that this package has the right to all the technical names it provides. - See the Inclusion Policy for more info. + + More info + + {% if conflicting_modnames | length > 4 %} + Please make sure that this package has the right to the names it uses. + {% else %} + Please make sure that this package has the right to the names {{ conflicting_modnames | join(", ") }}. + {% endif %}
{% endif %} diff --git a/app/templates/packages/similar.html b/app/templates/packages/similar.html new file mode 100644 index 0000000..59178d2 --- /dev/null +++ b/app/templates/packages/similar.html @@ -0,0 +1,45 @@ +{% extends "base.html" %} + +{% block title %} +Modname Uniqueness +{% endblock %} + +{% block content %} +

{{ package.title }}

+

{{ self.title() }}

+ + {% if packages_modnames %} +

Packages sharing provided mods

+

+ This package contains modnames that are present in the following packages: +

+ {% for metapackage, packages in packages_modnames.items() %} +

{{ metapackage.name }}

+ + {% endfor %} + {% endif %} + + {% if similar_topics %} +

Similar Forum Topics

+ + {% endif %} +{% endblock %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index efc1f1a..33c891b 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -185,7 +185,7 @@
{% from "macros/package_approval.html" import render_banners %} - {{ render_banners(package, current_user, topic_error, topic_error_lvl, similar_topics or packages_modnames) }} + {{ render_banners(package, current_user, topic_error, topic_error_lvl, conflicting_modnames) }} {% if review_thread and review_thread.checkPerm(current_user, "SEE_THREAD") %}

{% if review_thread.private %}🔒{% endif %} {{ review_thread.title }}

@@ -270,42 +270,6 @@ {% from "macros/packagegridtile.html" import render_pkggrid %} {{ render_pkggrid(packages_uses) }} {% endif %} - - {% if packages_modnames or similar_topics %} -

Modname uniqueness

- - {% if packages_modnames %} -

Packages sharing provided mods

-

- This package contains modnames that are present in the following packages: -

- - {% endif %} - - {% if similar_topics %} -

Similar Forum Topics

- - {% endif %} - {% endif %}