Skip to content

Commit 9917afc

Browse files
committed
Update tests
1 parent 3f14010 commit 9917afc

File tree

3 files changed

+88
-48
lines changed

3 files changed

+88
-48
lines changed

docs/api/advanced_configuration.rst

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ with different options.
1515
Adding to the context of versioning admin views
1616
------------------------------------------------
1717

18-
Currently versioning supports adding context variables to the unpublish confirmation view. Wider support for adding context variables is planned, but at the moment only the unpublish confirmation view is supported. This is how one would configure this in `cms_config.py`:
18+
Currently versioning supports adding context variables to the unpublish confirmation
19+
view. Wider support for adding context variables is planned, but at the moment only
20+
the unpublish confirmation view is supported. This is how one would configure this
21+
in ```cms_config.py```:
1922

2023
.. code-block:: python
2124
@@ -35,12 +38,16 @@ Currently versioning supports adding context variables to the unpublish confirma
3538
}
3639
3740
38-
Any context variable added to this setting will be displayed on the unpublish confirmation page automatically, but if you wish to change where on the page it displays, you will need to override the `djangocms_versioning/admin/unpublish_confirmation.html` template.
41+
Any context variable added to this setting will be displayed on the unpublish confirmation
42+
page automatically, but if you wish to change where on the page it displays, you will
43+
need to override the `djangocms_versioning/admin/unpublish_confirmation.html` template.
3944

4045

4146
Additional options on the VersionableItem class
4247
-------------------------------------------------
43-
The three mandatory attributes of `VersionableItem` are described in detail on the :doc:`versioning_integration` page. Below are additional options you might want to set.
48+
The three mandatory attributes of :class:`~djangocms_versioning.datastructures.VersionableItem`
49+
are described in detail on the :doc:`versioning_integration` page. Below are additional
50+
options you might want to set.
4451

4552

4653
.. _preview_url:
@@ -75,7 +82,8 @@ This will define the url that will be used for each version on the version list
7582

7683
extra_grouping_fields
7784
++++++++++++++++++++++
78-
Defines one or more :term:`extra grouping fields <extra grouping field>`. This will add a UI filter to the version list table enabling filtering by that field.
85+
Defines one or more :term:`extra grouping fields <extra grouping field>`. This will add a
86+
UI filter to the version list table enabling filtering by that field.
7987

8088
.. code-block:: python
8189
@@ -98,7 +106,8 @@ Defines one or more :term:`extra grouping fields <extra grouping field>`. This w
98106

99107
version_list_filter_lookups
100108
++++++++++++++++++++++++++++
101-
Must be defined if the :ref:`extra_grouping_fields` option has been set. This will let the UI filter know what values it should allow filtering by.
109+
Must be defined if the :ref:`extra_grouping_fields` option has been set. This will let the
110+
UI filter know what values it should allow filtering by.
102111

103112
.. code-block:: python
104113
@@ -121,12 +130,14 @@ Must be defined if the :ref:`extra_grouping_fields` option has been set. This wi
121130
grouper_selector_option_label
122131
++++++++++++++++++++++++++++++
123132

124-
If the version table link is specified without a grouper param, a form with a dropdown of grouper objects will display. By default, if the grouper object is registered with the
133+
If the version table link is specified without a grouper param, a form with a dropdown
134+
of grouper objects will display. By default, if the grouper object is registered with the
125135
admin and has a ``search_fields`` attribute, the dropdown will be an autocomplete
126136
field which will display the object's ``__str__`` method. This is the recommended
127137
method.
128138

129-
For models not registerd with the admin, or without search fields, this setting defines how the labels of those groupers will display on the dropdown (regular select field).
139+
For models not registerd with the admin, or without search fields, this setting defines
140+
how the labels of those groupers will display on the dropdown (regular select field).
130141

131142

132143
.. code-block:: python
@@ -152,7 +163,8 @@ For models not registerd with the admin, or without search fields, this setting
152163
153164
content_admin_mixin
154165
++++++++++++++++++++
155-
Versioning modifies how the admin of the :term:`content model <content model>` works with `VersioningAdminMixin`. But you can modify this mixin with this setting.
166+
Versioning modifies how the admin of the :term:`content model <content model>` works with
167+
:class:`~djangocms-versioning.admin.VersioningAdminMixin`. But you can modify this mixin with this setting.
156168

