2 # Copyright (C) 2018 rubenwardy
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from flask_user import *
21 from app.models import *
22 from flask_wtf import FlaskForm
24 from wtforms.validators import *
25 from app.utils import rank_required
27 @bp.route("/versions/")
28 @rank_required(UserRank.MODERATOR)
30 return render_template("admin/versions/list.html", versions=MinetestRelease.query.order_by(db.asc(MinetestRelease.id)).all())
32 class VersionForm(FlaskForm):
33 name = StringField("Name", [InputRequired(), Length(3,100)])
34 protocol = IntegerField("Protocol")
35 submit = SubmitField("Save")
37 @bp.route("/versions/new/", methods=["GET", "POST"])
38 @bp.route("/versions/<name>/edit/", methods=["GET", "POST"])
39 @rank_required(UserRank.MODERATOR)
40 def create_edit_version(name=None):
43 version = MinetestRelease.query.filter_by(name=name).first()
47 form = VersionForm(formdata=request.form, obj=version)
48 if request.method == "POST" and form.validate():
50 version = MinetestRelease(form.name.data)
51 db.session.add(version)
52 flash("Created version " + form.name.data, "success")
54 flash("Updated version " + form.name.data, "success")
56 form.populate_obj(version)
58 return redirect(url_for("admin.version_list"))
60 return render_template("admin/versions/edit.html", version=version, form=form)