Add mismatched topics editor page

This commit is contained in:
rubenwardy 2024-06-22 10:45:14 +01:00
parent aeca6cbbdb
commit 12545c69ac
4 changed files with 101 additions and 3 deletions

@ -82,7 +82,7 @@ def list_all():
topic = qb.build_topic_query().first()
if qb.search and topic:
return redirect("https://forum.minetest.net/viewtopic.php?t=" + str(topic.topic_id))
return redirect(topic.url)
page = get_int_or_abort(request.args.get("page"), 1)
num = min(40, get_int_or_abort(request.args.get("n"), 100))

@ -17,12 +17,12 @@
from flask import redirect, url_for, abort, render_template, request
from flask_login import current_user, login_required
from sqlalchemy import or_
from sqlalchemy import or_, and_
from app.models import Package, PackageState, PackageScreenshot, PackageUpdateConfig, ForumTopic, db, \
PackageRelease, Permission, UserRank, License, MetaPackage, Dependency, AuditLogEntry, Tag, MinetestRelease
from app.querybuilder import QueryBuilder
from app.utils import get_int_or_abort, is_yes
from app.utils import get_int_or_abort, is_yes, rank_required
from . import bp
@ -188,3 +188,28 @@ def mtver_support():
return render_template("todo/mtver_support.html", current_tab="screenshots",
packages=query.all(), sort_by=sort_by, is_mtm_only=is_mtm_only, current_stable=current_stable)
@bp.route("/todo/topics/mismatch/")
@rank_required(UserRank.EDITOR)
def topics_mismatch():
missing_topics = Package.query.filter(Package.forums.is_not(None)) .filter(~ForumTopic.query.filter(ForumTopic.topic_id == Package.forums).exists()).all()
packages_bad_author = (
db.session.query(Package, ForumTopic)
.select_from(Package)
.join(ForumTopic, Package.forums == ForumTopic.topic_id)
.filter(Package.author_id != ForumTopic.author_id)
.all())
packages_bad_title = (
db.session.query(Package, ForumTopic)
.select_from(Package)
.join(ForumTopic, Package.forums == ForumTopic.topic_id)
.filter(and_(ForumTopic.name != Package.name, ~ForumTopic.title.ilike("%" + Package.title + "%"), ~ForumTopic.title.ilike("%" + Package.name + "%")))
.all())
return render_template("todo/topics_mismatch.html",
missing_topics=missing_topics,
packages_bad_author=packages_bad_author,
packages_bad_title=packages_bad_title)

@ -156,6 +156,10 @@ class ForumTopic(db.Model):
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
@property
def url(self):
return "https://forum.minetest.net/viewtopic.php?t=" + str(self.topic_id)
def get_repo_url(self):
if self.link is None:
return None

@ -0,0 +1,69 @@
{% extends "base.html" %}
{% block title %}
Mismatched Topics
{% endblock %}
{% macro render_topics(pairs) %}
<ul class="list-group">
{% for pair in pairs %}
{% set package = pair[0] %}
{% set topic = pair[1] %}
<li class="list-group-item">
<div class="row">
<a class="col-sm-3 text-muted" style="min-width: 200px;" href="{{ package.get_url('packages.view') }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
src="{{ package.get_thumb_or_placeholder() }}" />
<span class="ps-2">
{{ package.title }} by {{ package.author.display_name }}
</span>
</a>
<a class="col-sm-3" href="{{ topic.url }}">
{{ topic.title }} by {{ topic.author.display_name }}
</a>
<div class="col-sm"></div>
<div class="col-sm-auto">
<a class="btn btn-secondary me-2" href="{{ package.get_url('packages.create_edit') }}">Edit</a>
<a class="btn btn-secondary">Unlink</a>
</div>
</div>
</li>
{% endfor %}
</ul>
{% endmacro %}
{% block content %}
<h1>{{ self.title() }}</h1>
<h2>Missing topics</h2>
<ul class="list-group">
{% for package in missing_topics %}
<li class="list-group-item">
<div class="row">
<a class="col-sm-3 text-muted" style="min-width: 200px;" href="{{ package.get_url('packages.view') }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
src="{{ package.get_thumb_or_placeholder() }}" />
<span class="ps-2">
{{ package.title }} by {{ package.author.display_name }}
</span>
</a>
<div class="col-sm"></div>
<div class="col-sm-auto">
<a class="btn btn-secondary me-2" href="{{ package.get_url('packages.create_edit') }}">Edit</a>
<a class="btn btn-secondary me-2" href="https://forum.minetest.net/viewtopic.php?t={{ package.forums }}">Forums</a>
</div>
</div>
</li>
{% endfor %}
</ul>
<h2>Mismatched authors</h2>
{{ render_topics(packages_bad_author) }}
<h2>Mismatched titles</h2>
{{ render_topics(packages_bad_title) }}
{% endblock %}