Beispiel #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)
Beispiel #2
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)