Пример #1
0
    def add_revision(self,
                     newrevision,
                     request,
                     article_revision=None,
                     save=True):
        """
        Given a revision to make to the metadata, save it,
        and create a new article revision so they are in parallel unless one is provided.
        If an article revision is provided, then link the metadata revision to it;
        otherwise, initially save metadata_revision.article_revision as null
        (the signal triggered by the new article revision being saved will lead to this
        method being called again with the article_revision).
        """

        if article_revision is None:
            # first save the submitted metadata. article_revision will be null
            super(Metadata, self).add_revision(newrevision, save=save)

            # create article revision
            article_revision = ArticleRevision()
            article_revision.inherit_predecessor(self.article)
            article_revision.set_from_request(request)
            article_revision.automatic_log = newrevision.automatic_log
            self.article.add_revision(article_revision, save=save)
            # will trigger the on_article_revision_pre_save signal handler,
            # which calls this method again, supplying an article_revision
        else:
            # update the metadata revision so it is attached to an article_revision
            newrevision.article = self.article  # defined in ArticlePlugin, which SimplePlugin and RevisionPlugin both inherit from
            newrevision.article_revision = article_revision

            super(Metadata, self).add_revision(newrevision, save=save)
Пример #2
0
    def form_valid(self, form):
        """Create a new article revision for the bot wiki page when the form is valid"""

        # If the article content is different, add a new revision
        if form.instance.wiki_article.current_revision.content != form.cleaned_data['wiki_article_content']:
            revision = ArticleRevision()
            revision.inherit_predecessor(form.instance.wiki_article)
            revision.title = form.instance.name
            revision.content = form.cleaned_data['wiki_article_content']
            # revision.user_message = form.cleaned_data['summary']
            revision.deleted = False
            revision.set_from_request(self.request)
            form.instance.wiki_article.add_revision(revision)
        return super(BotUpdate, self).form_valid(form)
Пример #3
0
 def save(self, *args, **kwargs):
     self.instance = self.article.category
     data = self.cleaned_data
     oldparent = self.instance.parent
     newparent = data['parent']
     if newparent != oldparent:  # parent has changed
         # make a new revision of the article to record the change
         revision = ArticleRevision()
         revision.inherit_predecessor(self.article)
         revision.set_from_request(self.request)
         revision.parent = newparent
         revision.categories = self.article.categories
         if oldparent:
             oldparent = oldparent.name
         revision.automatic_log = f'Parent Category: {oldparent} → {newparent.name if newparent else "None"} (not revertible)'
         self.article.add_revision(revision)
         # reverting to a previous revision from the Changes page currently does not affect the category parent
     self.instance.parent = newparent
     self.instance.save()
     super(EditCategoryForm, self).save(*args, **kwargs)