Skip to content

Commit

Permalink
Merge pull request #3476 from gustavi/fix-3286
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Mar 31, 2016
2 parents 9573d27 + a4a1bee commit 504cc3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions zds/tutorialv2/forms.py
Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions zds/tutorialv2/views/views_contents.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 504cc3c

Please sign in to comment.