diff options
-rw-r--r-- | app/templates/admin/licenses/edit.html | 25 | ||||
-rw-r--r-- | app/templates/admin/licenses/list.html | 16 | ||||
-rw-r--r-- | app/templates/admin/list.html | 13 | ||||
-rw-r--r-- | app/templates/admin/tags/edit.html (renamed from app/templates/tags/edit.html) | 0 | ||||
-rw-r--r-- | app/templates/admin/tags/list.html (renamed from app/templates/tags/list.html) | 0 | ||||
-rw-r--r-- | app/templates/base.html | 1 | ||||
-rw-r--r-- | app/views/__init__.py | 3 | ||||
-rw-r--r-- | app/views/licenseseditor.py | 62 | ||||
-rw-r--r-- | app/views/packages/__init__.py | 4 | ||||
-rw-r--r-- | app/views/tagseditor.py | 4 | ||||
-rw-r--r-- | setup.py | 4 |
11 files changed, 119 insertions, 13 deletions
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 %} + <p> + <a href="{{ url_for('license_list_page') }}">Back to list</a> | + <a href="{{ url_for('createedit_license_page') }}">New License</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.is_foss) }} + {{ render_submit_field(form.submit) }} + </form> +{% 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 %} + <p> + <a href="{{ url_for('createedit_license_page') }}">New Tag</a> + </p> + <ul> + {% for l in licenses %} + <li><a href="{{ url_for('createedit_license_page', name=l.name) }}">{{ l.name }}</a> [{{ l.is_foss and "Free" or "Non-free"}}]</li> + {% endfor %} + </ul> +{% 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 @@ <ul> <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('switch_user_page') }}">Sign in as another user</a></li> </ul> @@ -17,12 +18,12 @@ <form method="post" action="" class="box-body"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> <select name="action"> - <option value="importmodlist">Import forum topics</option> - <option value="importscreenshots" selected>Import screenshots from VCS</option> - <option value="importdepends">Import dependencies from downloads</option> - <option value="modprovides">Set provides to mod name</option> - <option value="recalcscores">Recalc package scores</option> - <option value="vcsrelease">Create VCS releases</option> + <option value="importmodlist" selected>Import forum topics</option> + <option value="recalcscores">Recalculate package scores</option> + <!-- <option value="importscreenshots">Import screenshots from VCS</option> --> + <!-- <option value="importdepends">Import dependencies from downloads</option> --> + <!-- <option value="modprovides">Set provides to mod name</option> --> + <!-- <option value="vcsrelease">Create VCS releases</option> --> </select> <input type="submit" value="Perform" /> </form> diff --git a/app/templates/tags/edit.html b/app/templates/admin/tags/edit.html index ccffa7f..ccffa7f 100644 --- a/app/templates/tags/edit.html +++ b/app/templates/admin/tags/edit.html diff --git a/app/templates/tags/list.html b/app/templates/admin/tags/list.html index 355f62d..355f62d 100644 --- a/app/templates/tags/list.html +++ b/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 %} <li><a href="{{ url_for('tag_list_page') }}">Tag Editor</a></li> + <li><a href="{{ url_for('license_list_page') }}">License Editor</a></li> {% endif %} <li><a href="{{ url_for('user.logout') }}">Sign out</a></li> </ul> 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) @@ -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) |