diff options
| author | rubenwardy <rw@rubenwardy.com> | 2019-11-15 23:51:42 +0000 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2019-11-15 23:51:42 +0000 |
| commit | 64f131ae27a7332245b5a4eb8e1e4879d7d99578 (patch) | |
| tree | a0b4101ca9c2132a072f1586c0df693583c91cf7 /app/views/admin/versioneditor.py | |
| parent | 015abe5a2507ad02273bc89953016c386aae4457 (diff) | |
| download | cheatdb-64f131ae27a7332245b5a4eb8e1e4879d7d99578.tar.xz | |
Refactor endpoints to use blueprints instead
Diffstat (limited to 'app/views/admin/versioneditor.py')
| -rw-r--r-- | app/views/admin/versioneditor.py | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/app/views/admin/versioneditor.py b/app/views/admin/versioneditor.py deleted file mode 100644 index 6bcf93a..0000000 --- a/app/views/admin/versioneditor.py +++ /dev/null @@ -1,60 +0,0 @@ -# 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) |
