forked from MarseyWorld/MarseyWorld
add mass badge granting and removal
parent
47cfa0d922
commit
52f9a99af1
|
@ -471,7 +471,14 @@ def badge_grant_get(v):
|
|||
def badge_grant_post(v):
|
||||
badges = admin_badges_grantable_list(v)
|
||||
|
||||
user = get_user(request.values.get("username"), graceful=True)
|
||||
usernames = request.values.get("usernames", "").strip()
|
||||
if not usernames:
|
||||
error = "You must enter usernames!"
|
||||
if v.client: return {"error": error}
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=True, error=error)
|
||||
|
||||
for username in usernames.split():
|
||||
user = get_user(username, graceful=True)
|
||||
if not user:
|
||||
error = "User not found!"
|
||||
if v.client: return {"error": error}
|
||||
|
@ -528,8 +535,8 @@ def badge_grant_post(v):
|
|||
)
|
||||
g.db.add(ma)
|
||||
|
||||
msg = f"{new_badge.name} Badge granted to @{user.username} successfully!"
|
||||
|
||||
msg = f"{new_badge.name} Badge granted to users successfully!"
|
||||
if v.client: return {"message": msg}
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=True, msg=msg)
|
||||
|
||||
|
@ -543,7 +550,14 @@ def badge_grant_post(v):
|
|||
def badge_remove_post(v):
|
||||
badges = admin_badges_grantable_list(v)
|
||||
|
||||
user = get_user(request.values.get("username"), graceful=True)
|
||||
usernames = request.values.get("usernames", "").strip()
|
||||
if not usernames:
|
||||
error = "You must enter usernames!"
|
||||
if v.client: return {"error": error}
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, error=error)
|
||||
|
||||
for username in usernames.split():
|
||||
user = get_user(username, graceful=True)
|
||||
if not user:
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, error="User not found!")
|
||||
|
||||
|
@ -569,7 +583,11 @@ def badge_remove_post(v):
|
|||
)
|
||||
g.db.add(ma)
|
||||
g.db.delete(badge)
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, msg=f"{badge.name} Badge removed from @{user.username} successfully!")
|
||||
|
||||
|
||||
msg = f"{badge.name} Badge removed from users successfully!"
|
||||
if v.client: return {"message": msg}
|
||||
return render_template("admin/badge_admin.html", v=v, badge_types=badges, grant=False, msg=msg)
|
||||
|
||||
|
||||
@app.get("/admin/alt_votes")
|
||||
|
|
|
@ -41,15 +41,15 @@
|
|||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<label for="input-username">Username</label>
|
||||
<input autocomplete="off" id="input-username" class="form-control" type="text" name="username" required>
|
||||
<label for="input-usernames">Usernames</label>
|
||||
<input autocomplete="off" id="input-usernames" class="form-control" type="text" name="usernames" placeholder="Required (separated by space)" required>
|
||||
|
||||
{% if grant %}
|
||||
<label class="mt-2" for="input-url">URL</label>
|
||||
<input autocomplete="off" id="input-url" class="form-control" type="text" name="url" type="url" placeholder="Optional">
|
||||
|
||||
<label class="mt-2" for="input-description">Custom description</label>
|
||||
<input autocomplete="off" id="input-description" class="form-control" type="text" name="description" placeholder="Leave blank for badge default">
|
||||
<input autocomplete="off" id="input-description" class="form-control" type="text" name="description" placeholder="Optional">
|
||||
{% endif %}
|
||||
<input autocomplete="off" class="btn btn-primary mt-3" type="submit">
|
||||
|
||||
|
|
Loading…
Reference in New Issue