From a4a1bee5b438b3afaca4839bce287df1b01d000a Mon Sep 17 00:00:00 2001 From: Augustin Laville Date: Thu, 31 Mar 2016 07:34:31 +0200 Subject: [PATCH] Fix #3286 : ajoute la possibilite de supprimer un auteur bot --- zds/tutorialv2/forms.py | 19 +++++++++++++++++++ zds/tutorialv2/views/views_contents.py | 8 +++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/zds/tutorialv2/forms.py b/zds/tutorialv2/forms.py index 7495e9a17e..60337af73c 100644 --- a/zds/tutorialv2/forms.py +++ b/zds/tutorialv2/forms.py @@ -86,6 +86,25 @@ def is_valid(self): return super(AuthorForm, self).is_valid() and "users" in self.clean() +class RemoveAuthorForm(AuthorForm): + + def clean(self): + """Check every username and send it to the cleaned_data["user"] list + + :return: a dictionary of all treated data with the users key added + """ + cleaned_data = super(AuthorForm, self).clean() + users = [] + for username in cleaned_data.get('username').split(","): + # we can remove all users (bots inclued) + user = Profile.objects.filter(user__username__iexact=username.strip().lower()).first() + if user is not None: + users.append(user.user) + if len(users) > 0: + cleaned_data["users"] = users + return cleaned_data + + class ContainerForm(FormWithTitle): introduction = forms.CharField( diff --git a/zds/tutorialv2/views/views_contents.py b/zds/tutorialv2/views/views_contents.py index 88a29ff910..cc8adb2948 100644 --- a/zds/tutorialv2/views/views_contents.py +++ b/zds/tutorialv2/views/views_contents.py @@ -37,7 +37,7 @@ from zds.notification.models import TopicAnswerSubscription from zds.tutorialv2.forms import ContentForm, JsFiddleActivationForm, AskValidationForm, AcceptValidationForm, \ RejectValidationForm, RevokeValidationForm, WarnTypoForm, ImportContentForm, ImportNewContentForm, ContainerForm, \ - ExtractForm, BetaForm, MoveElementForm, AuthorForm, CancelValidationForm + ExtractForm, BetaForm, MoveElementForm, AuthorForm, RemoveAuthorForm, CancelValidationForm from zds.tutorialv2.mixins import SingleContentDetailViewMixin, SingleContentFormViewMixin, SingleContentViewMixin, \ SingleContentDownloadViewMixin, SingleContentPostMixin from zds.tutorialv2.models import TYPE_CHOICES_DICT @@ -1740,6 +1740,8 @@ def form_invalid(self, form): class RemoveAuthorFromContent(AddAuthorToContent): + form_class = RemoveAuthorForm + @staticmethod def remove_author(content, user): """Remove an user from the authors and ensure that he is access to the content's gallery is also removed. @@ -1795,10 +1797,10 @@ def form_valid(self, form): if not current_user: # if the removed author is not current user messages.success( - self.request, _(u'Vous avez enlevé {} de la liste des auteurs de « {} ».').format(authors_list, _type)) + self.request, _(u'Vous avez enlevé {} de la liste des auteurs de {}.').format(authors_list, _type)) self.success_url = self.object.get_absolute_url() else: # if current user is leaving the content's redaction, redirect him to a more suitable page - messages.success(self.request, _(u'Vous avez bien quitté la rédaction de « {} ».').format(_type)) + messages.success(self.request, _(u'Vous avez bien quitté la rédaction de {}.').format(_type)) self.success_url = reverse('content:find-' + self.object.type.lower(), args=[self.request.user.pk]) self.already_finished = True # this one is kind of tricky : because of inheritance we used to force redirection # to the content itself. This does not please me but I think it is better to do that like that instead of