Revisioned content

Nodular’s RevisionedNodeMixin base class helps make models with revisioned content.

class nodular.revisioned.RevisionedNodeMixin

RevisionedNodeMixin replaces NodeMixin for models that need to keep their entire contents under revision control. A revisioned node can have multiple simultaneously active versions (each with a label) or archived versions (label=None).

Revisions are stored as distinct table rows with full content, not as diffs. All columns that need revisioning must be in the RevisionMixin model, not in the RevisionedNodeMixin model. Usage:

class MyDocument(RevisionedNodeMixin, Node):
    __tablename__ = u'my_document'

class MyDocumentRevision(MyDocument.RevisionMixin, db.Model):
    # __tablename__ is auto-generated
    content = db.Column(db.UnicodeText)
revise(revision=None, user=None, workflow_label=None)

Clone the given revision or make a new blank revision.

Returns:New revision object
set_workflow_label(revision, workflow_label)

Set the workflow label for the given revision.

class nodular.revisioned.RevisionedNodeMixin.RevisionMixin

The RevisionMixin base class is available from subclasses of RevisionedNodeMixin. It describes the model for a revision of the RevisionedNodeMixin node and defines relationships between the two models.

For usage instructions, see RevisionedNodeMixin.

RevisionMixin adds the following attributes and methods to your class.


Refers to the parent RevisionedNodeMixin subclass for which this model stores content revisions.


Autogenerated table name (parent table name with '_revision' suffixed).


Id and relationship to the parent model instance. The foreign key constraint refers to the parent model and not to the Node table to ensure that a revision cannot be accidentally attached to the wrong type of node.


Unique workflow status code for this node, None for archived revisions. A given revision code may be used by only one revision in a document, to indicate a revision currently flagged as Draft, Pending or Published.


The user who created this revision. In a multi-user editing environment, only one user can be tagged as the creator of the revision.


Id and relationship to previous revision that revision revises.


Copies this revision into a new revision attached to the same parent model. copy() is not content aware; your subclass will need to override copy() to copy contents:

class MyDocumentRevision(MyDocument.RevisionMixin, db.Model):
    content = db.Column(db.UnicodeText)

    def copy(self):
        revision = super(MyDocumentRevision, self).copy()
        revision.content = self.content
        return revision