def test_show_dropdown_menus(self): request = NavigationDummyRequest(path='/some-navigation-widget-left') root = get_root() result = navigation_widget_items(root, request) c1 = root[u'content_1'] = Content(title=u'Content_1') c1[u'sub_1'] = Content(title=u'Sub_1') c1[u'sub_1'][u'sub_sub_1'] = Content(title=u'Sub_Sub_1') c2 = root[u'content_2'] = Content(title=u'Content_2') c2[u'sub_2'] = Content(title=u'Sub_2') html = render_view( c1, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert not u'nav-list-careted' in html st = get_current_registry().settings st['kotti_navigation.navigation_widget.left_display_type'] = u'hor_pills_with_dropdowns' html = render_view( c1, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert u'nav-list-careted' in html
def test_include_content_types(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'options', ['stacked', 'include_root']) root[u'content_1'] = Content() root[u'content_2'] = Content() root[u'content_2'].in_navigation = False # If we include the content type the nav item is present. set_nav_setting('left', 'include', [Content.type_info.name]) html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'content_2' not in html # With an empty include_content_types, the nav item is not present. set_nav_setting('left', 'include', []) html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'content_2' not in html # Again, with show_hidden True. set_nav_setting('left', 'options', ['stacked', 'include_root', 'show_hidden_while_logged_in']) with patch('kotti_navigation.util.the_user', return_value='admin'): html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'content_2' in html
def test_exclude_content_types(self): root = get_root() request = DummyRequest() root[u'content_1'] = Content() # with no exclude the hidden nav points is shown html = render_view(root, request, name='navigation-widget') assert u'content_1' in html # if we exclude the content type the nav point disappears get_current_registry().settings['kotti_navigation.navigation_widget.exclude_content_types'] = u'kotti.resources.Content' html = render_view(root, request, name='navigation-widget') assert u'content_1' not in html
def test_is_tree_open(self): request = NavigationDummyRequest(path='/some-navigation-widget-left') root = get_root() root[u'content_1'] = Content() root[u'content_1'][u'sub_1'] = Content() root[u'content_2'] = Content() root[u'content_2'][u'sub_2'] = Content() request.context = root html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' not in html request.context = root[u'content_1'] html = render_view(root[u'content_1'], request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' not in html request.context = root[u'content_2'] html = render_view(root[u'content_2'], request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html request.context = root[u'content_2'][u'sub_2'] html = render_view(root[u'content_2'][u'sub_2'], request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html se = get_current_registry().settings se['kotti_navigation.navigation_widget.left_display_type'] = u'ver_tabs_stacked_open_all' request.context = root html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' in html
def test_exclude_content_types(self): root = get_root() request = NavigationDummyRequest(path='/some-navigation-widget-left') root[u'content_1'] = Content() # with no exclude the hidden nav items is shown html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html # if we exclude the content type the nav item disappears se = get_current_registry().settings se['kotti_navigation.navigation_widget.left_exclude_content_types'] =\ u'kotti.resources.Content' html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' not in html
def test_exclude_content_types(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'options', ['stacked', 'include_root']) root[u'content_1'] = Content() # with no exclude the hidden nav items is shown html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html # if we exclude the content type the nav item disappears set_nav_setting('left', 'exclude', [Content.type_info.name]) html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' not in html
def test_is_tree_open(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'options', ['stacked', 'include_root']) root[u'content_1'] = Content() root[u'content_1'][u'sub_1'] = Content() root[u'content_2'] = Content() root[u'content_2'][u'sub_2'] = Content() self.request.context = root html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' not in html self.request.context = root[u'content_1'] html = render_view(root[u'content_1'], self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' not in html self.request.context = root[u'content_2'] html = render_view(root[u'content_2'], self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html self.request.context = root[u'content_2'][u'sub_2'] html = render_view(root[u'content_2'][u'sub_2'], self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html set_nav_setting('left', 'options', ['stacked', 'open_all']) self.request.context = root html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' in html
def test_render_widget(self): root = get_root() self.request = NavigationDummyRequest(slot='top') set_nav_setting('top', 'options', ['stacked', 'include_root']) html = render_view(root, self.request, name='navigation-widget-tree') assert '<ul class="nav nav-pills nav-stacked">' in html
def test_render_widget(self): root = get_root() html = render_view( root, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert ' class="nav nav-pills"' in html
def test_render_widget(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'display_manner', 'tabs') set_nav_setting('left', 'options', ['stacked', 'include_root']) html = render_view(root, self.request, name='navigation-widget-tree') assert '<ul class="nav nav-tabs nav-stacked">' in html
def test_render_widget(self): root = get_root() html = render_view( root, NavigationDummyRequest(path='/some-navigation-widget-top'), name='navigation-widget-tree-top') assert '<ul class="nav nav-tabs nav-stacked">' in html
def test_is_tree_open(self): request = NavigationDummyRequest() root = get_root() root[u'content_1'] = Content() root[u'content_1'][u'sub_1'] = Content() root[u'content_2'] = Content() root[u'content_2'][u'sub_2'] = Content() request.context = root html = render_view(root, request, name='navigation-widget') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' not in html request.context = root[u'content_1'] html = render_view(root[u'content_1'], request, name='navigation-widget') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' not in html request.context = root[u'content_2'] html = render_view(root[u'content_2'], request, name='navigation-widget') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html request.context = root[u'content_2'][u'sub_2'] html = render_view(root[u'content_2'][u'sub_2'], request, name='navigation-widget') assert u'content_1' in html assert u'sub_1' not in html assert u'content_2' in html assert u'sub_2' in html se = get_current_registry().settings se['kotti_navigation.navigation_widget.open_all'] = u'true' request.context = root html = render_view(root, request, name='navigation-widget') assert u'content_1' in html assert u'sub_1' in html assert u'content_2' in html assert u'sub_2' in html
def test_show_hidden(self): root = get_root() request = DummyRequest() root[u'content_1'] = Content() root[u'content_2'] = Content() root[u'content_2'].in_navigation = False # with standard settings the hidden nav points are hidden html = render_view(root, request, name='navigation-widget') assert u'content_1' in html assert u'content_2' not in html # if we change the setting, the nav points still hidden get_current_registry().settings['kotti_navigation.navigation_widget.show_hidden_while_logged_in'] = u'true' html = render_view(root, request, name='navigation-widget') assert u'content_1' in html assert u'content_2' not in html
def test_render_widget(self): self.request = NavigationDummyRequest(slot='top') root = get_root() root[u'content_1'] = Content(title=u'Content_1') self.request.context = root[u'content_1'] html = render_view(root[u'content_1'], self.request, name='navigation-widget-menu') assert '<ul class="nav nav-list">' in html
def test_render_widget(self): request = NavigationDummyRequest(path='/some-navigation-widget-beforebodyend') root = get_root() root[u'content_1'] = Content(title=u'Content_1') request.context = root[u'content_1'] html = render_view(root[u'content_1'], request, name='navigation-widget-tree-beforebodyend') assert '<ul class="nav nav-tabs nav-stacked">' in html
def test_render_widget(self): request = NavigationDummyRequest(path='/some-navigation-widget-beforebodyend') root = get_root() root[u'content_1'] = Content(title=u'Content_1') root[u'content_1'][u'sub_1'] = Content(title=u'Sub_1') request.context = root[u'content_1'][u'sub_1'] html = render_view(root[u'content_1'][u'sub_1'], request, name='navigation-widget-breadcrumbs-beforebodyend') assert 'You are here:' in html
def test_render_widget(self): request = NavigationDummyRequest(path='/some-navigation-widget-right') root = get_root() root[u'content_1'] = Content(title=u'Content_1') request.context = root[u'content_1'] html = render_view(root[u'content_1'], request, name='navigation-widget-tree-right') assert '<ul class="nav nav-tabs nav-stacked">' in html
def test_include_content_types(self): root = get_root() request = NavigationDummyRequest(path='/some-navigation-widget-left') root[u'content_1'] = Content() root[u'content_2'] = Content() root[u'content_2'].in_navigation = False # If we include the content type the nav item is present. se = get_current_registry().settings se['kotti_navigation.navigation_widget.left_include_content_types'] =\ u'kotti.resources.Content' html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html # With an empty include_content_types, the nav item is not present. se['kotti_navigation.navigation_widget.left_include_content_types'] =\ u'' html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html
def test_show_hidden(self): root = get_root() request = NavigationDummyRequest(path='/some-navigation-widget-left') root[u'content_1'] = Content() root[u'content_2'] = Content() root[u'content_2'].in_navigation = False # with standard settings the hidden nav items are hidden html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'content_2' not in html # if we change the setting, the nav items still hidden se = get_current_registry().settings se['kotti_navigation.navigation_widget.left_show_hidden_while_logged_in'] =\ u'true' html = render_view(root, request, name='navigation-widget-tree-left') assert u'content_1' in html assert u'content_2' not in html
def tile_content(context, request, url=None, size_x=None, use=None, custom_text=None, extra_style=None): if url is None and "url" in request.POST: url = request.POST["url"] if use is None and "use" in request.POST: use = request.POST["use"] if custom_text is None and "custom_text" in request.POST: custom_text = request.POST["custom_text"] if extra_style is None and "extra_style" in request.POST: extra_style = request.POST["extra_style"] if size_x is None and "size_x" in request.POST: size_x = request.POST["size_x"] if url == "" or url is None or url is False: request.content_url = None current_context = context else: resource = None app_url = request.application_url parsed_url = urlparse(url) base_url = "{}://{}".format(parsed_url.scheme, parsed_url.netloc) if app_url.startswith(base_url) or url.startswith("/"): try: resource = find_resource(context, parsed_url.path) except KeyError: return _(u"Can't find resource with path {0}.".format(parsed_url.path)) request.image = None if resource is not None: current_context = resource if use == u"use_internal_image": tree = nodes_tree(request, context=resource).tolist() if tree: resource_images = [obj for obj in tree if IImage.providedBy(obj)] if resource_images: request.image = resource_images[0] request.content_url = request.resource_url(resource) request.target = "_self" else: current_context = context request.content_url = url request.target = "_blank" request.view_name = "tile-view" request.size = 2 if size_x: request.size = int(size_x) + 2 request.use = None if use is not None: request.use = use request.extra_style = u"" if extra_style is not None: request.extra_style = extra_style if custom_text is not None: request.custom_text = custom_text return render_view(current_context, request, name="tile-view")
def test_render_widget(self): self.request = NavigationDummyRequest(slot='beforebodyend') root = get_root() root[u'content_1'] = Content(title=u'Content_1') self.request.context = root[u'content_1'] set_nav_setting('beforebodyend', 'display_type', 'tree') set_nav_setting('beforebodyend', 'options', ['stacked', 'include_root', 'open_all']) html = render_view(root[u'content_1'], self.request, name='navigation-widget-tree') assert '<ul class="nav nav-pills nav-stacked">' in html
def test_render_widget(self): request = NavigationDummyRequest( path='/some-navigation-widget-beforebodyend') root = get_root() root[u'content_1'] = Content(title=u'Content_1') root[u'content_1'][u'sub_1'] = Content(title=u'Sub_1') request.context = root[u'content_1'][u'sub_1'] html = render_view(root[u'content_1'][u'sub_1'], request, name='navigation-widget-breadcrumbs-beforebodyend') assert 'You are here:' in html
def test_show_dropdown_menus(self): root = get_root() c1 = root[u'content_1'] = Content(title=u'Content_1') c1[u'sub_1'] = Content(title=u'Sub_1') c1[u'sub_1'][u'sub_sub_1'] = Content(title=u'Sub_Sub_1') c2 = root[u'content_2'] = Content(title=u'Content_2') c2[u'sub_2'] = Content(title=u'Sub_2') set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'options', []) html = render_view(c1, self.request, name='navigation-widget-items') assert u'nav-list-careted' not in html set_nav_setting('left', 'display_type', 'items') set_nav_setting('left', 'options', ['pills', 'dropdowns']) html = render_view(c1, self.request, name='navigation-widget-items') assert u'nav-list-careted' in html
def test_render_widget(self): self.request = NavigationDummyRequest(slot='beforebodyend') root = get_root() root[u'content_1'] = Content(title=u'Content_1') root[u'content_1'][u'sub_1'] = Content(title=u'Sub_1') self.request.context = root[u'content_1'][u'sub_1'] set_nav_setting('beforebodyend', 'display_type', 'breadcrumbs') set_nav_setting('beforebodyend', 'show_in_context', 'everywhere') set_nav_setting('beforebodyend', 'options', ['include_root']) set_nav_setting('beforebodyend', 'label', 'You are here:') html = render_view(root[u'content_1'][u'sub_1'], self.request, name='navigation-widget') assert 'You are here:' in html
def test_is_node_open(self): request = NavigationDummyRequest(path='/some-navigation-widget-left') root = get_root() root[u'content_1'] = Content() root[u'content_1'][u'sub_1'] = Content() root[u'content_2'] = Content() root[u'content_2'][u'sub_2'] = Content() request.context = root html = render_view(root, request, name='navigation-widget-tree-left') assert is_node_open(root, request) assert is_node_open(root['content_1'], request) == False assert is_node_open(root['content_2'], request) == False
def navigation_widget(self): show_here = get_setting(self.location + "_show_in_context") show = show_in_context(show_here, self.context) if not show: raise PredicateMismatch() display_type = get_setting(self.location + "_display_type") if not display_type: raise PredicateMismatch() view_name = "navigation-widget-" + display_type return render_view(self.context, self.request, name=view_name)
def test_show_hidden(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'options', ['stacked', 'include_root']) root[u'content_1'] = Content() root[u'content_2'] = Content() root[u'content_2'].in_navigation = False # with standard settings the hidden nav items are hidden html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'content_2' not in html # if we change the setting, the nav items still hidden set_nav_setting('left', 'options', ['tabs', 'stacked', 'include_root', 'show_hidden_while_logged_in']) with patch('kotti_navigation.util.the_user', return_value='admin'): html = render_view(root, self.request, name='navigation-widget-tree') assert u'content_1' in html assert u'content_2' in html
def test_show_dropdown_menus(self): request = NavigationDummyRequest(path='/some-navigation-widget-left') root = get_root() result = navigation_widget_items(root, request) c1 = root[u'content_1'] = Content(title=u'Content_1') c1[u'sub_1'] = Content(title=u'Sub_1') c1[u'sub_1'][u'sub_sub_1'] = Content(title=u'Sub_Sub_1') c2 = root[u'content_2'] = Content(title=u'Content_2') c2[u'sub_2'] = Content(title=u'Sub_2') html = render_view(c1, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert not u'nav-list-careted' in html st = get_current_registry().settings st['kotti_navigation.navigation_widget.left_display_type'] = u'hor_pills_with_dropdowns' html = render_view(c1, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert u'nav-list-careted' in html
def test_show_dropdown_menus(self): request = NavigationDummyRequest() root = get_root() result = navigation_widget(root, request) assert result['show_dropdown_menus'] == False c1 = root[u'content_1'] = Content(title=u'Content_1') c1[u'sub_1'] = Content(title=u'Sub_1') c1[u'sub_1'][u'sub_sub_1'] = Content(title=u'Sub_Sub_1') c2 = root[u'content_2'] = Content(title=u'Content_2') c2[u'sub_2'] = Content(title=u'Sub_2') html = render_view(c1, NavigationDummyRequest(), name='navigation-widget') assert not u'nav-list-careted' in html st = get_current_registry().settings st['kotti_navigation.navigation_widget.show_dropdown_menus'] = u'true' html = render_view(c1, NavigationDummyRequest(), name='navigation-widget') assert u'nav-list-careted' in html
def tile_content(context, request, url=None, size_x=None): if url is None and 'url' in request.GET: url = request.GET['url'] if url is None: return u'' if size_x is None and 'size_x' in request.GET: size_x = request.GET['size_x'] path = urlparse(url).path try: resource = find_resource(context, path) except KeyError: return _(u"Can't find resource with path {0}.".format(path)) request.view_name = "tile-view" request.size = 2 if size_x: request.size = int(size_x) + 2 return render_view(resource, request, name="tile-view")
def test_render_widget(self): root = get_root() html = render_view(root, NavigationDummyRequest(), name='navigation-widget') assert '<ul class="nav nav-pills nav-stacked">' in html
def test_render_widget(self): root = get_root() html = render_view(root, NavigationDummyRequest(path='/some-navigation-widget-left'), name='navigation-widget-items-left') assert ' class="nav nav-pills"' in html
def test_render_widget(self): root = get_root() html = render_view(root, NavigationDummyRequest(path='/some-navigation-widget-top'), name='navigation-widget-tree-top') assert '<ul class="nav nav-tabs nav-stacked">' in html
def test_render_widget(self): root = get_root() set_nav_setting('left', 'display_type', 'tree') set_nav_setting('left', 'display_manner', 'tabs') html = render_view(root, self.request, name='navigation-widget-items') assert ' class="nav nav-tabs"' in html