mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
Add Languages editor to admin tools
This commit is contained in:
parent
e138eb9c72
commit
1656c79c1d
@ -19,4 +19,4 @@ from flask import Blueprint
|
||||
|
||||
bp = Blueprint("admin", __name__)
|
||||
|
||||
from . import admin, audit, licenseseditor, tagseditor, versioneditor, warningseditor, email
|
||||
from . import admin, audit, licenseseditor, tagseditor, versioneditor, warningseditor, languageseditor, email
|
||||
|
69
app/blueprints/admin/languageseditor.py
Normal file
69
app/blueprints/admin/languageseditor.py
Normal file
@ -0,0 +1,69 @@
|
||||
# ContentDB
|
||||
# Copyright (C) 2018-24 rubenwardy
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from flask import redirect, render_template, abort, url_for
|
||||
from flask_login import current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, TextAreaField, SubmitField
|
||||
from wtforms.validators import InputRequired, Length, Optional
|
||||
|
||||
from app.models import db, AuditSeverity, UserRank, Language
|
||||
from app.utils import add_audit_log, rank_required
|
||||
from . import bp
|
||||
|
||||
|
||||
@bp.route("/admin/languages/")
|
||||
@rank_required(UserRank.ADMIN)
|
||||
def language_list():
|
||||
return render_template("admin/languages/list.html", languages=Language.query.all())
|
||||
|
||||
|
||||
class LanguageForm(FlaskForm):
|
||||
id = StringField("Id", [InputRequired(), Length(2, 10)])
|
||||
title = TextAreaField("Title", [Optional(), Length(2, 100)])
|
||||
submit = SubmitField("Save")
|
||||
|
||||
|
||||
@bp.route("/admin/languages/new/", methods=["GET", "POST"])
|
||||
@bp.route("/admin/languages/<id_>/edit/", methods=["GET", "POST"])
|
||||
@rank_required(UserRank.ADMIN)
|
||||
def create_edit_language(id_=None):
|
||||
language = None
|
||||
if id_ is not None:
|
||||
language = Language.query.filter_by(id=id_).first()
|
||||
if language is None:
|
||||
abort(404)
|
||||
|
||||
form = LanguageForm(obj=language)
|
||||
if form.validate_on_submit():
|
||||
if language is None:
|
||||
language = Language()
|
||||
db.session.add(language)
|
||||
form.populate_obj(language)
|
||||
|
||||
add_audit_log(AuditSeverity.EDITOR, current_user, f"Created language {language.id}",
|
||||
url_for("admin.create_edit_language", id_=language.id))
|
||||
else:
|
||||
form.populate_obj(language)
|
||||
|
||||
add_audit_log(AuditSeverity.EDITOR, current_user, f"Edited language {language.id}",
|
||||
url_for("admin.create_edit_language", id_=language.id))
|
||||
|
||||
db.session.commit()
|
||||
return redirect(url_for("admin.create_edit_language", id_=language.id))
|
||||
|
||||
return render_template("admin/languages/edit.html", language=language, form=form)
|
23
app/templates/admin/languages/edit.html
Normal file
23
app/templates/admin/languages/edit.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% if language %}
|
||||
Edit {{ language.title }}
|
||||
{% else %}
|
||||
New language
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<a class="btn btn-primary float-end" href="{{ url_for('admin.create_edit_language') }}">New Language</a>
|
||||
<a class="btn btn-secondary mb-4" href="{{ url_for('admin.language_list') }}">Back to list</a>
|
||||
|
||||
{% from "macros/forms.html" import render_field, render_submit_field, render_checkbox_field %}
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_field(form.id) }}
|
||||
{{ render_field(form.title) }}
|
||||
{{ render_submit_field(form.submit) }}
|
||||
</form>
|
||||
{% endblock %}
|
39
app/templates/admin/languages/list.html
Normal file
39
app/templates/admin/languages/list.html
Normal file
@ -0,0 +1,39 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{{ _("Languages") }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<a class="btn btn-primary float-end" href="{{ url_for('admin.create_edit_language') }}">{{ _("New Tag") }}</a>
|
||||
|
||||
<h1>{{ _("Languages") }}</h1>
|
||||
|
||||
<div class="list-group">
|
||||
<div class="list-group-item">
|
||||
<div class="row text-muted">
|
||||
<div class="col-sm-2">
|
||||
{{ _("Id") }}
|
||||
</div>
|
||||
|
||||
<div class="col-sm">
|
||||
{{ _("Title") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for l in languages %}
|
||||
<a class="list-group-item list-group-item-action"
|
||||
href="{{ url_for('admin.create_edit_language', id_=l.id) }}">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
{{ l.id }}
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
{{ l.title }}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
@ -68,6 +68,10 @@
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
Warning Editor
|
||||
</a>
|
||||
<a class="list-group-item list-group-item-action" href="{{ url_for('admin.language_list') }}">
|
||||
<i class="fas fa-language me-2"></i>
|
||||
Languages Editor
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -182,6 +182,7 @@
|
||||
role="button"
|
||||
aria-expanded="false">
|
||||
<i class="fas fa-language"></i>
|
||||
<span class="sr-only">{{ _("Languages") }}</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-right" role="menu">
|
||||
{% for locale, locale_name in config["LANGUAGES"].items() %}
|
||||
|
Loading…
Reference in New Issue
Block a user