Esempio n. 1
0
    def form_valid(self, form):

        old_validation = Validation.objects.filter(
            content__pk=self.object.pk, status__in=['PENDING', 'PENDING_V']).first()

        if old_validation:  # if an old validation exists, cancel it!
            old_validator = old_validation.validator
            old_validation.status = 'CANCEL'
            old_validation.date_validation = datetime.now()
            old_validation.save()
        else:
            old_validator = None

        # create a 'validation' object
        validation = Validation()
        validation.content = self.object
        validation.date_proposition = datetime.now()
        validation.comment_authors = form.cleaned_data['text']
        validation.version = form.cleaned_data['version']
        if old_validator:
            validation.validator = old_validator
            validation.date_reserve = old_validation.date_reserve
            validation.status = 'PENDING_V'
        validation.save()

        # warn the former validator that an update has been made, if any
        if old_validator:
            bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
            msg = render_to_string(
                'tutorialv2/messages/validation_change.md',
                {
                    'content': self.versioned_object,
                    'validator': validation.validator.username,
                    'url': self.versioned_object.get_absolute_url() + '?version=' + form.cleaned_data['version'],
                    'url_history': reverse('content:history', args=[self.object.pk, self.object.slug])
                })

            send_mp(
                bot,
                [old_validator],
                _('Une nouvelle version a été envoyée en validation.'),
                self.versioned_object.title,
                msg,
                False,
                hat=get_hat_from_settings('validation'),
            )

        # update the content with the source and the version of the validation
        self.object.source = form.cleaned_data['source']
        self.object.sha_validation = validation.version
        self.object.save()

        messages.success(self.request, _("Votre demande de validation a été transmise à l'équipe."))

        self.success_url = self.versioned_object.get_absolute_url(version=self.sha)
        return super(AskValidationForContent, self).form_valid(form)
Esempio n. 2
0
    def form_valid(self, form):

        old_validation = Validation.objects.filter(
            content__pk=self.object.pk, status__in=['PENDING',
                                                    'PENDING_V']).first()

        if old_validation:  # if an old validation exists, cancel it!
            old_validator = old_validation.validator
            old_validation.status = 'CANCEL'
            old_validation.date_validation = datetime.now()
            old_validation.save()
        else:
            old_validator = None

        # create a 'validation' object
        validation = Validation()
        validation.content = self.object
        validation.date_proposition = datetime.now()
        validation.comment_authors = form.cleaned_data['text']
        validation.version = form.cleaned_data['version']
        if old_validator:
            validation.validator = old_validator
            validation.date_reserve = old_validation.date_reserve
            validation.status = 'PENDING_V'
        validation.save()

        # warn the former validator that an update has been made, if any
        if old_validator:
            bot = get_object_or_404(
                User, username=settings.ZDS_APP['member']['bot_account'])
            msg = render_to_string(
                'tutorialv2/messages/validation_change.md', {
                    'content':
                    self.versioned_object,
                    'validator':
                    validation.validator.username,
                    'url':
                    self.versioned_object.get_absolute_url() + '?version=' +
                    form.cleaned_data['version'],
                    'url_history':
                    reverse('content:history',
                            args=[self.object.pk, self.object.slug])
                })

            send_mp(
                bot,
                [old_validator],
                _('Une nouvelle version a été envoyée en validation.'),
                self.versioned_object.title,
                msg,
                False,
                hat=get_hat_from_settings('validation'),
            )

        # update the content with the source and the version of the validation
        self.object.source = form.cleaned_data['source']
        self.object.sha_validation = validation.version
        self.object.save()

        messages.success(
            self.request,
            _("Votre demande de validation a été transmise à l'équipe."))

        self.success_url = self.versioned_object.get_absolute_url(
            version=self.sha)
        return super(AskValidationForContent, self).form_valid(form)
Esempio n. 3
0
    def form_valid(self, form):

        old_validation = Validation.objects.filter(
            content__pk=self.object.pk, status__in=["PENDING",
                                                    "PENDING_V"]).first()

        if old_validation:  # if an old validation exists, cancel it!
            old_validator = old_validation.validator
            old_validation.status = "CANCEL"
            old_validation.date_validation = datetime.now()
            old_validation.save()
        else:
            old_validator = None

        # create a 'validation' object
        validation = Validation()
        validation.content = self.object
        validation.date_proposition = datetime.now()
        validation.comment_authors = form.cleaned_data["text"]
        validation.version = form.cleaned_data["version"]
        if old_validator:
            validation.validator = old_validator
            validation.date_reserve = old_validation.date_reserve
            validation.status = "PENDING_V"
        validation.save()

        # warn the former validator that an update has been made, if any
        if old_validator:
            bot = get_object_or_404(
                User, username=settings.ZDS_APP["member"]["bot_account"])
            msg = render_to_string(
                "tutorialv2/messages/validation_change.md",
                {
                    "content":
                    self.versioned_object,
                    "validator":
                    validation.validator.username,
                    "url":
                    self.versioned_object.get_absolute_url() + "?version=" +
                    form.cleaned_data["version"],
                    "url_history":
                    reverse("content:history",
                            args=[self.object.pk, self.object.slug]),
                },
            )
            if not self.object.validation_private_message:
                self.object.validation_private_message = send_mp(
                    bot,
                    [old_validator],
                    self.object.validation_message_title,
                    self.versioned_object.title,
                    msg,
                    send_by_mail=False,
                    hat=get_hat_from_settings("validation"),
                )
            else:
                send_message_mp(bot, self.object.validation_private_message,
                                msg)

        # update the content with the source and the version of the validation
        self.object.source = self.versioned_object.source
        self.object.sha_validation = validation.version
        self.object.save()

        messages.success(
            self.request,
            _("Votre demande de validation a été transmise à l'équipe."))

        self.success_url = self.versioned_object.get_absolute_url(
            version=self.sha)
        return super(AskValidationForContent, self).form_valid(form)