Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed May 4, 2022
1 parent 5e592d2 commit d77d1f0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
* Convert various pages in the documentation to Markdown (Daniel Kirkham)
* Add `base_url_path` to `ModelAdmin` so that the default URL structure of app_label/model_name can be overridden (Vu Pham, Khanh Hoang)
* Add `full_url` to the API output of `ImageRenditionField` (Paarth Agarwal)
* Replace `PageRevision` with generic `Revision` model (Sage Abdullah)


3.0 (xx.xx.xxxx) - IN DEVELOPMENT
Expand Down
70 changes: 53 additions & 17 deletions docs/reference/pages/model_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -484,25 +484,43 @@ The ``locale`` and ``translation_key`` fields have a unique key constraint to pr
.. autoattribute:: localized


.. _page-revision-model-ref:
.. _revision-model-ref:

``PageRevision``
``Revision``
================

Every time a page is edited a new ``PageRevision`` is created and saved to the database. It can be used to find the full history of all changes that have been made to a page and it also provides a place for new changes to be kept before going live.
Every time a page is edited a new ``Revision`` is created and saved to the database. It can be used to find the full history of all changes that have been made to a page and it also provides a place for new changes to be kept before going live.

- Revisions can be created from any :class:`~wagtail.models.Page` object by calling its :meth:`~Page.save_revision` method
- The content of the page is JSON-serialisable and stored in the :attr:`~PageRevision.content` field
- You can retrieve a ``PageRevision`` as a :class:`~wagtail.models.Page` object by calling the :meth:`~PageRevision.as_page_object` method
- The content of the page is JSON-serialisable and stored in the :attr:`~Revision.content` field
- You can retrieve a ``Revision`` as a :class:`~wagtail.models.Page` object by calling the :meth:`~Revision.as_page_object` method

.. versionchanged:: 4.0

The model has been renamed from ``PageRevision`` to ``Revision`` and it now references the ``Page`` model using a combination of an ``object_id`` :class:`~django.db.models.CharField` and foreign keys to :class:`~django.contrib.contenttypes.models.ContentType`.

Database fields
~~~~~~~~~~~~~~~

.. class:: PageRevision
.. class:: Revision

.. attribute:: page
.. attribute:: content_type

(foreign key to :class:`~wagtail.models.Page`)
(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)

This is the content type of the object this revision belongs to. For page revisions, this means the content type of the specific page type.

.. attribute:: base_content_type

(foreign key to :class:`~django.contrib.contenttypes.models.ContentType`)

This is the base content type of the object this revision belongs to. For page revisions, this means the content type of the default page type.

.. attribute:: object_id

(string)

This represents the id of the object this revision belongs to.

.. attribute:: submitted_for_moderation

Expand Down Expand Up @@ -536,38 +554,52 @@ Database fields
Managers
~~~~~~~~

.. class:: PageRevision
.. class:: Revision
:noindex:

.. attribute:: objects

This manager is used to retrieve all of the ``PageRevision`` objects in the database
This manager is used to retrieve all of the ``Revision`` objects in the database

Example:

.. code-block:: python
PageRevision.objects.all()
Revision.objects.all()
.. attribute:: page_revisions

This manager is used to retrieve all of the ``Revision`` objects that belong to pages.

Example:

.. code-block:: python
Revision.page_revisions.all()
.. versionadded:: 4.0

This manager is added as a shorthand to retrieve page revisions.

.. attribute:: submitted_revisions

This manager is used to retrieve all of the ``PageRevision`` objects that are awaiting moderator approval
This manager is used to retrieve all of the ``Revision`` objects that are awaiting moderator approval

Example:

.. code-block:: python
PageRevision.submitted_revisions.all()
Revision.submitted_revisions.all()
Methods and properties
~~~~~~~~~~~~~~~~~~~~~~

.. class:: PageRevision
.. class:: Revision
:noindex:

.. automethod:: as_page_object

This method retrieves this revision as an instance of its :class:`~wagtail.models.Page` subclass.
This method retrieves this revision as an instance of its :class:`~wagtail.models.Page` subclass. This assumes that the revision belongs to a page.

.. automethod:: approve_moderation

Expand All @@ -579,11 +611,15 @@ Methods and properties

.. automethod:: is_latest_revision

Returns ``True`` if this revision is its page's latest revision
Returns ``True`` if this revision is the object's latest revision

.. automethod:: publish

Calling this will copy the content of this revision into the live page object. If the page is in draft, it will be published.
Calling this will copy the content of this revision into the live object. If the object is in draft, it will be published.

.. autoattribute:: content_object

This property returns the object this revision belongs to.

``GroupPagePermission``
=======================
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Signals
=======

Wagtail's :ref:`page-revision-model-ref` and :ref:`page-model-ref` implement
Wagtail's :ref:`revision-model-ref` and :ref:`page-model-ref` implement
:doc:`Signals <topics/signals>` from ``django.dispatch``.
Signals are useful for creating side-effects from page publish/unpublish events.

Expand All @@ -13,11 +13,11 @@ For example, you could use signals to send publish notifications to a messaging
``page_published``
------------------

This signal is emitted from a ``PageRevision`` when a revision is set to `published`.
This signal is emitted from a ``Revision`` when a page revision is set to `published`.

:sender: The page ``class``.
:instance: The specific ``Page`` instance.
:revision: The ``PageRevision`` that was published.
:revision: The ``Revision`` that was published.
:kwargs: Any other arguments passed to ``page_published.send()``.

To listen to a signal, implement ``page_published.connect(receiver, sender, **kwargs)``. Here's a simple
Expand Down
9 changes: 9 additions & 0 deletions docs/releases/4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ depth: 1
* Convert various pages in the documentation to Markdown (Daniel Kirkham)
* Add `base_url_path` to `ModelAdmin` so that the default URL structure of app_label/model_name can be overridden (Vu Pham, Khanh Hoang)
* Add `full_url` to the API output of `ImageRenditionField` (Paarth Agarwal)
* Replace `PageRevision` with generic `Revision` model (Sage Abdullah)

### Bug fixes

Expand All @@ -26,3 +27,11 @@ depth: 1
### `base_url_path` keyword argument added to AdminURLHelper

The `wagtail.contrib.modeladmin.helpers.AdminURLHelper` class now accepts a `base_url_path` keyword argument on its constructor. Custom subclasses of this class should be updated to accept this keyword argument.

### `PageRevision` replaced with `Revision`

The `PageRevision` model has been replaced with a generic `Revision` model. If you use the `PageRevision` model in your code, make sure that:

* Creation of `PageRevision` objects should be updated to create `Revision` objects using the page's `id` as the `object_id`, the default `Page` model's content type as the `base_content_type`, and the page's specific content type as the `content_type`.
* Queries that use the `PageRevision.objects` manager should be updated to use the `Revision.page_revision` manager.
* Queries for `Page` objects that use `PageRevision.page_id` should be updated to cast the `Revision.object_id` to an integer before using it in the query.

0 comments on commit d77d1f0

Please sign in to comment.