mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
Add flask-admin
This commit is contained in:
parent
23b324cc9c
commit
dd6257a0a0
@ -1,11 +1,12 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Admin Tools
|
Admin
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="db/">Database</a></li>
|
||||||
<li><a href="{{ url_for('user_list_page') }}">User list</a></li>
|
<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('tag_list_page') }}">Tag Editor</a></li>
|
||||||
<li><a href="{{ url_for('license_list_page') }}">License Editor</a></li>
|
<li><a href="{{ url_for('license_list_page') }}">License Editor</a></li>
|
||||||
|
@ -27,6 +27,34 @@ from flask_wtf import FlaskForm
|
|||||||
from wtforms import *
|
from wtforms import *
|
||||||
from app.utils import loginUser, rank_required, triggerNotif
|
from app.utils import loginUser, rank_required, triggerNotif
|
||||||
import datetime
|
import datetime
|
||||||
|
from flask_admin import Admin
|
||||||
|
from flask_admin.contrib.sqla import ModelView
|
||||||
|
|
||||||
|
class MyModelView(ModelView):
|
||||||
|
def is_accessible(self):
|
||||||
|
return current_user.is_authenticated and current_user.rank.atLeast(UserRank.ADMIN)
|
||||||
|
|
||||||
|
def inaccessible_callback(self, name, **kwargs):
|
||||||
|
# redirect to login page if user doesn't have access
|
||||||
|
return redirect(url_for('user.login', next=request.url))
|
||||||
|
|
||||||
|
admin = Admin(app, name='ContentDB', template_mode='bootstrap3', url="/admin/db")
|
||||||
|
admin.add_view(MyModelView(User, db.session))
|
||||||
|
admin.add_view(MyModelView(Package, db.session))
|
||||||
|
admin.add_view(MyModelView(Dependency, db.session))
|
||||||
|
admin.add_view(MyModelView(EditRequest, db.session))
|
||||||
|
admin.add_view(MyModelView(EditRequestChange, db.session))
|
||||||
|
admin.add_view(MyModelView(ForumTopic, db.session))
|
||||||
|
admin.add_view(MyModelView(License, db.session))
|
||||||
|
admin.add_view(MyModelView(MetaPackage, db.session))
|
||||||
|
admin.add_view(MyModelView(Notification, db.session))
|
||||||
|
admin.add_view(MyModelView(PackageRelease, db.session))
|
||||||
|
admin.add_view(MyModelView(PackageScreenshot, db.session))
|
||||||
|
admin.add_view(MyModelView(Tag, db.session))
|
||||||
|
admin.add_view(MyModelView(Thread, db.session))
|
||||||
|
admin.add_view(MyModelView(ThreadReply, db.session))
|
||||||
|
admin.add_view(MyModelView(UserEmailVerification, db.session))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/", methods=["GET", "POST"])
|
@app.route("/admin/", methods=["GET", "POST"])
|
||||||
@rank_required(UserRank.ADMIN)
|
@rank_required(UserRank.ADMIN)
|
||||||
@ -79,8 +107,8 @@ def admin_page():
|
|||||||
|
|
||||||
rel = PackageRelease()
|
rel = PackageRelease()
|
||||||
rel.package = package
|
rel.package = package
|
||||||
rel.title = datetime.date.today().isoformat()
|
rel.title = datetime.date.today().isoformat()
|
||||||
rel.url = ""
|
rel.url = ""
|
||||||
rel.task_id = uuid()
|
rel.task_id = uuid()
|
||||||
rel.approved = True
|
rel.approved = True
|
||||||
db.session.add(rel)
|
db.session.add(rel)
|
||||||
@ -98,6 +126,7 @@ def admin_page():
|
|||||||
deleted_packages = Package.query.filter_by(soft_deleted=True).all()
|
deleted_packages = Package.query.filter_by(soft_deleted=True).all()
|
||||||
return render_template("admin/list.html", deleted_packages=deleted_packages)
|
return render_template("admin/list.html", deleted_packages=deleted_packages)
|
||||||
|
|
||||||
|
|
||||||
class SwitchUserForm(FlaskForm):
|
class SwitchUserForm(FlaskForm):
|
||||||
username = StringField("Username")
|
username = StringField("Username")
|
||||||
submit = SubmitField("Switch")
|
submit = SubmitField("Switch")
|
||||||
|
@ -14,3 +14,4 @@ Flask-FlatPages==0.6
|
|||||||
Flask-Migrate==2.1.1
|
Flask-Migrate==2.1.1
|
||||||
pillow==5.1.0
|
pillow==5.1.0
|
||||||
GitPython==2.1.10
|
GitPython==2.1.10
|
||||||
|
flask-admin==1.5.1
|
||||||
|
Loading…
Reference in New Issue
Block a user