Commit bdd2fda0 authored by Sli's avatar Sli

Merge branch 'rootplace' into 'master'

rootplace: create a cli utility to delete user's forum message to avoid connection timeout error

See merge request !194
parents d1f3fb2a 46db8b39
Pipeline #1709 passed with stage
in 25 minutes and 4 seconds
......@@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-03-17 17:55+0100\n"
"POT-Creation-Date: 2019-03-19 17:16+0100\n"
"PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n"
......@@ -4615,6 +4615,15 @@ msgstr "Supprimer tous les messages forum d'un utilisateur"
msgid "Delete 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. Use ./manage.py delete_all_forum_user_messages ID."
msgstr ""
"Si vous avez des soucis en utilisant cet utilitaire (connexion expirée, "
"erreur 500), essayez en utilisant l'utilitaire en ligne de commande. "
"Utilisez ./manage.py delete_user_messages ID."
#: rootplace/templates/rootplace/merge.jinja:8
msgid "Merge two users"
msgstr "Fusionner deux utilisateurs"
......@@ -4623,15 +4632,15 @@ msgstr "Fusionner deux utilisateurs"
msgid "Merge"
msgstr "Fusion"
#: rootplace/views.py:93
#: rootplace/views.py:110
msgid "User that will be kept"
msgstr "Utilisateur qui sera conservé"
#: rootplace/views.py:96
#: rootplace/views.py:113
msgid "User that will be deleted"
msgstr "Utilisateur qui sera supprimé"
#: rootplace/views.py:102
#: rootplace/views.py:119
msgid "User to be selected"
msgstr "Utilisateur à sélectionner"
......
# -*- 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.
#
#
# -*- 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.
#
#
#!/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 a user
"""
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"],))
exit(1)
confirm = input(
"User selected: %s\nDo you really want to delete all message from this user ? [y/N] "
% (user,)
)
if not confirm.lower().startswith("y"):
print("Operation aborted")
exit(1)
delete_all_forum_user_messages(user, User.objects.get(id=0), True)
......@@ -11,4 +11,5 @@
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Delete messages{% endtrans %}" /></p>
</form>
<p><strong>{% trans %}If you have trouble using this utility (timeout error, 500 error), try using the command line utility. Use ./manage.py delete_all_forum_user_messages ID.{% endtrans %}</strong></p>
{% endblock %}
\ No newline at end of file
......@@ -25,7 +25,7 @@
from django.utils.translation import ugettext as _
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.core.exceptions import PermissionDenied
......@@ -33,6 +33,7 @@ from ajax_select.fields import AutoCompleteSelectField
from core.models import User
from counter.models import Customer
from forum.models import ForumMessageMeta
......@@ -88,6 +89,22 @@ def merge_users(u1, u2):
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):
user1 = AutoCompleteSelectField(
"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
Messages are soft deleted and are still visible from admins
GUI frontend to the dedicated command
"""
template_name = "rootplace/delete_user_messages.jinja"
......@@ -142,10 +160,7 @@ class DeleteAllForumUserMessagesView(FormView):
def form_valid(self, form):
self.user = form.cleaned_data["user"]
for message in self.user.forum_messages.all():
ForumMessageMeta(
message=message, user=self.request.user, action="DELETE"
).save()
delete_all_forum_user_messages(self.user, self.request.user)
return super(DeleteAllForumUserMessagesView, self).form_valid(form)
def get_success_url(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment