Add package count to languages editor

This commit is contained in:
rubenwardy 2024-02-26 02:09:00 +00:00
parent b1a9398ed1
commit fe40a7c6d4
3 changed files with 34 additions and 8 deletions

@ -21,7 +21,7 @@ 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.models import db, AuditSeverity, UserRank, Language, Package, PackageState
from app.utils import add_audit_log, rank_required
from . import bp
@ -29,7 +29,9 @@ 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())
total_package_count = Package.query.filter_by(state=PackageState.APPROVED).count()
return render_template("admin/languages/list.html",
languages=Language.query.all(), total_package_count=total_package_count)
class LanguageForm(FlaskForm):

@ -847,6 +847,8 @@ class Language(db.Model):
id = db.Column(db.String(10), primary_key=True)
title = db.Column(db.String(100), unique=True, nullable=False)
packages = db.relationship("Package", secondary="package_translation", lazy="dynamic")
@property
def has_contentdb_translation(self):
return self.id in app.config["LANGUAGES"].keys()

@ -5,21 +5,27 @@
{% endblock %}
{% block content %}
<a class="btn btn-primary float-end" href="{{ url_for('admin.create_edit_language') }}">{{ _("New Tag") }}</a>
<a class="btn btn-primary float-end" href="{{ url_for('admin.create_edit_language') }}">New Language</a>
<h1>{{ _("Languages") }}</h1>
<div class="list-group">
<div class="list-group-item">
<div class="row text-muted">
<div class="col-2">
<div class="col-1">
{{ _("Id") }}
</div>
<div class="col">
<div class="col-2">
{{ _("Title") }}
</div>
<div class="col-1">
{{ _("Packages") }}
</div>
<div class="col"></div>
<div class="col-3 text-end">
{{ _("Has ContentDB translation?") }}
</div>
@ -27,15 +33,31 @@
</div>
{% for l in languages %}
{% if l.id == "en" %}
{% set lang_package_count = total_package_count %}
{% else %}
{% set lang_package_count = l.packages.filter_by(state='APPROVED').count() %}
{% endif %}
<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-2">
<div class="row align-items-center justify-content-center">
<div class="col-1">
{{ l.id }}
</div>
<div class="col">
<div class="col-2">
{{ l.title }}
</div>
<div class="col-1">
{{ lang_package_count }}
</div>
<div class="col">
<div class="progress">
<div class="progress-bar" role="progressbar"
style="width: {{ 100 * lang_package_count / total_package_count }}%;"
aria-valuenow="{{ lang_package_count }}" aria-valuemin="0" aria-valuemax="{{ total_package_count }}">
</div>
</div>
</div>
<div class="col-3 text-end">
{% if l.has_contentdb_translation %}
<i class="fas fa-check text-success"></i>