Versioning

Versioning different states of models in a point in time has been implemented using the VersionsMixin, it provides several API methods that can be invoked by using the api_model_instance_call_route() route.

class VersionsMixin[source]

Model mixin that allows archiving different versions of a model instance.

TODO: Magic methods that will query the history database if the real document has been deleted for whatever reason.

get_real_id()[source]

Get the original document’s ObjectId.

get_version()[source]

Get the version of this object.

If the version is 0, the object has never been published.

Return int

incremental version number

get_status()[source]

Get the status for a page.

Can be either one of STATUS_CHOICES.

get_status_name()[source]

Get a human readable status name.

classmethod get_newest(obj)[source]

Get the newest version of that object.

Might return the same object.

classmethod get_by_id(obj_id)[source]

Get an object by its original ObjectId.

classmethod get_by_version(obj_id, version)[source]

Get a specific version of the specified object.

Parameters
  • obj_id – ObjectId to look for.

  • version – Can be a number, 'latest' or 'draft'.

classmethod get_by_version_or_404(obj_id, version)[source]

Get a specific version of the specified object.

Trigger a 404 when we don’t find the object.

Parameters
  • obj_id – ObjectId to look for.

  • version – Can be a number, 'latest' or 'draft'.

api_publish()[source]

Save a new copy of this object in the history collection.

Requires no parameters.

Returns the version of the newly published document, example response:

{
    "status": true,
    "version": 3
}
api_publish_tree()[source]

Publish all draft pages below and including the given page.

Requires no parameters.

Returns the number of published pages in published_count, example response:

{
    "published_count": 3
}
classmethod pre_save(sender, document, **kwargs)[source]

Set this object’s dirty status so we know there have been changes since last publish.

api_history()[source]

Get this object’s history sorted by newest first.

Returns a list of objects in the history key, example response:

{
    "status": true,
    "history": [
        {
            "name": "My newest version",
            "_history": {
                "id": "someobjectid",
                "version": 2
            }
        },
        {
            "name": "My old version",
            "_history": {
                "id": "someobjectid",
                "version": 1
            }
        }
    ]
}
api_version(version)[source]

Get a specific version of this object.

Request with version=XXX parameter, to get just one specific version. You can also specify latest to get the newest published version.

Returns the requested object in the object key, example response:

{
    "status": true,
    "object": {
        "name": "My object",
        "_history": {
            "id": "someobjectid",
            "version": 3
        }
    }
}
delete(with_history=False, **kwargs)[source]

Delete this object and optionally with its entire history.

Unless with_history is set, a new ‘deleted’ record will be created in the history.

Parameters

with_history (bool) – Also delete all corresponding history entries.