mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 23:17:37 +01:00
Add MinetestRelease editor
This commit is contained in:
parent
f112756b04
commit
0e5c1f83ff
@ -9,6 +9,7 @@
|
||||
<li><a href="{{ url_for('user_list_page') }}">User list</a></li>
|
||||
<li><a href="{{ url_for('tag_list_page') }}">Tag Editor</a></li>
|
||||
<li><a href="{{ url_for('license_list_page') }}">License Editor</a></li>
|
||||
<li><a href="{{ url_for('version_list_page') }}">Version Editor</a></li>
|
||||
<li><a href="{{ url_for('switch_user_page') }}">Sign in as another user</a></li>
|
||||
</ul>
|
||||
|
||||
|
25
app/templates/admin/versions/edit.html
Normal file
25
app/templates/admin/versions/edit.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% if version %}
|
||||
Edit {{ version.name }}
|
||||
{% else %}
|
||||
New Minetest Version
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<a href="{{ url_for('version_list_page') }}">Back to list</a> |
|
||||
<a href="{{ url_for('createedit_version_page') }}">New Version</a>
|
||||
</p>
|
||||
|
||||
{% from "macros/forms.html" import render_field, render_submit_field %}
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_field(form.name) }}
|
||||
{{ render_field(form.protocol) }}
|
||||
{{ render_submit_field(form.submit) }}
|
||||
</form>
|
||||
{% endblock %}
|
16
app/templates/admin/versions/list.html
Normal file
16
app/templates/admin/versions/list.html
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Minetest Versions
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<a href="{{ url_for('createedit_version_page') }}">New Tag</a>
|
||||
</p>
|
||||
<ul>
|
||||
{% for v in versions %}
|
||||
<li><a href="{{ url_for('createedit_version_page', name=v.name) }}">{{ v.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
@ -15,4 +15,4 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from . import admin, licenseseditor, tagseditor, todo
|
||||
from . import admin, licenseseditor, tagseditor, versioneditor, todo
|
||||
|
60
app/views/admin/versioneditor.py
Normal file
60
app/views/admin/versioneditor.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Content DB
|
||||
# Copyright (C) 2018 rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from flask import *
|
||||
from flask_user import *
|
||||
from app import app
|
||||
from app.models import *
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import *
|
||||
from wtforms.validators import *
|
||||
from app.utils import rank_required
|
||||
|
||||
@app.route("/versions/")
|
||||
@rank_required(UserRank.MODERATOR)
|
||||
def version_list_page():
|
||||
return render_template("admin/versions/list.html", versions=MinetestRelease.query.order_by(db.asc(MinetestRelease.id)).all())
|
||||
|
||||
class VersionForm(FlaskForm):
|
||||
name = StringField("Name", [InputRequired(), Length(3,100)])
|
||||
protocol = IntegerField("Protocol")
|
||||
submit = SubmitField("Save")
|
||||
|
||||
@app.route("/versions/new/", methods=["GET", "POST"])
|
||||
@app.route("/versions/<name>/edit/", methods=["GET", "POST"])
|
||||
@rank_required(UserRank.MODERATOR)
|
||||
def createedit_version_page(name=None):
|
||||
version = None
|
||||
if name is not None:
|
||||
version = MinetestRelease.query.filter_by(name=name).first()
|
||||
if version is None:
|
||||
abort(404)
|
||||
|
||||
form = VersionForm(formdata=request.form, obj=version)
|
||||
if request.method == "POST" and form.validate():
|
||||
if version is None:
|
||||
version = MinetestRelease(form.name.data)
|
||||
db.session.add(version)
|
||||
flash("Created version " + form.name.data, "success")
|
||||
else:
|
||||
flash("Updated version " + form.name.data, "success")
|
||||
|
||||
form.populate_obj(version)
|
||||
db.session.commit()
|
||||
return redirect(url_for("version_list_page"))
|
||||
|
||||
return render_template("admin/versions/edit.html", version=version, form=form)
|
Loading…
Reference in New Issue
Block a user