8
8
from django .utils .translation import gettext as _
9
9
from django .utils .translation import override as force_language
10
10
11
- from cms .toolbar .utils import get_object_preview_url
11
+ from cms .toolbar .utils import (
12
+ get_object_edit_url ,
13
+ get_object_preview_url ,
14
+ )
12
15
13
16
14
17
class WizardBase :
@@ -18,7 +21,7 @@ class WizardBase:
18
21
template_name = None
19
22
20
23
def __init__ (self , title , weight , form , model = None , template_name = None ,
21
- description = None ):
24
+ description = None , edit_mode_on_success = True ):
22
25
"""
23
26
:param title: The title of the wizard. It will appear in a large font size on the wizard “menu”
24
27
:param weight: Used for determining the order of the wizards on the
@@ -32,14 +35,16 @@ def __init__(self, title, weight, form, model=None, template_name=None,
32
35
:param description: This is used on the start form. The description is optional, but if it is
33
36
not supplied, the CMS will create one from the pattern:
34
37
"Create a new «model.verbose_name» instance."
38
+ :param edit_mode_on_success: Whether the user will get redirected to object edit url after a
39
+ successful creation or not. This only works if the object is registered
40
+ for toolbar enabled models.
35
41
"""
36
- # NOTE: If class attributes or properties are changed, consider updating
37
- # cms.templatetags.cms_wizard_tags.WizardProperty too.
38
42
self .title = title
39
43
self .weight = weight
40
44
self .form = form
41
45
self .model = model
42
46
self .description = description
47
+ self .edit_mode_on_success = edit_mode_on_success
43
48
if template_name is not None :
44
49
self .template_name = template_name
45
50
@@ -129,9 +134,10 @@ def get_success_url(self, obj, **kwargs):
129
134
"""
130
135
Once the wizard has completed, the user will be redirected to the URL of the new
131
136
object that was created. By default, this is done by return the result of
132
- calling the ``get_absolute_url`` method on the object. This may then be modified
133
- to force the user into edit mode if the wizard property ``edit_mode_on_success``
134
- is True.
137
+ calling the ``get_absolute_url`` method on the object. If the object is registered
138
+ for toolbar enabled models, the object edit url will be returned. This may be modified
139
+ to return the preview url instead by setting the wizard property ``edit_mode_on_success``
140
+ to False.
135
141
136
142
In some cases, the created content will not implement ``get_absolute_url`` or
137
143
that redirecting the user is undesirable. In these cases, simply override this
@@ -144,6 +150,8 @@ def get_success_url(self, obj, **kwargs):
144
150
extension = apps .get_app_config ('cms' ).cms_extension
145
151
146
152
if obj .__class__ in extension .toolbar_enabled_models :
153
+ if self .edit_mode_on_success :
154
+ return get_object_edit_url (obj , language = kwargs .get ("language" , None ))
147
155
return get_object_preview_url (obj , language = kwargs .get ("language" , None ))
148
156
else :
149
157
if "language" in kwargs :
0 commit comments