Пример #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)
Пример #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)
Пример #3
0
    def form_valid(self, form):
        # get database representation and validated version
        db_object = self.object
        versioned = self.versioned_object

        # get initial git path
        old_git_path = db_object.get_repo_path()

        # store data for later
        authors = db_object.authors.all()
        subcats = db_object.subcategory.all()
        tags = db_object.tags.all()
        article = PublishableContent(title=db_object.title,
                                     type='ARTICLE',
                                     creation_date=datetime.now(),
                                     sha_public=db_object.sha_public,
                                     public_version=None,
                                     licence=db_object.licence,
                                     sha_validation=db_object.sha_public,
                                     sha_draft=db_object.sha_public,
                                     image=db_object.image,
                                     source=db_object.source)

        opinion_url = db_object.get_absolute_url_online()
        article.save()
        # add M2M objects
        for author in authors:
            article.authors.add(author)
        for subcat in subcats:
            article.subcategory.add(subcat)
        for tag in tags:
            article.tags.add(tag)
        article.save()
        # add information about the conversion to the original opinion
        db_object.converted_to = article
        db_object.save()

        # clone the repo
        clone_repo(old_git_path, article.get_repo_path())
        versionned_article = article.load_version(sha=article.sha_validation)
        # mandatory to avoid path collision
        versionned_article.slug = article.slug
        article.sha_validation = versionned_article.repo_update(
            versionned_article.title, versionned_article.get_introduction(),
            versionned_article.get_conclusion())
        article.sha_draft = article.sha_validation
        article.save()
        # ask for validation
        validation = Validation()
        validation.content = article
        validation.date_proposition = datetime.now()
        validation.comment_authors = _(
            'Promotion du billet « [{0}]({1}) » en article par [{2}]({3}).'.
            format(article.title, article.get_absolute_url_online(),
                   self.request.user.username,
                   self.request.user.profile.get_absolute_url()))
        validation.version = article.sha_validation
        validation.save()
        # creating the gallery
        gal = Gallery()
        gal.title = db_object.gallery.title
        gal.slug = db_object.gallery.slug
        gal.pubdate = datetime.now()
        gal.save()
        article.gallery = gal
        # save updates
        article.save()
        article.ensure_author_gallery()

        # send message to user
        msg = render_to_string('tutorialv2/messages/opinion_promotion.md', {
            'content': versioned,
            'url': opinion_url,
        })

        bot = get_object_or_404(
            User, username=settings.ZDS_APP['member']['bot_account'])
        send_mp(
            bot,
            article.authors.all(),
            _('Billet promu en article'),
            versionned_article.title,
            msg,
            True,
            direct=False,
            hat=get_hat_from_settings('validation'),
        )

        self.success_url = db_object.get_absolute_url()

        messages.success(
            self.request,
            _('Le billet a bien été promu en article et est en attente de validation.'
              ))

        return super(PromoteOpinionToArticle, self).form_valid(form)
Пример #4
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)
Пример #5
0
    def form_valid(self, form):
        # get database representation and validated version
        db_object = self.object
        versioned = self.versioned_object

        # get initial git path
        old_git_path = db_object.get_repo_path()

        # store data for later
        authors = db_object.authors.all()
        subcats = db_object.subcategory.all()
        tags = db_object.tags.all()
        article = PublishableContent(title=db_object.title,
                                     type='ARTICLE',
                                     creation_date=datetime.now(),
                                     sha_public=db_object.sha_public,
                                     public_version=None,
                                     licence=db_object.licence,
                                     sha_validation=db_object.sha_public,
                                     sha_draft=db_object.sha_public,
                                     image=db_object.image,
                                     source=db_object.source
                                     )

        opinion_url = db_object.get_absolute_url_online()
        article.save()
        # add M2M objects
        for author in authors:
            article.authors.add(author)
        for subcat in subcats:
            article.subcategory.add(subcat)
        for tag in tags:
            article.tags.add(tag)
        article.save()
        # add information about the conversion to the original opinion
        db_object.converted_to = article
        db_object.save()

        # clone the repo
        clone_repo(old_git_path, article.get_repo_path())
        versionned_article = article.load_version(sha=article.sha_validation)
        # mandatory to avoid path collision
        versionned_article.slug = article.slug
        article.sha_validation = versionned_article.repo_update(versionned_article.title,
                                                                versionned_article.get_introduction(),
                                                                versionned_article.get_conclusion())
        article.sha_draft = article.sha_validation
        article.save()
        # ask for validation
        validation = Validation()
        validation.content = article
        validation.date_proposition = datetime.now()
        validation.comment_authors = _('Promotion du billet « [{0}]({1}) » en article par [{2}]({3}).'.format(
            article.title,
            article.get_absolute_url_online(),
            self.request.user.username,
            self.request.user.profile.get_absolute_url()
        ))
        validation.version = article.sha_validation
        validation.save()
        # creating the gallery
        gal = Gallery()
        gal.title = db_object.gallery.title
        gal.slug = db_object.gallery.slug
        gal.pubdate = datetime.now()
        gal.save()
        article.gallery = gal
        # save updates
        article.save()
        article.ensure_author_gallery()

        # send message to user
        msg = render_to_string(
            'tutorialv2/messages/opinion_promotion.md',
            {
                'content': versioned,
                'url': opinion_url,
            })

        bot = get_object_or_404(User, username=settings.ZDS_APP['member']['bot_account'])
        send_mp(
            bot,
            article.authors.all(),
            _('Billet promu en article'),
            versionned_article.title,
            msg,
            True,
            direct=False,
            hat=get_hat_from_settings('validation'),
        )

        self.success_url = db_object.get_absolute_url()

        messages.success(self.request, _('Le billet a bien été promu en article et est en attente de validation.'))

        return super(PromoteOpinionToArticle, self).form_valid(form)