From 514a24e2c41686e91df25970b2b624d767c94c18 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 28 Jul 2018 17:26:28 +0100 Subject: [PATCH] Add license editor --- app/templates/admin/licenses/edit.html | 25 ++++++++++ app/templates/admin/licenses/list.html | 16 ++++++ app/templates/admin/list.html | 13 ++--- app/templates/{ => admin}/tags/edit.html | 0 app/templates/{ => admin}/tags/list.html | 0 app/templates/base.html | 1 + app/views/__init__.py | 3 +- app/views/licenseseditor.py | 62 ++++++++++++++++++++++++ app/views/packages/__init__.py | 4 +- app/views/tagseditor.py | 4 +- setup.py | 4 +- 11 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 app/templates/admin/licenses/edit.html create mode 100644 app/templates/admin/licenses/list.html rename app/templates/{ => admin}/tags/edit.html (100%) rename app/templates/{ => admin}/tags/list.html (100%) create mode 100644 app/views/licenseseditor.py diff --git a/app/templates/admin/licenses/edit.html b/app/templates/admin/licenses/edit.html new file mode 100644 index 0000000..c68b17f --- /dev/null +++ b/app/templates/admin/licenses/edit.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block title %} + {% if license %} + Edit {{ license.name }} + {% else %} + New license + {% endif %} +{% endblock %} + +{% block content %} +

+ Back to list | + New License +

+ + {% from "macros/forms.html" import render_field, render_submit_field %} +
+ {{ form.hidden_tag() }} + + {{ render_field(form.name) }} + {{ render_field(form.is_foss) }} + {{ render_submit_field(form.submit) }} +
+{% endblock %} diff --git a/app/templates/admin/licenses/list.html b/app/templates/admin/licenses/list.html new file mode 100644 index 0000000..43856f5 --- /dev/null +++ b/app/templates/admin/licenses/list.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %} +Licenses +{% endblock %} + +{% block content %} +

+ New Tag +

+ +{% endblock %} diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index 4763bdc..a2ac6d5 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -8,6 +8,7 @@ @@ -17,12 +18,12 @@
diff --git a/app/templates/tags/edit.html b/app/templates/admin/tags/edit.html similarity index 100% rename from app/templates/tags/edit.html rename to app/templates/admin/tags/edit.html diff --git a/app/templates/tags/list.html b/app/templates/admin/tags/list.html similarity index 100% rename from app/templates/tags/list.html rename to app/templates/admin/tags/list.html diff --git a/app/templates/base.html b/app/templates/base.html index 126f56f..35a2ac6 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -65,6 +65,7 @@ {% endif %} {% if current_user.rank == current_user.rank.MODERATOR %}
  • Tag Editor
  • +
  • License Editor
  • {% endif %}
  • Sign out
  • 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('//') 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 . + + +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//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) diff --git a/setup.py b/setup.py index e106aa2..df57698 100644 --- a/setup.py +++ b/setup.py @@ -362,12 +362,12 @@ for tag in ["Inventory", "Mapgen", "Building", \ licenses = {} for license in ["GPLv2.1", "GPLv3", "LGPLv2.1", "LGPLv3", "AGPLv2.1", "AGPLv3", "Apache", "BSD 3-Clause", "BSD 2-Clause", "CC0", "CC-BY-SA", - "CC-BY", "MIT", "ZLib"]: + "CC-BY", "MIT", "ZLib", "Other (Free)"]: row = License(license) licenses[row.name] = row db.session.add(row) -for license in ["CC-BY-NC-SA"]: +for license in ["CC-BY-NC-SA", "Other (Non-free)"]: row = License(license, False) licenses[row.name] = row db.session.add(row)