aboutsummaryrefslogtreecommitdiff
path: root/app/views
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-07-28 17:26:28 +0100
committerrubenwardy <rw@rubenwardy.com>2018-07-28 17:26:28 +0100
commit514a24e2c41686e91df25970b2b624d767c94c18 (patch)
tree65ce40f5653d7e518f4dbb697b6891d8023cfdd2 /app/views
parent742a327cbbcd0f8cd19de337e51780f8478acbb1 (diff)
downloadcheatdb-514a24e2c41686e91df25970b2b624d767c94c18.tar.xz
Add license editor
Diffstat (limited to 'app/views')
-rw-r--r--app/views/__init__.py3
-rw-r--r--app/views/licenseseditor.py62
-rw-r--r--app/views/packages/__init__.py4
-rw-r--r--app/views/tagseditor.py4
4 files changed, 68 insertions, 5 deletions
diff --git a/app/views/__init__.py b/app/views/__init__.py
index 8695a4e..412c236 100644
--- a/app/views/__init__.py
+++ b/app/views/__init__.py
@@ -53,7 +53,8 @@ def home_page():
return render_template("index.html", new=new, popular=popular, count=count)
from . import users, githublogin, packages, meta, threads, api
-from . import sass, tasks, admin, notifications, tagseditor, thumbnails
+from . import tasks, admin, notifications, tagseditor, licenseseditor
+from . import sass, thumbnails
@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
@app.route('/<path:path>/')
diff --git a/app/views/licenseseditor.py b/app/views/licenseseditor.py
new file mode 100644
index 0000000..9f1a0ce
--- /dev/null
+++ b/app/views/licenseseditor.py
@@ -0,0 +1,62 @@
+# 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("/licenses/")
+@rank_required(UserRank.MODERATOR)
+def license_list_page():
+ return render_template("admin/licenses/list.html", licenses=License.query.order_by(db.asc(License.name)).all())
+
+class LicenseForm(FlaskForm):
+ name = StringField("Name", [InputRequired(), Length(3,100)])
+ is_foss = BooleanField("Is FOSS")
+ submit = SubmitField("Save")
+
+@app.route("/licenses/new/", methods=["GET", "POST"])
+@app.route("/licenses/<name>/edit/", methods=["GET", "POST"])
+@rank_required(UserRank.MODERATOR)
+def createedit_license_page(name=None):
+ license = None
+ if name is not None:
+ license = License.query.filter_by(name=name).first()
+ if license is None:
+ abort(404)
+
+ form = LicenseForm(formdata=request.form, obj=license)
+ if request.method == "GET":
+ form.is_foss.data = True
+ elif request.method == "POST" and form.validate():
+ if license is None:
+ license = License(form.name.data)
+ db.session.add(license)
+ flash("Created license " + form.name.data, "success")
+ else:
+ flash("Updated license " + form.name.data, "success")
+
+ form.populate_obj(license)
+ db.session.commit()
+ return redirect(url_for("createedit_license_page", name=license.name))
+
+ return render_template("admin/licenses/edit.html", license=license, form=form)
diff --git a/app/views/packages/__init__.py b/app/views/packages/__init__.py
index 4d9f791..8e0410f 100644
--- a/app/views/packages/__init__.py
+++ b/app/views/packages/__init__.py
@@ -175,8 +175,8 @@ class PackageForm(FlaskForm):
shortDesc = StringField("Short Description (Plaintext)", [InputRequired(), Length(1,200)])
desc = TextAreaField("Long Description (Markdown)", [Optional(), Length(0,10000)])
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
- license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
- media_license = QuerySelectField("Media License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
+ license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query.order_by(db.asc(License.name)), get_pk=lambda a: a.id, get_label=lambda a: a.name)
+ media_license = QuerySelectField("Media License", [InputRequired()], query_factory=lambda: License.query.order_by(db.asc(License.name)), get_pk=lambda a: a.id, get_label=lambda a: a.name)
provides_str = StringField("Provides (mods included in package)", [Optional(), Length(0,1000)])
tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title)
harddep_str = StringField("Hard Dependencies", [Optional(), Length(0,1000)])
diff --git a/app/views/tagseditor.py b/app/views/tagseditor.py
index 5181c0b..adcbec8 100644
--- a/app/views/tagseditor.py
+++ b/app/views/tagseditor.py
@@ -27,7 +27,7 @@ from app.utils import rank_required
@app.route("/tags/")
@rank_required(UserRank.MODERATOR)
def tag_list_page():
- return render_template("tags/list.html", tags=Tag.query.order_by(db.asc(Tag.title)).all())
+ return render_template("admin/tagslist.html", tags=Tag.query.order_by(db.asc(Tag.title)).all())
class TagForm(FlaskForm):
title = StringField("Title", [InputRequired(), Length(3,100)])
@@ -54,4 +54,4 @@ def createedit_tag_page(name=None):
db.session.commit()
return redirect(url_for("createedit_tag_page", name=tag.name))
- return render_template("tags/edit.html", tag=tag, form=form)
+ return render_template("admin/tags/edit.html", tag=tag, form=form)