diff --git a/app/blueprints/admin/admin.py b/app/blueprints/admin/admin.py index d6f9965f..50ea64f8 100644 --- a/app/blueprints/admin/admin.py +++ b/app/blueprints/admin/admin.py @@ -150,6 +150,16 @@ def admin_page(): else: flash("No downloads to create", "danger") + return redirect(url_for("admin.admin_page")) + + elif action == "delmetapackages": + query = MetaPackage.query.filter(~MetaPackage.dependencies.any(), ~MetaPackage.packages.any()) + count = query.count() + query.delete(synchronize_session=False) + db.session.commit() + + flash("Deleted " + str(count) + " unused meta packages", "success") + return redirect(url_for("admin.admin_page")) else: flash("Unknown action: " + action, "danger") diff --git a/app/blueprints/metapackages/__init__.py b/app/blueprints/metapackages/__init__.py index ef9f803a..6d32e652 100644 --- a/app/blueprints/metapackages/__init__.py +++ b/app/blueprints/metapackages/__init__.py @@ -24,7 +24,10 @@ from app.models import * @bp.route("/metapackages/") def list_all(): - mpackages = MetaPackage.query.order_by(db.asc(MetaPackage.name)).all() + mpackages = db.session.query(MetaPackage, func.count(MetaPackage.id)) \ + .select_from(MetaPackage).outerjoin(MetaPackage.packages) \ + .order_by(db.asc(MetaPackage.name)) \ + .group_by(MetaPackage.id).all() return render_template("meta/list.html", mpackages=mpackages) @bp.route("/metapackages/<name>/") diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index 211c86dd..4f426747 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -25,15 +25,17 @@ <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> <div class="row px-3"> <select name="action" class="custom-select col"> - <option value="delstuckreleases" selected>Delete stuck releases</option> - <option value="checkreleases">Validate all Zip releases</option> + <option value="cleanuploads" selected>Delete unreachable uploads</option> + <option value="delmetapackages">Delete unused meta packages</option> + <option value="delstuckreleases">Delete stuck releases</option> <option value="reimportpackages">Reimport meta</option> + <option value="recalcscores">Recalculate package scores</option> + <option value="div">------</option> + <option value="checkreleases">Validate all Zip releases</option> <option value="importmodlist">Import forum topics</option> <option value="importforeign">Import foreign release downloads</option> - <option value="recalcscores">Recalculate package scores</option> <option value="checkusers">Check forum users</option> <option value="importscreenshots">Import screenshots from VCS</option> - <option value="cleanuploads">Delete unreachable uploads</option> </select> <input type="submit" value="Perform" class="col-sm-auto btn btn-primary ml-2" /> </div> diff --git a/app/templates/meta/list.html b/app/templates/meta/list.html index 525bafde..a2a468c9 100644 --- a/app/templates/meta/list.html +++ b/app/templates/meta/list.html @@ -5,11 +5,36 @@ Meta Packages {% endblock %} {% block content %} - <ul> - {% for meta in mpackages %} - <li><a href="{{ url_for('metapackages.view', name=meta.name) }}">{{ meta.name }}</a> ({{ meta.packages.filter_by(soft_deleted=False, approved=True).all() | count }} packages)</li> + <div class="list-group"> + <div class="list-group-item"> + <div class="row text-muted"> + <div class="col-sm"> + {{ _("Name") }} + </div> + + <div class="col-sm-1 text-center"> + {{ _("Packages") }} + </div> + </div> + </div> + + {% for pair in mpackages %} + {% set meta = pair[0] %} + {% set count = pair[1] %} + <a class="list-group-item list-group-item-action" + href="{{ url_for('metapackages.view', name=meta.name) }}"> + <div class="row"> + <div class="col-sm"> + {{ meta.name }} + </div> + + <div class="col-sm-1 text-center"> + {{ count }} + </div> + </div> + </a> {% else %} <li><i>No meta packages found.</i></li> {% endfor %} - </ul> + </div> {% endblock %}