mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 23:17:37 +01:00
Add ability to bulk change releases
This commit is contained in:
parent
84b996c489
commit
5cd8b35d1f
@ -481,6 +481,10 @@ class Package(db.Model):
|
||||
return url_for("create_edit_editrequest_page",
|
||||
author=self.author.username, name=self.name)
|
||||
|
||||
def getBulkReleaseURL(self):
|
||||
return url_for("bulk_change_release_page",
|
||||
author=self.author.username, name=self.name)
|
||||
|
||||
def getDownloadURL(self):
|
||||
return url_for("package_download_page",
|
||||
author=self.author.username, name=self.name)
|
||||
|
@ -115,7 +115,7 @@
|
||||
|
||||
{% macro render_checkbox_field(field, label=None) -%}
|
||||
{% if not label %}{% set label=field.label.text %}{% endif %}
|
||||
<div class="checkbox">
|
||||
<div class="checkbox {{ kwargs.pop('class_', '') }}">
|
||||
<label>
|
||||
{{ field(type='checkbox', **kwargs) }} {{ label }}
|
||||
</label>
|
||||
|
29
app/templates/packages/release_bulk_change.html
Normal file
29
app/templates/packages/release_bulk_change.html
Normal file
@ -0,0 +1,29 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Create a release | {{ package.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Bulk Change Releases</h1>
|
||||
|
||||
<p class="mb-5">
|
||||
Use this page to set the min and max of all releases for your package.
|
||||
</p>
|
||||
|
||||
{% from "macros/forms.html" import render_field, render_submit_field, render_checkbox_field %}
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<div class="row">
|
||||
{{ render_checkbox_field(form.set_min, class_="col-sm-2") }}
|
||||
{{ render_field(form.min_rel, class_="col-sm-10") }}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{ render_checkbox_field(form.set_max, class_="col-sm-2") }}
|
||||
{{ render_field(form.max_rel, class_="col-sm-10") }}
|
||||
</div>
|
||||
|
||||
{{ render_submit_field(form.submit) }}
|
||||
</form>
|
||||
{% endblock %}
|
@ -237,10 +237,12 @@
|
||||
<div class="card my-4">
|
||||
<div class="card-header">
|
||||
Releases
|
||||
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
|
||||
<a class="float-right"
|
||||
href="{{ package.getCreateReleaseURL() }}">+</a>
|
||||
{% endif %}
|
||||
<div class="float-right">
|
||||
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
|
||||
<a href="{{ package.getBulkReleaseURL() }}">bulk</a>
|
||||
<a href="{{ package.getCreateReleaseURL() }}">+</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for rel in releases %}
|
||||
|
@ -160,3 +160,38 @@ def edit_release_page(package, id):
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
return render_template("packages/release_edit.html", package=package, release=release, form=form)
|
||||
|
||||
|
||||
|
||||
class BulkReleaseForm(FlaskForm):
|
||||
set_min = BooleanField("Set Min")
|
||||
min_rel = QuerySelectField("Minimum Minetest Version", [InputRequired()],
|
||||
query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name)
|
||||
set_max = BooleanField("Set Max")
|
||||
max_rel = QuerySelectField("Maximum Minetest Version", [InputRequired()],
|
||||
query_factory=lambda: MinetestRelease.query.order_by(db.asc(MinetestRelease.id)), get_pk=lambda a: a.id, get_label=lambda a: a.name)
|
||||
submit = SubmitField("Update")
|
||||
|
||||
|
||||
@app.route("/packages/<author>/<name>/releases/bulk_change/", methods=["GET", "POST"])
|
||||
@login_required
|
||||
@is_package_page
|
||||
def bulk_change_release_page(package):
|
||||
if not package.checkPerm(current_user, Permission.MAKE_RELEASE):
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
# Initial form class from post data and default data
|
||||
form = BulkReleaseForm()
|
||||
|
||||
if request.method == "POST" and form.validate():
|
||||
for release in package.releases.all():
|
||||
if form["set_min"].data:
|
||||
release.min_rel = form["min_rel"].data.getActual()
|
||||
if form["set_max"].data:
|
||||
release.max_rel = form["max_rel"].data.getActual()
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
return render_template("packages/release_bulk_change.html", package=package, form=form)
|
||||
|
Loading…
Reference in New Issue
Block a user