Add modname uniqueness page

This commit is contained in:
rubenwardy 2021-07-29 19:34:47 +01:00
parent ff846f4478
commit 447f3e2d5b
4 changed files with 87 additions and 50 deletions

@ -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/<author>/<name>/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)

@ -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) -%}
<div class="row mb-4">
<span class="col">
@ -82,10 +82,16 @@
</div>
{% endif %}
{% if show_modname_warning %}
{% if conflicting_modnames %}
<div class="alert alert-warning">
Please make sure that this package has the right to all the technical names it provides.
See the <a href="/policy_and_guidance/">Inclusion Policy</a> for more info.
<a class="float-right btn btn-sm btn-warning" href="{{ package.getURL('packages.similar') }}">
More info
</a>
{% 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 %}
</div>
{% endif %}

@ -0,0 +1,45 @@
{% extends "base.html" %}
{% block title %}
Modname Uniqueness
{% endblock %}
{% block content %}
<h1><a href="{{ package.getURL("packages.view") }}">{{ package.title }}</a></h1>
<h2>{{ self.title() }}</h2>
{% if packages_modnames %}
<h3>Packages sharing provided mods</h3>
<p class="text-muted">
This package contains modnames that are present in the following packages:
</p>
{% for metapackage, packages in packages_modnames.items() %}
<h4>{{ metapackage.name }}</h4>
<ul>
{% for pkg in packages %}
<li>
<a href="{{ pkg.getURL('packages.view') }}">
{{ _("%(title)s by %(author)s", title=pkg.title, author=pkg.author.display_name) }}
</a>
[{{ pkg.type.value }}]
</li>
{% endfor %}
</ul>
{% endfor %}
{% endif %}
{% if similar_topics %}
<h3>Similar Forum Topics</h3>
<ul>
{% for t in similar_topics %}
<li>
[{{ t.type.value }}]
<a href="https://forum.minetest.net/viewtopic.php?t={{ t.topic_id }}">
{{ t.title }} by {{ t.author.display_name }}
</a>
{% if t.wip %}[WIP]{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

@ -185,7 +185,7 @@
<section class="my-4 pb-3" style="border-bottom: 1px solid rgba(0,0,0,0.5);">
<div class="container">
{% 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") %}
<h2>{% if review_thread.private %}&#x1f512;{% endif %} {{ review_thread.title }}</h2>
@ -270,42 +270,6 @@
{% from "macros/packagegridtile.html" import render_pkggrid %}
{{ render_pkggrid(packages_uses) }}
{% endif %}
{% if packages_modnames or similar_topics %}
<h2>Modname uniqueness</h2>
{% if packages_modnames %}
<h3>Packages sharing provided mods</h3>
<p class="text-muted">
This package contains modnames that are present in the following packages:
</p>
<ul>
{% for pkg in packages_modnames %}
<li>
<a href="{{ pkg.getURL('packages.view') }}">
{{ _("%(title)s by %(author)s", title=pkg.title, author=pkg.author.display_name) }}
</a>
[{{ pkg.type.value }}]
</li>
{% endfor %}
</ul>
{% endif %}
{% if similar_topics %}
<h3>Similar Forum Topics</h3>
<ul>
{% for t in similar_topics %}
<li>
[{{ t.type.value }}]
<a href="https://forum.minetest.net/viewtopic.php?t={{ t.topic_id }}">
{{ t.title }} by {{ t.author.display_name }}
</a>
{% if t.wip %}[WIP]{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
</div>
<aside class="col-md-3 info-sidebar">