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_version()[source]¶ Get the version of this object.
If the version is 0, the object has never been published.
- Return int
incremental version number
-
classmethod
get_newest(obj)[source]¶ Get the newest version of that object.
Might return the same object.
-
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
versionof 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
historykey, 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=XXXparameter, to get just one specific version. You can also specifylatestto get the newest published version.Returns the requested object in the
objectkey, example response:{ "status": true, "object": { "name": "My object", "_history": { "id": "someobjectid", "version": 3 } } }
-