aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/templates/admin/list.html1
-rw-r--r--app/templates/base.html3
-rw-r--r--app/templates/tags/edit.html27
-rw-r--r--app/templates/tags/list.html16
-rw-r--r--app/views/__init__.py2
-rw-r--r--app/views/tagseditor.py57
6 files changed, 105 insertions, 1 deletions
diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html
index 373f18b..3c15fa9 100644
--- a/app/templates/admin/list.html
+++ b/app/templates/admin/list.html
@@ -7,6 +7,7 @@
{% block content %}
<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('switch_user_page') }}">Sign in as another user</a></li>
</ul>
diff --git a/app/templates/base.html b/app/templates/base.html
index dc31624..7b9f361 100644
--- a/app/templates/base.html
+++ b/app/templates/base.html
@@ -63,6 +63,9 @@
{% if current_user.rank == current_user.rank.ADMIN %}
<li><a href="{{ url_for('admin_page') }}">Admin</a></li>
{% endif %}
+ {% if current_user.rank == current_user.rank.MODERATOR %}
+ <li><a href="{{ url_for('tag_list_page') }}">Tag Editor</a></li>
+ {% endif %}
<li><a href="{{ url_for('user.logout') }}">Sign out</a></li>
</ul>
</li>
diff --git a/app/templates/tags/edit.html b/app/templates/tags/edit.html
new file mode 100644
index 0000000..ccffa7f
--- /dev/null
+++ b/app/templates/tags/edit.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+
+{% block title %}
+ {% if tag %}
+ Edit {{ tag.title }}
+ {% else %}
+ New tag
+ {% endif %}
+{% endblock %}
+
+{% block content %}
+ <p>
+ <a href="{{ url_for('tag_list_page') }}">Back to list</a> |
+ <a href="{{ url_for('createedit_tag_page') }}">New Tag</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.title) }}
+ {% if tag %}
+ {{ render_field(form.name) }}
+ {% endif %}
+ {{ render_submit_field(form.submit) }}
+ </form>
+{% endblock %}
diff --git a/app/templates/tags/list.html b/app/templates/tags/list.html
new file mode 100644
index 0000000..355f62d
--- /dev/null
+++ b/app/templates/tags/list.html
@@ -0,0 +1,16 @@
+{% extends "base.html" %}
+
+{% block title %}
+Tags
+{% endblock %}
+
+{% block content %}
+ <p>
+ <a href="{{ url_for('createedit_tag_page') }}">New Tag</a>
+ </p>
+ <ul>
+ {% for t in tags %}
+ <li><a href="{{ url_for('createedit_tag_page', name=t.name) }}">{{ t.title }}</a> [{{ t.packages | count }} packages]</li>
+ {% endfor %}
+ </ul>
+{% endblock %}
diff --git a/app/views/__init__.py b/app/views/__init__.py
index 8bfb178..c584bb8 100644
--- a/app/views/__init__.py
+++ b/app/views/__init__.py
@@ -43,7 +43,7 @@ def home_page():
packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
return render_template("index.html", packages=packages, count=count)
-from . import users, githublogin, packages, sass, tasks, admin, notifications
+from . import users, githublogin, packages, sass, tasks, admin, notifications, tagseditor
@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
@app.route('/<path:path>/')
diff --git a/app/views/tagseditor.py b/app/views/tagseditor.py
new file mode 100644
index 0000000..533e500
--- /dev/null
+++ b/app/views/tagseditor.py
@@ -0,0 +1,57 @@
+# 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("/tags/")
+@rank_required(UserRank.MODERATOR)
+def tag_list_page():
+ return render_template("tags/list.html", tags=Tag.query.all())
+
+class TagForm(FlaskForm):
+ title = StringField("Title", [InputRequired(), Length(3,100)])
+ name = StringField("Name", [Optional(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")])
+ submit = SubmitField("Save")
+
+@app.route("/tags/new/", methods=["GET", "POST"])
+@app.route("/tags/<name>/edit/", methods=["GET", "POST"])
+@rank_required(UserRank.MODERATOR)
+def createedit_tag_page(name=None):
+ tag = None
+ if name is not None:
+ tag = Tag.query.filter_by(name=name).first()
+ if tag is None:
+ abort(404)
+
+ form = TagForm(formdata=request.form, obj=tag)
+ if request.method == "POST" and form.validate():
+ if tag is None:
+ tag = Tag(form.title.data)
+ db.session.add(tag)
+ else:
+ form.populate_obj(tag)
+ db.session.commit()
+ return redirect(url_for("createedit_tag_page", name=tag.name))
+
+ return render_template("tags/edit.html", tag=tag, form=form)