mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
rootplace: create a cli utility to delete user's forum message to avoid connection timeout error
This commit is contained in:
parent
2ee50c0fbd
commit
f9d4f41b7c
@ -6,7 +6,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2019-03-17 17:55+0100\n"
|
"POT-Creation-Date: 2019-03-18 20:48+0100\n"
|
||||||
"PO-Revision-Date: 2016-07-18\n"
|
"PO-Revision-Date: 2016-07-18\n"
|
||||||
"Last-Translator: Skia <skia@libskia.so>\n"
|
"Last-Translator: Skia <skia@libskia.so>\n"
|
||||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||||
@ -4615,6 +4615,13 @@ msgstr "Supprimer tous les messages forum d'un utilisateur"
|
|||||||
msgid "Delete messages"
|
msgid "Delete messages"
|
||||||
msgstr "Supprimer les messages"
|
msgstr "Supprimer les messages"
|
||||||
|
|
||||||
|
#: rootplace/templates/rootplace/delete_user_messages.jinja:14
|
||||||
|
msgid ""
|
||||||
|
"If you have trouble using this utility (timeout error, 500 error), try using "
|
||||||
|
"the command line utility"
|
||||||
|
msgstr "Si vous avez des soucis en utilisant cet utilitaire (connection expirée, erreur 500), "
|
||||||
|
"essayez en utilisant l'utilitaire en ligne de commande"
|
||||||
|
|
||||||
#: rootplace/templates/rootplace/merge.jinja:8
|
#: rootplace/templates/rootplace/merge.jinja:8
|
||||||
msgid "Merge two users"
|
msgid "Merge two users"
|
||||||
msgstr "Fusionner deux utilisateurs"
|
msgstr "Fusionner deux utilisateurs"
|
||||||
@ -4623,15 +4630,15 @@ msgstr "Fusionner deux utilisateurs"
|
|||||||
msgid "Merge"
|
msgid "Merge"
|
||||||
msgstr "Fusion"
|
msgstr "Fusion"
|
||||||
|
|
||||||
#: rootplace/views.py:93
|
#: rootplace/views.py:110
|
||||||
msgid "User that will be kept"
|
msgid "User that will be kept"
|
||||||
msgstr "Utilisateur qui sera conservé"
|
msgstr "Utilisateur qui sera conservé"
|
||||||
|
|
||||||
#: rootplace/views.py:96
|
#: rootplace/views.py:113
|
||||||
msgid "User that will be deleted"
|
msgid "User that will be deleted"
|
||||||
msgstr "Utilisateur qui sera supprimé"
|
msgstr "Utilisateur qui sera supprimé"
|
||||||
|
|
||||||
#: rootplace/views.py:102
|
#: rootplace/views.py:119
|
||||||
msgid "User to be selected"
|
msgid "User to be selected"
|
||||||
msgstr "Utilisateur à sélectionner"
|
msgstr "Utilisateur à sélectionner"
|
||||||
|
|
||||||
|
23
rootplace/management/__init__.py
Normal file
23
rootplace/management/__init__.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# -*- coding:utf-8 -*
|
||||||
|
#
|
||||||
|
# Copyright 2016,2017
|
||||||
|
# - Sli <antoine@bartuccio.fr>
|
||||||
|
#
|
||||||
|
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||||
|
# http://ae.utbm.fr.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License a published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||||
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
#
|
23
rootplace/management/commands/__init__.py
Normal file
23
rootplace/management/commands/__init__.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# -*- coding:utf-8 -*
|
||||||
|
#
|
||||||
|
# Copyright 2016,2017
|
||||||
|
# - Sli <antoine@bartuccio.fr>
|
||||||
|
#
|
||||||
|
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||||
|
# http://ae.utbm.fr.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License a published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||||
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
#
|
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding:utf-8 -*
|
||||||
|
#
|
||||||
|
# Copyright 2017
|
||||||
|
# - Sli <antoine@bartuccio.fr>
|
||||||
|
#
|
||||||
|
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
||||||
|
# http://ae.utbm.fr.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License a published by the Free Software
|
||||||
|
# Foundation; either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
||||||
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from core.models import User
|
||||||
|
from rootplace.views import delete_all_forum_user_messages
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
Delete all forum messages from an user
|
||||||
|
Messages are soft deleted and are still visible from admins
|
||||||
|
"""
|
||||||
|
|
||||||
|
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"],))
|
||||||
|
return
|
||||||
|
|
||||||
|
confirm = input(
|
||||||
|
"User selected %s\nDo you really want to delete all user's messages ? [y/N] "
|
||||||
|
% (user,)
|
||||||
|
)
|
||||||
|
|
||||||
|
if confirm != "y" and confirm != "Y":
|
||||||
|
print("Operation aborted")
|
||||||
|
return
|
||||||
|
|
||||||
|
delete_all_forum_user_messages(user, User.objects.get(id=0), True)
|
@ -11,4 +11,5 @@
|
|||||||
{{ form.as_p() }}
|
{{ form.as_p() }}
|
||||||
<p><input type="submit" value="{% trans %}Delete messages{% endtrans %}" /></p>
|
<p><input type="submit" value="{% trans %}Delete messages{% endtrans %}" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
<p><strong>{% trans %}If you have trouble using this utility (timeout error, 500 error), try using the command line utility{% endtrans %}</strong></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
from django.core.urlresolvers import reverse, reverse_lazy
|
from django.core.urlresolvers import reverse
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
@ -33,6 +33,7 @@ from ajax_select.fields import AutoCompleteSelectField
|
|||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from counter.models import Customer
|
from counter.models import Customer
|
||||||
|
|
||||||
from forum.models import ForumMessageMeta
|
from forum.models import ForumMessageMeta
|
||||||
|
|
||||||
|
|
||||||
@ -88,6 +89,22 @@ def merge_users(u1, u2):
|
|||||||
return u1
|
return u1
|
||||||
|
|
||||||
|
|
||||||
|
def delete_all_forum_user_messages(user, moderator, verbose=False):
|
||||||
|
"""
|
||||||
|
Create a ForumMessageMeta that says a forum
|
||||||
|
message is deleted on every forum message of an user
|
||||||
|
user: the user to delete messages from
|
||||||
|
moderator: the one marked as the moderator
|
||||||
|
"""
|
||||||
|
for message in user.forum_messages.all():
|
||||||
|
if message.is_deleted():
|
||||||
|
continue
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(message)
|
||||||
|
ForumMessageMeta(message=message, user=moderator, action="DELETE").save()
|
||||||
|
|
||||||
|
|
||||||
class MergeForm(forms.Form):
|
class MergeForm(forms.Form):
|
||||||
user1 = AutoCompleteSelectField(
|
user1 = AutoCompleteSelectField(
|
||||||
"users", label=_("User that will be kept"), help_text=None, required=True
|
"users", label=_("User that will be kept"), help_text=None, required=True
|
||||||
@ -127,6 +144,7 @@ class DeleteAllForumUserMessagesView(FormView):
|
|||||||
"""
|
"""
|
||||||
Delete all forum messages from an user
|
Delete all forum messages from an user
|
||||||
Messages are soft deleted and are still visible from admins
|
Messages are soft deleted and are still visible from admins
|
||||||
|
GUI frontend to the dedicated command
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template_name = "rootplace/delete_user_messages.jinja"
|
template_name = "rootplace/delete_user_messages.jinja"
|
||||||
@ -142,10 +160,7 @@ class DeleteAllForumUserMessagesView(FormView):
|
|||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.user = form.cleaned_data["user"]
|
self.user = form.cleaned_data["user"]
|
||||||
for message in self.user.forum_messages.all():
|
delete_all_forum_user_messages(self.user, self.request.user)
|
||||||
ForumMessageMeta(
|
|
||||||
message=message, user=self.request.user, action="DELETE"
|
|
||||||
).save()
|
|
||||||
return super(DeleteAllForumUserMessagesView, self).form_valid(form)
|
return super(DeleteAllForumUserMessagesView, self).form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user