mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-08 16:43:47 +01:00
parent
fb1d33d27a
commit
5a0aa636f3
@ -19,6 +19,7 @@ from flask import *
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from wtforms import *
|
from wtforms import *
|
||||||
|
from wtforms.ext.sqlalchemy.fields import QuerySelectField
|
||||||
from wtforms.validators import *
|
from wtforms.validators import *
|
||||||
|
|
||||||
from app.utils import *
|
from app.utils import *
|
||||||
@ -37,6 +38,11 @@ class EditScreenshotForm(FlaskForm):
|
|||||||
submit = SubmitField("Save")
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
|
|
||||||
|
class EditPackageScreenshotsForm(FlaskForm):
|
||||||
|
cover_image = QuerySelectField("Cover Image", [DataRequired()], allow_blank=True, get_pk=lambda a: a.id, get_label=lambda a: a.title)
|
||||||
|
submit = SubmitField("Save")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/packages/<author>/<name>/screenshots/", methods=["GET", "POST"])
|
@bp.route("/packages/<author>/<name>/screenshots/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@is_package_page
|
@is_package_page
|
||||||
@ -47,6 +53,9 @@ def screenshots(package):
|
|||||||
if package.screenshots.count() == 0:
|
if package.screenshots.count() == 0:
|
||||||
return redirect(package.getNewScreenshotURL())
|
return redirect(package.getNewScreenshotURL())
|
||||||
|
|
||||||
|
form = EditPackageScreenshotsForm(obj=package)
|
||||||
|
form.cover_image.query = package.screenshots
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
order = request.form.get("order")
|
order = request.form.get("order")
|
||||||
if order:
|
if order:
|
||||||
@ -62,7 +71,11 @@ def screenshots(package):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
return render_template("packages/screenshots.html", package=package)
|
if form.validate_on_submit():
|
||||||
|
form.populate_obj(package)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return render_template("packages/screenshots.html", package=package, form=form)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/packages/<author>/<name>/screenshots/new/", methods=["GET", "POST"])
|
@bp.route("/packages/<author>/<name>/screenshots/new/", methods=["GET", "POST"])
|
||||||
@ -99,6 +112,7 @@ def create_screenshot(package):
|
|||||||
|
|
||||||
return render_template("packages/screenshot_new.html", package=package, form=form)
|
return render_template("packages/screenshot_new.html", package=package, form=form)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/packages/<author>/<name>/screenshots/<id>/edit/", methods=["GET", "POST"])
|
@bp.route("/packages/<author>/<name>/screenshots/<id>/edit/", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@is_package_page
|
@is_package_page
|
||||||
|
@ -308,9 +308,12 @@ class Package(db.Model):
|
|||||||
releases = db.relationship("PackageRelease", back_populates="package",
|
releases = db.relationship("PackageRelease", back_populates="package",
|
||||||
lazy="dynamic", order_by=db.desc("package_release_releaseDate"), cascade="all, delete, delete-orphan")
|
lazy="dynamic", order_by=db.desc("package_release_releaseDate"), cascade="all, delete, delete-orphan")
|
||||||
|
|
||||||
screenshots = db.relationship("PackageScreenshot", back_populates="package",
|
screenshots = db.relationship("PackageScreenshot", back_populates="package", foreign_keys="PackageScreenshot.package_id",
|
||||||
lazy="dynamic", order_by=db.asc("package_screenshot_order"), cascade="all, delete, delete-orphan")
|
lazy="dynamic", order_by=db.asc("package_screenshot_order"), cascade="all, delete, delete-orphan")
|
||||||
|
|
||||||
|
cover_image_id = db.Column(db.Integer, db.ForeignKey("package_screenshot.id"), nullable=True, default=None)
|
||||||
|
cover_image = db.relationship("PackageScreenshot", uselist=False, foreign_keys=[cover_image_id])
|
||||||
|
|
||||||
maintainers = db.relationship("User", secondary=maintainers)
|
maintainers = db.relationship("User", secondary=maintainers)
|
||||||
|
|
||||||
threads = db.relationship("Thread", back_populates="package", order_by=db.desc("thread_created_at"),
|
threads = db.relationship("Thread", back_populates="package", order_by=db.desc("thread_created_at"),
|
||||||
|
@ -63,6 +63,17 @@
|
|||||||
{{ _("Reordering requires JavaScript.") }}
|
{{ _("Reordering requires JavaScript.") }}
|
||||||
</p>
|
</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
|
|
||||||
|
<h2>{{ _("Cover Image") }}</h2>
|
||||||
|
|
||||||
|
{% from "macros/forms.html" import render_submit_field, render_field %}
|
||||||
|
<form action="" method="POST" class="form" role="form">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
|
{{ render_field(form.cover_image, tabindex=220) }}
|
||||||
|
|
||||||
|
{{ render_submit_field(form.submit, tabindex=280) }}
|
||||||
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
|
@ -27,8 +27,9 @@
|
|||||||
{% set release = package.getDownloadRelease() %}
|
{% set release = package.getDownloadRelease() %}
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
{% set cover_image = package.cover_image.url or package.getMainScreenshotURL() %}
|
||||||
<header class="jumbotron pb-3"
|
<header class="jumbotron pb-3"
|
||||||
style="background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.7)), url('{{ package.getMainScreenshotURL() }}');
|
style="background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.7)), url('{{ cover_image }}');
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: center;">
|
background-position: center;">
|
||||||
|
30
migrations/versions/8d22def23c8b_.py
Normal file
30
migrations/versions/8d22def23c8b_.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 8d22def23c8b
|
||||||
|
Revises: 42b14763c95e
|
||||||
|
Create Date: 2020-12-10 22:23:32.291613
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '8d22def23c8b'
|
||||||
|
down_revision = 'a9c1c08bf956'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('package', sa.Column('cover_image_id', sa.Integer(), nullable=True))
|
||||||
|
op.create_foreign_key(None, 'package', 'package_screenshot', ['cover_image_id'], ['id'])
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint(None, 'package', type_='foreignkey')
|
||||||
|
op.drop_column('package', 'cover_image_id')
|
||||||
|
# ### end Alembic commands ###
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Create a database migration, and copy it back to the host.
|
# Create a database migration, and copy it back to the host.
|
||||||
|
|
||||||
docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db revision"
|
docker exec contentdb_app_1 sh -c "FLASK_CONFIG=../config.cfg FLASK_APP=app/__init__.py flask db migrate"
|
||||||
docker exec -u root contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/"
|
docker exec -u root contentdb_app_1 sh -c "cp /home/cdb/migrations/versions/* /source/migrations/versions/"
|
||||||
|
|
||||||
USER=$(whoami)
|
USER=$(whoami)
|
||||||
|
Loading…
Reference in New Issue
Block a user