2019-03-18 19:52:35 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-04-06 11:08:42 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# Copyright 2023 © AE UTBM
|
|
|
|
# ae@utbm.fr / ae.info@utbm.fr
|
|
|
|
# All contributors are listed in the CONTRIBUTORS file.
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
|
|
|
# https://ae.utbm.fr.
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# You can find the whole source code at https://github.com/ae-utbm/sith3
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
|
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE"
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
2023-04-06 11:08:42 +00:00
|
|
|
# PREVIOUSLY LICENSED UNDER THE MIT LICENSE,
|
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE.old
|
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE.old"
|
2019-03-18 19:52:35 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from core.models import User
|
|
|
|
from rootplace.views import delete_all_forum_user_messages
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
"""
|
2020-08-27 13:59:42 +00:00
|
|
|
Delete all forum messages from a user
|
2019-03-18 19:52:35 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
help = "Delete all user's forum message"
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument("user_id", type=int)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
user = User.objects.filter(id=options["user_id"]).first()
|
|
|
|
|
|
|
|
if user is None:
|
|
|
|
print("User with ID %s not found" % (options["user_id"],))
|
2019-03-19 16:23:02 +00:00
|
|
|
exit(1)
|
2019-03-18 19:52:35 +00:00
|
|
|
|
|
|
|
confirm = input(
|
2019-03-19 16:23:02 +00:00
|
|
|
"User selected: %s\nDo you really want to delete all message from this user ? [y/N] "
|
2019-03-18 19:52:35 +00:00
|
|
|
% (user,)
|
|
|
|
)
|
|
|
|
|
2019-03-19 16:23:02 +00:00
|
|
|
if not confirm.lower().startswith("y"):
|
2019-03-18 19:52:35 +00:00
|
|
|
print("Operation aborted")
|
2019-03-19 16:23:02 +00:00
|
|
|
exit(1)
|
2019-03-18 19:52:35 +00:00
|
|
|
|
|
|
|
delete_all_forum_user_messages(user, User.objects.get(id=0), True)
|