mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
parent
fc7739be2c
commit
cb5fa4d6e7
@ -18,8 +18,7 @@
|
|||||||
from urllib.parse import quote as urlescape
|
from urllib.parse import quote as urlescape
|
||||||
|
|
||||||
import flask_menu as menu
|
import flask_menu as menu
|
||||||
from celery import uuid
|
from flask import render_template
|
||||||
from flask import render_template, flash
|
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from sqlalchemy import or_, func
|
from sqlalchemy import or_, func
|
||||||
@ -30,11 +29,12 @@ from wtforms.validators import *
|
|||||||
|
|
||||||
from app.querybuilder import QueryBuilder
|
from app.querybuilder import QueryBuilder
|
||||||
from app.rediscache import has_key, set_key
|
from app.rediscache import has_key, set_key
|
||||||
from app.tasks.importtasks import importRepoScreenshot, checkZipRelease
|
from app.tasks.importtasks import importRepoScreenshot
|
||||||
from app.utils import *
|
from app.utils import *
|
||||||
from . import bp, get_package_tabs
|
from . import bp, get_package_tabs
|
||||||
from ...logic.LogicError import LogicError
|
from ...logic.LogicError import LogicError
|
||||||
from ...logic.packages import do_edit_package
|
from ...logic.packages import do_edit_package
|
||||||
|
from app.models.packages import PackageProvides
|
||||||
|
|
||||||
|
|
||||||
@menu.register_menu(bp, ".mods", "Mods", order=11, endpoint_arguments_constructor=lambda: { 'type': 'mod' })
|
@menu.register_menu(bp, ".mods", "Mods", order=11, endpoint_arguments_constructor=lambda: { 'type': 'mod' })
|
||||||
@ -118,26 +118,36 @@ def getReleases(package):
|
|||||||
@bp.route("/packages/<author>/<name>/")
|
@bp.route("/packages/<author>/<name>/")
|
||||||
@is_package_page
|
@is_package_page
|
||||||
def view(package):
|
def view(package):
|
||||||
alternatives = None
|
show_similar = not package.approved and (
|
||||||
if package.type == PackageType.MOD:
|
current_user in package.maintainers or
|
||||||
alternatives = Package.query \
|
package.checkPerm(current_user, Permission.APPROVE_NEW))
|
||||||
.filter_by(name=package.name, type=PackageType.MOD) \
|
|
||||||
.filter(Package.id != package.id, Package.state!=PackageState.DELETED) \
|
packages_modnames = None
|
||||||
|
similar_topics = 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)) \
|
.order_by(db.desc(Package.score)) \
|
||||||
.all()
|
.all()
|
||||||
|
|
||||||
|
similar_topics = ForumTopic.query \
|
||||||
show_similar_topics = current_user == package.author or \
|
|
||||||
package.checkPerm(current_user, Permission.APPROVE_NEW)
|
|
||||||
|
|
||||||
similar_topics = None if not show_similar_topics else \
|
|
||||||
ForumTopic.query \
|
|
||||||
.filter_by(name=package.name) \
|
.filter_by(name=package.name) \
|
||||||
.filter(ForumTopic.topic_id != package.forums) \
|
.filter(ForumTopic.topic_id != package.forums) \
|
||||||
.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \
|
.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \
|
||||||
.order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \
|
.order_by(db.asc(ForumTopic.name), db.asc(ForumTopic.title)) \
|
||||||
.all()
|
.all()
|
||||||
|
|
||||||
|
packages_uses = None
|
||||||
|
if package.type == PackageType.MOD:
|
||||||
|
packages_uses = Package.query.filter(
|
||||||
|
Package.type == PackageType.MOD,
|
||||||
|
Package.id != package.id,
|
||||||
|
Package.state != PackageState.DELETED,
|
||||||
|
Package.dependencies.any(
|
||||||
|
Dependency.meta_package_id.in_([p.id for p in package.provides]))) \
|
||||||
|
.order_by(db.desc(Package.score)).limit(6).all()
|
||||||
|
|
||||||
releases = getReleases(package)
|
releases = getReleases(package)
|
||||||
|
|
||||||
review_thread = package.review_thread
|
review_thread = package.review_thread
|
||||||
@ -172,8 +182,8 @@ def view(package):
|
|||||||
has_review = current_user.is_authenticated and PackageReview.query.filter_by(package=package, author=current_user).count() > 0
|
has_review = current_user.is_authenticated and PackageReview.query.filter_by(package=package, author=current_user).count() > 0
|
||||||
|
|
||||||
return render_template("packages/view.html",
|
return render_template("packages/view.html",
|
||||||
package=package, releases=releases,
|
package=package, releases=releases, packages_uses=packages_uses,
|
||||||
alternatives=alternatives, similar_topics=similar_topics,
|
packages_modnames=packages_modnames, similar_topics=similar_topics,
|
||||||
review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl,
|
review_thread=review_thread, topic_error=topic_error, topic_error_lvl=topic_error_lvl,
|
||||||
threads=threads.all(), has_review=has_review)
|
threads=threads.all(), has_review=has_review)
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class PackagePropertyKey(enum.Enum):
|
|||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
provides = db.Table("provides",
|
PackageProvides = db.Table("provides",
|
||||||
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
|
db.Column("package_id", db.Integer, db.ForeignKey("package.id"), primary_key=True),
|
||||||
db.Column("metapackage_id", db.Integer, db.ForeignKey("meta_package.id"), primary_key=True)
|
db.Column("metapackage_id", db.Integer, db.ForeignKey("meta_package.id"), primary_key=True)
|
||||||
)
|
)
|
||||||
@ -296,7 +296,7 @@ class Package(db.Model):
|
|||||||
issueTracker = db.Column(db.String(200), nullable=True)
|
issueTracker = db.Column(db.String(200), nullable=True)
|
||||||
forums = db.Column(db.Integer, nullable=True)
|
forums = db.Column(db.Integer, nullable=True)
|
||||||
|
|
||||||
provides = db.relationship("MetaPackage", secondary=provides, order_by=db.asc("name"), back_populates="packages")
|
provides = db.relationship("MetaPackage", secondary=PackageProvides, order_by=db.asc("name"), back_populates="packages")
|
||||||
|
|
||||||
dependencies = db.relationship("Dependency", back_populates="depender", lazy="dynamic", foreign_keys=[Dependency.depender_id])
|
dependencies = db.relationship("Dependency", back_populates="depender", lazy="dynamic", foreign_keys=[Dependency.depender_id])
|
||||||
|
|
||||||
@ -615,7 +615,7 @@ class MetaPackage(db.Model):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
dependencies = db.relationship("Dependency", back_populates="meta_package", lazy="dynamic")
|
dependencies = db.relationship("Dependency", back_populates="meta_package", lazy="dynamic")
|
||||||
packages = db.relationship("Package", lazy="dynamic", back_populates="provides", secondary=provides)
|
packages = db.relationship("Package", lazy="dynamic", back_populates="provides", secondary=PackageProvides)
|
||||||
|
|
||||||
mp_name_valid = db.CheckConstraint("name ~* '^[a-z0-9_]+$'")
|
mp_name_valid = db.CheckConstraint("name ~* '^[a-z0-9_]+$'")
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% macro render_banners(package, current_user, topic_error, topic_error_lvl, similar_topics) -%}
|
{% macro render_banners(package, current_user, topic_error, topic_error_lvl, show_modname_warning) -%}
|
||||||
|
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
<span class="col">
|
<span class="col">
|
||||||
@ -82,13 +82,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if similar_topics %}
|
{% if show_modname_warning %}
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
Please make sure that this package has the right to
|
Please make sure that this package has the right to all the technical names it provides.
|
||||||
the name '{{ package.name }}'.
|
See the <a href="/policy_and_guidance/">Inclusion Policy</a> for more info.
|
||||||
See the
|
|
||||||
<a href="/policy_and_guidance/">Inclusion Policy</a>
|
|
||||||
for more info.
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@
|
|||||||
<section class="my-4 pb-3" style="border-bottom: 1px solid rgba(0,0,0,0.5);">
|
<section class="my-4 pb-3" style="border-bottom: 1px solid rgba(0,0,0,0.5);">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% from "macros/package_approval.html" import render_banners %}
|
{% from "macros/package_approval.html" import render_banners %}
|
||||||
{{ render_banners(package, current_user, topic_error, topic_error_lvl, similar_topics) }}
|
{{ render_banners(package, current_user, topic_error, topic_error_lvl, similar_topics or packages_modnames) }}
|
||||||
|
|
||||||
{% if review_thread and review_thread.checkPerm(current_user, "SEE_THREAD") %}
|
{% if review_thread and review_thread.checkPerm(current_user, "SEE_THREAD") %}
|
||||||
<h2>{% if review_thread.private %}🔒{% endif %} {{ review_thread.title }}</h2>
|
<h2>{% if review_thread.private %}🔒{% endif %} {{ review_thread.title }}</h2>
|
||||||
@ -265,15 +265,34 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{ render_reviews(package.reviews, current_user) }}
|
{{ render_reviews(package.reviews, current_user) }}
|
||||||
|
|
||||||
{% if alternatives %}
|
{% if packages_uses %}
|
||||||
<h2>Related</h2>
|
<h2>Used By</h2>
|
||||||
|
|
||||||
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
{% from "macros/packagegridtile.html" import render_pkggrid %}
|
||||||
{{ render_pkggrid(alternatives) }}
|
{{ 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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% if similar_topics %}
|
{% if similar_topics %}
|
||||||
<h2>Similar Forum Topics</h2>
|
<h3>Similar Forum Topics</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for t in similar_topics %}
|
{% for t in similar_topics %}
|
||||||
<li>
|
<li>
|
||||||
@ -286,6 +305,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<aside class="col-md-3 info-sidebar">
|
<aside class="col-md-3 info-sidebar">
|
||||||
|
Loading…
Reference in New Issue
Block a user