157169
.. code-block:: python
158170
@@ -179,44 +191,44 @@ Versioning modifies how the admin of the :term:`content model <content model>` w
179191
),
180192
]
181193
182-
grouper_admin_mixin
183-
++++++++++++++++++++
184-
This option allows you to customize the admin interface for the
185-
:term:`grouper model <grouper model>` by providing a custom ModelAdmin mixin.
186-
By default, versioning uses the standard admin, but you can override or extend
187-
its behavior using this setting.
188-
189-
To use, define your mixin class and set it on the `VersionableItem`:
190-
191-
.. code-block:: python
192-
193-
# some_app/cms_config.py
194-
from cms.app_base import CMSAppConfig
195-
from djangocms_versioning.datastructures import VersionableItem
196-
197-
class CustomGrouperAdminMixin:
198-
# Override ModelAdmin methods or attributes as needed
199-
def has_delete_permission(self, request, obj=None):
200-
return False
201-
202-
class SomeCMSConfig(CMSAppConfig):
203-
djangocms_versioning_enabled = True
204-
versioning = [
205-
VersionableItem(
206-
....,
207-
grouper_admin_mixin=CustomGrouperAdminMixin,
208-
),
209-
]
210-
211-
This mixin will be applied to the admin for the grouper model registered by
212-
versioning, allowing you to customize permissions, list display, or any other
213-
admin behavior.
214-
215-
Selecting the string ``"__default__"`` will use the
216-
:class:`djangocms_versioning.admin.DefaultGrouperVersioningAdminMixin`
217-
which combines the functionality of the
218-
:class:`djangocms_versioning.admin.StateIndicatorMixin` and the
219-
:class:`djangocms_versioning.admin.ExtendedGrouperVersionAdminMixin.
194+
grouper_admin_mixin
195+
++++++++++++++++++++
196+
This option allows you to customize the admin interface for the
197+
:term:`grouper model <grouper model>` by providing a custom ModelAdmin mixin.
198+
By default, versioning uses the standard admin, but you can override or extend
199+
its behavior using this setting.
200+
201+
To use, define your mixin class and set it on the `VersionableItem`:
202+
203+
.. code-block:: python
204+
205+
# some_app/cms_config.py
206+
from cms.app_base import CMSAppConfig
207+
from djangocms_versioning.datastructures import VersionableItem
208+
209+
class CustomGrouperAdminMixin:
210+
# Override ModelAdmin methods or attributes as needed
211+
def has_delete_permission(self, request, obj=None):
212+
return False
213+
214+
class SomeCMSConfig(CMSAppConfig):
215+
djangocms_versioning_enabled = True
216+
versioning = [
217+
VersionableItem(
218+
....,
219+
grouper_admin_mixin=CustomGrouperAdminMixin,
220+
),
221+
]
222+
223+
This mixin will be applied to the admin for the grouper model registered by
224+
versioning, allowing you to customize permissions, list display, or any other
225+
admin behavior.
226+
227+
Selecting the string ``"__default__"`` will use the
228+
:class:`~djangocms_versioning.admin.DefaultGrouperVersioningAdminMixin`
229+
which combines the functionality of the
230+
:class:`~djangocms_versioning.admin.StateIndicatorMixin` and the
231+
:class:`~djangocms_versioning.admin.ExtendedGrouperVersionAdminMixin`.
220232

221233
extended_admin_field_modifiers
222234
++++++++++++++++++++++++++++++

docs/introduction/versioning_integration.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ which we have used is sufficient, but in many cases you might need to write your
113113

114114
Once a model is registered for versioning its behaviour changes:
115115

116-
1. It's default manager (``Model.objects``) only sees published versions of the model. See :term:``content model``.
117-
2. It's ``Model.objects.create`` method now will not only create the :term:`content model` but also a corresponding ``Version`` model. Since the ``Version`` model requires a ``User`` object to track who created which version the correct way of creating a versioned :term:`content model` is::
116+
1. It's default manager (``Model.objects``) only sees published versions of the model.
117+
See :term:``content model``.
118+
2. It's ``Model.objects.create`` method now will not only create the :term:`content model`
119+
but also a corresponding ``Version`` model. Since the ``Version`` model requires a
120+
``User`` object to track who created which version the correct way of creating a
121+
versioned :term:`content model` is::
118122

119123
Model.objects.with_user(request.user).create(...)
120124

tests/test_admin.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,6 +3228,30 @@ def test_get_list_display(self):
32283228
self.assertIn("indicator", list_display_functions)
32293229
self.assertIn("list_actions", list_display_functions)
32303230

3231+
def test_can_change_content(self):
3232+
"""
3233+
The default grouper admin should allow changing content
3234+
"""
3235+
from djangocms_versioning.admin import ExtendedGrouperVersionAdminMixin
3236+
3237+
modeladmin = admin.site._registry[Poll]
3238+
modeladmin.language = "en"
3239+
request = self.get_request("/")
3240+
request.user = self.get_superuser()
3241+
3242+
draft_content = factories.PollContentWithVersionFactory(language="en")
3243+
public_content = factories.PollContentWithVersionFactory(language="en")
3244+
public_content.versions.first().publish(request.user)
3245+
3246+
3247+
self.assertIsInstance(modeladmin, ExtendedGrouperVersionAdminMixin)
3248+
can_change = modeladmin.can_change_content(request, None)
3249+
self.assertTrue(can_change)
3250+
can_change = modeladmin.can_change_content(request, draft_content)
3251+
self.assertTrue(can_change)
3252+
can_change = modeladmin.can_change_content(request, public_content)
3253+
self.assertFalse(can_change)
3254+
32313255

32323256
class ListActionsTestCase(CMSTestCase):
32333257
def setUp(self):

0 commit comments

Comments
 (0)