From 45238496416222c62ee7b0583d47f8289b55b83c Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 19 Jul 2021 23:02:20 +0100 Subject: [PATCH] Add Draft/ChangesNeeded notification admin action --- app/blueprints/admin/admin.py | 27 ++++++++++++++++++++++++++- app/templates/admin/list.html | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/blueprints/admin/admin.py b/app/blueprints/admin/admin.py index 313e34fe..47f5fe7a 100644 --- a/app/blueprints/admin/admin.py +++ b/app/blueprints/admin/admin.py @@ -21,13 +21,14 @@ from celery import group from flask import * from flask_login import current_user, login_user from flask_wtf import FlaskForm +from sqlalchemy import or_ from wtforms import * from wtforms.validators import InputRequired, Length from app.models import * from app.tasks.forumtasks import importTopicList, checkAllForumAccounts from app.tasks.importtasks import importRepoScreenshot, checkZipRelease, check_for_updates -from app.utils import rank_required, addAuditLog, addNotification +from app.utils import rank_required, addAuditLog, addNotification, get_system_user from . import bp @@ -184,6 +185,30 @@ def admin_page(): flash("Started update configs", "success") return redirect(url_for("admin.admin_page")) + elif action == "remindwip": + users = User.query.filter(User.packages.any(or_(Package.state==PackageState.WIP, Package.state==PackageState.CHANGES_NEEDED))) + system_user = get_system_user() + for user in users: + packages = db.session.query(Package.title).filter( + Package.author_id==user.id, + or_(Package.state==PackageState.WIP, Package.state==PackageState.CHANGES_NEEDED)) \ + .all() + + # Who needs translations? + packages = [pkg[0] for pkg in packages] + if len(packages) >= 3: + packages[len(packages) - 1] = "and " + packages[len(packages) - 1] + packages_list = ", ".join(packages) + else: + packages_list = "and ".join(packages) + + havent = "haven't" if len(packages) > 1 else "hasn't" + + addNotification(user, system_user, NotificationType.PACKAGE_APPROVAL, + f"Did you forget? {packages_list} {havent} been submitted for review yet", + url_for('todo.view_user', username=user.username)) + db.session.commit() + else: flash("Unknown action: " + action, "danger") diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index ddf8fc48..f248e28e 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -39,6 +39,7 @@ +