def has_change_permission(self, request, obj=None): if not obj: return False return page_permissions.user_can_change_page_permissions( request.user, page=obj, site=obj.node.site, )
def add_page_menu(self): if self.page and self.has_page_change_permission(): edit_mode = self.toolbar.edit_mode refresh = self.toolbar.REFRESH_PAGE # menu for current page # NOTE: disabled if the current path is "deeper" into the # application's url patterns than its root. This is because # when the Content Manager is at the root of the app-hook, # some of the page options still make sense. current_page_menu = self.toolbar.get_or_create_menu( PAGE_MENU_IDENTIFIER, _('Page'), position=1, disabled=self.in_apphook() and not self.in_apphook_root()) new_page_params = {'edit': 1, 'position': 'last-child'} new_sub_page_params = {'edit': 1, 'position': 'last-child', 'target': self.page.pk} if self.page.parent_id: new_page_params['target'] = self.page.parent_id can_add_sibling_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page.parent, ) else: can_add_sibling_page = page_permissions.user_can_add_page( user=self.request.user, site=self.current_site, ) can_add_sub_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page, ) # page operations menu add_page_menu = current_page_menu.get_or_create_menu( PAGE_MENU_ADD_IDENTIFIER, _('Create Page'), ) app_page_url = admin_reverse('cms_page_add') add_page_menu_modal_items = ( (_('New Page'), new_page_params, can_add_sibling_page), (_('New Sub Page'), new_sub_page_params, can_add_sub_page), (_('Duplicate this Page'), {'copy_target': self.page.pk}, can_add_sibling_page) ) for title, params, has_perm in add_page_menu_modal_items: params.update(language=self.toolbar.language) add_page_menu.add_modal_item( title, url=add_url_parameters(app_page_url, params), disabled=not has_perm, ) # first break current_page_menu.add_break(PAGE_MENU_FIRST_BREAK) # page edit page_edit_url = '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') current_page_menu.add_link_item(_('Edit this Page'), disabled=edit_mode, url=page_edit_url) # page settings page_settings_url = admin_reverse('cms_page_change', args=(self.page.pk,)) page_settings_url = add_url_parameters(page_settings_url, language=self.toolbar.language) current_page_menu.add_modal_item(_('Page settings'), url=page_settings_url, disabled=not edit_mode, on_close=refresh) # advanced settings advanced_url = admin_reverse('cms_page_advanced', args=(self.page.pk,)) advanced_url = add_url_parameters(advanced_url, language=self.toolbar.language) advanced_disabled = not edit_mode or not self.page.has_advanced_settings_permission(self.request.user) current_page_menu.add_modal_item(_('Advanced settings'), url=advanced_url, disabled=advanced_disabled) # templates menu if self.toolbar.build_mode or edit_mode: templates_menu = current_page_menu.get_or_create_menu('templates', _('Templates')) action = admin_reverse('cms_page_change_template', args=(self.page.pk,)) for path, name in get_cms_setting('TEMPLATES'): active = self.page.template == path if path == TEMPLATE_INHERITANCE_MAGIC: templates_menu.add_break(TEMPLATE_MENU_BREAK) templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active, on_success=refresh) # page type page_type_url = admin_reverse('cms_page_add_page_type') page_type_url = add_url_parameters(page_type_url, copy_target=self.page.pk, language=self.toolbar.language) current_page_menu.add_modal_item(_('Save as Page Type'), page_type_url, disabled=not edit_mode) # second break current_page_menu.add_break(PAGE_MENU_SECOND_BREAK) # permissions if self.permissions_activated: permissions_url = admin_reverse('cms_page_permissions', args=(self.page.pk,)) permission_disabled = not edit_mode if not permission_disabled: permission_disabled = not page_permissions.user_can_change_page_permissions( user=self.request.user, page=self.page, ) current_page_menu.add_modal_item(_('Permissions'), url=permissions_url, disabled=permission_disabled) # dates settings dates_url = admin_reverse('cms_page_dates', args=(self.page.pk,)) current_page_menu.add_modal_item(_('Publishing dates'), url=dates_url, disabled=not edit_mode) # third break current_page_menu.add_break(PAGE_MENU_THIRD_BREAK) # navigation toggle nav_title = _('Hide in navigation') if self.page.in_navigation else _('Display in navigation') nav_action = admin_reverse('cms_page_change_innavigation', args=(self.page.pk,)) current_page_menu.add_ajax_item(nav_title, action=nav_action, disabled=not edit_mode, on_success=refresh) # publisher if self.title: if self.title.published: publish_title = _('Unpublish page') publish_url = admin_reverse('cms_page_unpublish', args=(self.page.pk, self.current_lang)) else: publish_title = _('Publish page') publish_url = admin_reverse('cms_page_publish_page', args=(self.page.pk, self.current_lang)) user_can_publish = user_can_publish_page(self.request.user, page=self.page) current_page_menu.add_ajax_item( publish_title, action=publish_url, disabled=not edit_mode or not user_can_publish, on_success=refresh, ) # revert to live current_page_menu.add_break(PAGE_MENU_FOURTH_BREAK) revert_action = admin_reverse('cms_page_revert_to_live', args=(self.page.pk, self.current_lang)) revert_question = _('Are you sure you want to revert to live?') # Only show this action if the page has pending changes and a public version is_enabled = self.page.is_dirty(self.current_lang) and self.page.publisher_public current_page_menu.add_ajax_item( _('Revert to live'), action=revert_action, question=revert_question, disabled=not is_enabled, on_success=refresh, extra_classes=('cms-toolbar-revert',), ) # last break current_page_menu.add_break(PAGE_MENU_LAST_BREAK) # delete delete_url = admin_reverse('cms_page_delete', args=(self.page.pk,)) delete_disabled = not edit_mode or not user_can_delete_page(self.request.user, page=self.page) on_delete_redirect_url = self.get_on_delete_redirect_url() current_page_menu.add_modal_item(_('Delete page'), url=delete_url, on_close=on_delete_redirect_url, disabled=delete_disabled)
def add_page_menu(self): if self.page: edit_mode = self.toolbar.edit_mode_active refresh = self.toolbar.REFRESH_PAGE can_change = user_can_change_page( user=self.request.user, page=self.page, site=self.current_site, ) # menu for current page # NOTE: disabled if the current path is "deeper" into the # application's url patterns than its root. This is because # when the Content Manager is at the root of the app-hook, # some of the page options still make sense. current_page_menu = self.toolbar.get_or_create_menu( PAGE_MENU_IDENTIFIER, _('Page'), position=1, disabled=self.in_apphook() and not self.in_apphook_root()) new_page_params = {'edit': 1} new_sub_page_params = {'edit': 1, 'parent_node': self.page.node_id} if self.page.is_page_type: add_page_url = admin_reverse('cms_pagetype_add') advanced_url = admin_reverse('cms_pagetype_advanced', args=(self.page.pk, )) page_settings_url = admin_reverse('cms_pagetype_change', args=(self.page.pk, )) duplicate_page_url = admin_reverse('cms_pagetype_duplicate', args=[self.page.pk]) else: add_page_url = admin_reverse('cms_page_add') advanced_url = admin_reverse('cms_page_advanced', args=(self.page.pk, )) page_settings_url = admin_reverse('cms_page_change', args=(self.page.pk, )) duplicate_page_url = admin_reverse('cms_page_duplicate', args=[self.page.pk]) can_add_root_page = page_permissions.user_can_add_page( user=self.request.user, site=self.current_site, ) if self.page.parent_page: new_page_params['parent_node'] = self.page.parent_page.node_id can_add_sibling_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page.parent_page, ) else: can_add_sibling_page = can_add_root_page can_add_sub_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page, ) # page operations menu add_page_menu = current_page_menu.get_or_create_menu( PAGE_MENU_ADD_IDENTIFIER, _('Create Page'), ) add_page_menu_modal_items = ( (_('New Page'), new_page_params, can_add_sibling_page), (_('New Sub Page'), new_sub_page_params, can_add_sub_page), ) for title, params, has_perm in add_page_menu_modal_items: params.update(language=self.toolbar.request_language) add_page_menu.add_modal_item( title, url=add_url_parameters(add_page_url, params), disabled=not has_perm, ) add_page_menu.add_modal_item( _('Duplicate this Page'), url=add_url_parameters( duplicate_page_url, {'language': self.toolbar.request_language}), disabled=not can_add_sibling_page, ) # first break current_page_menu.add_break(PAGE_MENU_FIRST_BREAK) # page edit page_edit_url = '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') current_page_menu.add_link_item(_('Edit this Page'), disabled=edit_mode, url=page_edit_url) # page settings page_settings_url = add_url_parameters( page_settings_url, language=self.toolbar.request_language) settings_disabled = not edit_mode or not can_change current_page_menu.add_modal_item(_('Page settings'), url=page_settings_url, disabled=settings_disabled, on_close=refresh) # advanced settings advanced_url = add_url_parameters( advanced_url, language=self.toolbar.request_language) can_change_advanced = self.page.has_advanced_settings_permission( self.request.user) advanced_disabled = not edit_mode or not can_change_advanced current_page_menu.add_modal_item(_('Advanced settings'), url=advanced_url, disabled=advanced_disabled) # templates menu if edit_mode: if self.page.is_page_type: action = admin_reverse('cms_pagetype_change_template', args=(self.page.pk, )) else: action = admin_reverse('cms_page_change_template', args=(self.page.pk, )) if can_change_advanced: templates_menu = current_page_menu.get_or_create_menu( 'templates', _('Templates'), disabled=not can_change, ) for path, name in get_cms_setting('TEMPLATES'): active = self.page.template == path if path == TEMPLATE_INHERITANCE_MAGIC: templates_menu.add_break(TEMPLATE_MENU_BREAK) templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active, on_success=refresh) # page type if not self.page.is_page_type: page_type_url = admin_reverse('cms_pagetype_add') page_type_url = add_url_parameters( page_type_url, source=self.page.pk, language=self.toolbar.request_language) page_type_disabled = not edit_mode or not can_add_root_page current_page_menu.add_modal_item(_('Save as Page Type'), page_type_url, disabled=page_type_disabled) # second break current_page_menu.add_break(PAGE_MENU_SECOND_BREAK) # permissions if self.permissions_activated: permissions_url = admin_reverse('cms_page_permissions', args=(self.page.pk, )) permission_disabled = not edit_mode if not permission_disabled: permission_disabled = not page_permissions.user_can_change_page_permissions( user=self.request.user, page=self.page, ) current_page_menu.add_modal_item(_('Permissions'), url=permissions_url, disabled=permission_disabled) if not self.page.is_page_type: # dates settings dates_url = admin_reverse('cms_page_dates', args=(self.page.pk, )) current_page_menu.add_modal_item( _('Publishing dates'), url=dates_url, disabled=(not edit_mode or not can_change), ) # third break current_page_menu.add_break(PAGE_MENU_THIRD_BREAK) # navigation toggle nav_title = _( 'Hide in navigation') if self.page.in_navigation else _( 'Display in navigation') nav_action = admin_reverse('cms_page_change_innavigation', args=(self.page.pk, )) current_page_menu.add_ajax_item( nav_title, action=nav_action, disabled=(not edit_mode or not can_change), on_success=refresh, ) # publisher if self.title and not self.page.is_page_type: if self.title.published: publish_title = _('Unpublish page') publish_url = admin_reverse('cms_page_unpublish', args=(self.page.pk, self.current_lang)) else: publish_title = _('Publish page') publish_url = admin_reverse('cms_page_publish_page', args=(self.page.pk, self.current_lang)) user_can_publish = user_can_publish_page(self.request.user, page=self.page) current_page_menu.add_ajax_item( publish_title, action=publish_url, disabled=not edit_mode or not user_can_publish, on_success=refresh, ) if self.current_lang and not self.page.is_page_type: # revert to live current_page_menu.add_break(PAGE_MENU_FOURTH_BREAK) revert_action = admin_reverse('cms_page_revert_to_live', args=(self.page.pk, self.current_lang)) revert_question = _('Are you sure you want to revert to live?') # Only show this action if the page has pending changes and a public version is_enabled = (edit_mode and can_change and self.page.is_dirty(self.current_lang) and self.page.publisher_public) current_page_menu.add_ajax_item( _('Revert to live'), action=revert_action, question=revert_question, disabled=not is_enabled, on_success=refresh, extra_classes=('cms-toolbar-revert', ), ) # last break current_page_menu.add_break(PAGE_MENU_LAST_BREAK) # delete if self.page.is_page_type: delete_url = admin_reverse('cms_pagetype_delete', args=(self.page.pk, )) else: delete_url = admin_reverse('cms_page_delete', args=(self.page.pk, )) delete_disabled = not edit_mode or not user_can_delete_page( self.request.user, page=self.page) on_delete_redirect_url = self.get_on_delete_redirect_url() current_page_menu.add_modal_item(_('Delete page'), url=delete_url, on_close=on_delete_redirect_url, disabled=delete_disabled)
def add_page_menu(self): if self.page and self.has_page_change_permission(): edit_mode = self.toolbar.edit_mode refresh = self.toolbar.REFRESH_PAGE # menu for current page # NOTE: disabled if the current path is "deeper" into the # application's url patterns than its root. This is because # when the Content Manager is at the root of the app-hook, # some of the page options still make sense. current_page_menu = self.toolbar.get_or_create_menu( PAGE_MENU_IDENTIFIER, _('Page'), position=1, disabled=self.in_apphook() and not self.in_apphook_root()) new_page_params = {'edit': 1, 'position': 'last-child'} new_sub_page_params = { 'edit': 1, 'position': 'last-child', 'target': self.page.pk } if self.page.parent_id: new_page_params['target'] = self.page.parent_id can_add_sibling_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page.parent, ) else: can_add_sibling_page = page_permissions.user_can_add_page( user=self.request.user, site=self.current_site, ) can_add_sub_page = page_permissions.user_can_add_subpage( user=self.request.user, target=self.page, ) # page operations menu add_page_menu = current_page_menu.get_or_create_menu( PAGE_MENU_ADD_IDENTIFIER, _('Create Page'), ) app_page_url = admin_reverse('cms_page_add') add_page_menu_modal_items = ((_('New Page'), new_page_params, can_add_sibling_page), (_('New Sub Page'), new_sub_page_params, can_add_sub_page), (_('Duplicate this Page'), { 'copy_target': self.page.pk }, can_add_sibling_page)) for title, params, has_perm in add_page_menu_modal_items: params.update(language=self.toolbar.language) add_page_menu.add_modal_item( title, url=add_url_parameters(app_page_url, params), disabled=not has_perm, ) # first break current_page_menu.add_break(PAGE_MENU_FIRST_BREAK) # page edit page_edit_url = '?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') current_page_menu.add_link_item(_('Edit this Page'), disabled=edit_mode, url=page_edit_url) # page settings page_settings_url = admin_reverse('cms_page_change', args=(self.page.pk, )) page_settings_url = add_url_parameters( page_settings_url, language=self.toolbar.language) current_page_menu.add_modal_item(_('Page settings'), url=page_settings_url, disabled=not edit_mode, on_close=refresh) # advanced settings advanced_url = admin_reverse('cms_page_advanced', args=(self.page.pk, )) advanced_url = add_url_parameters(advanced_url, language=self.toolbar.language) advanced_disabled = not edit_mode or not self.page.has_advanced_settings_permission( self.request.user) current_page_menu.add_modal_item(_('Advanced settings'), url=advanced_url, disabled=advanced_disabled) # templates menu if self.toolbar.build_mode or edit_mode: templates_menu = current_page_menu.get_or_create_menu( 'templates', _('Templates')) action = admin_reverse('cms_page_change_template', args=(self.page.pk, )) for path, name in get_cms_setting('TEMPLATES'): active = self.page.template == path if path == TEMPLATE_INHERITANCE_MAGIC: templates_menu.add_break(TEMPLATE_MENU_BREAK) templates_menu.add_ajax_item(name, action=action, data={'template': path}, active=active, on_success=refresh) # page type page_type_url = admin_reverse('cms_page_add_page_type') page_type_url = add_url_parameters(page_type_url, copy_target=self.page.pk, language=self.toolbar.language) current_page_menu.add_modal_item(_('Save as Page Type'), page_type_url, disabled=not edit_mode) # second break current_page_menu.add_break(PAGE_MENU_SECOND_BREAK) # permissions if self.permissions_activated: permissions_url = admin_reverse('cms_page_permissions', args=(self.page.pk, )) permission_disabled = not edit_mode if not permission_disabled: permission_disabled = not page_permissions.user_can_change_page_permissions( user=self.request.user, page=self.page, ) current_page_menu.add_modal_item(_('Permissions'), url=permissions_url, disabled=permission_disabled) # dates settings dates_url = admin_reverse('cms_page_dates', args=(self.page.pk, )) current_page_menu.add_modal_item(_('Publishing dates'), url=dates_url, disabled=not edit_mode) # third break current_page_menu.add_break(PAGE_MENU_THIRD_BREAK) # navigation toggle nav_title = _( 'Hide in navigation') if self.page.in_navigation else _( 'Display in navigation') nav_action = admin_reverse('cms_page_change_innavigation', args=(self.page.pk, )) current_page_menu.add_ajax_item(nav_title, action=nav_action, disabled=not edit_mode, on_success=refresh) # publisher if self.title: if self.title.published: publish_title = _('Unpublish page') publish_url = admin_reverse('cms_page_unpublish', args=(self.page.pk, self.current_lang)) else: publish_title = _('Publish page') publish_url = admin_reverse('cms_page_publish_page', args=(self.page.pk, self.current_lang)) user_can_publish = user_can_publish_page(self.request.user, page=self.page) current_page_menu.add_ajax_item( publish_title, action=publish_url, disabled=not edit_mode or not user_can_publish, on_success=refresh, ) # last break current_page_menu.add_break(PAGE_MENU_LAST_BREAK) # delete delete_url = admin_reverse('cms_page_delete', args=(self.page.pk, )) delete_disabled = not edit_mode or not user_can_delete_page( self.request.user, page=self.page) on_delete_redirect_url = self.get_on_delete_redirect_url() current_page_menu.add_modal_item(_('Delete page'), url=delete_url, on_close=on_delete_redirect_url, disabled=delete_disabled)