0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-28 00:17:06 +01:00

syntactic sugar for get_page_modes: change it to a property called preview_modes and add a default_preview_mode helper

Conflicts:
	wagtail/wagtailadmin/views/pages.py
This commit is contained in:
Matt Westcott 2014-06-12 16:48:44 +01:00
parent dd52ccab2a
commit 78481dc846
5 changed files with 28 additions and 27 deletions

View File

@ -201,6 +201,7 @@ Properties:
* status_string
* subpage_types
* indexed_fields
* preview_modes
Methods:
@ -213,7 +214,6 @@ Methods:
* get_descendants
* get_siblings
* search
* get_page_modes
* show_as_mode

View File

@ -190,10 +190,10 @@ Load Alternate Templates by Overriding get_template()
Page Modes
----------
Preview Modes
-------------
get_page_modes
preview_modes
show_as_mode

View File

@ -230,7 +230,7 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
'page_class': page_class,
'parent_page': parent_page,
'edit_handler': edit_handler,
'display_modes': page.get_page_modes(),
'display_modes': page.preview_modes,
'form': form, # Used in unit tests
})
@ -361,7 +361,7 @@ def edit(request, page_id):
'page': page,
'edit_handler': edit_handler,
'errors_debug': errors_debug,
'display_modes': page.get_page_modes(),
'display_modes': page.preview_modes,
'form': form, # Used in unit tests
})
@ -409,12 +409,8 @@ def preview_on_edit(request, page_id):
if form.is_valid():
form.save(commit=False)
try:
display_mode = request.GET['mode']
except KeyError:
display_mode = page.get_page_modes()[0][0]
response = page.show_as_mode(display_mode)
preview_mode = request.GET.get('mode', page.default_preview_mode)
response = page.show_as_mode(preview_mode)
response['X-Wagtail-Preview'] = 'ok'
return response
@ -425,7 +421,7 @@ def preview_on_edit(request, page_id):
response = render(request, 'wagtailadmin/pages/edit.html', {
'page': page,
'edit_handler': edit_handler,
'display_modes': page.get_page_modes(),
'display_modes': page.preview_modes,
})
response['X-Wagtail-Preview'] = 'error'
return response
@ -458,11 +454,8 @@ def preview_on_create(request, content_type_app_name, content_type_model_name, p
page.depth = parent_page.depth + 1
page.path = Page._get_children_path_interval(parent_page.path)[1]
try:
display_mode = request.GET['mode']
except KeyError:
display_mode = page.get_page_modes()[0][0]
response = page.show_as_mode(display_mode)
preview_mode = request.GET.get('mode', page.default_preview_mode)
response = page.show_as_mode(preview_mode)
response['X-Wagtail-Preview'] = 'ok'
return response
@ -476,7 +469,7 @@ def preview_on_create(request, content_type_app_name, content_type_model_name, p
'page_class': page_class,
'parent_page': parent_page,
'edit_handler': edit_handler,
'display_modes': page.get_page_modes(),
'display_modes': page.preview_modes,
})
response['X-Wagtail-Preview'] = 'error'
return response

View File

@ -706,19 +706,28 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, Indexed)):
"request middleware returned a response")
return request
def get_page_modes(self):
@property
def preview_modes(self):
"""
Return a list of (internal_name, display_name) tuples for the modes in which
A list of (internal_name, display_name) tuples for the modes in which
this page can be displayed for preview/moderation purposes. Ordinarily a page
will only have one display mode, but subclasses of Page can override this -
for example, a page containing a form might have a default view of the form,
and a post-submission 'thankyou' page
"""
return self.get_page_modes()
def get_page_modes(self):
# Deprecated accessor for the preview_modes property
return [('', 'Default')]
@property
def default_preview_mode(self):
return self.preview_modes[0][0]
def show_as_mode(self, mode_name):
"""
Given an internal name from the get_page_modes() list, return an HTTP response
Given an internal name from the preview_modes list, return an HTTP response
indicative of the page being viewed in that mode. By default this passes a
dummy request into the serve() mechanism, ensuring that it matches the behaviour
on the front-end; subclasses that define additional page modes will need to

View File

@ -170,11 +170,10 @@ class AbstractForm(Page):
'form': form,
})
def get_page_modes(self):
return [
('form', 'Form'),
('landing', 'Landing page'),
]
preview_modes = [
('form', 'Form'),
('landing', 'Landing page'),
]
def show_as_mode(self, mode):
if mode == 'landing':