def navigation_move(route, order, **kwargs): if Content.objects(route=route).first() is None: raise InvalidCommand("route '{0}' does not exist in content collection".format(route)) if Content.objects(route=route, show_in_navigation=True).first() is None: raise InvalidCommand("route '{0}' is not visible in navigation".format(route)) nav_order = NavigationOrder.objects(route=route).first() if nav_order is None: # This probably shouldn't happen. nav_order = NavigationOrder.add(route=route) nav_order.move(order)
def testNavigationOrderPopulate(self): Content(route='athing', show_in_navigation=True).save() Content(route='bthing', show_in_navigation=True).save() Content(route='notathing').save() ContentNavigationOrder.populate_from_content() eq_(NavigationOrder.objects(order=0).first().route, 'athing') eq_(NavigationOrder.objects(order=1).first().route, 'bthing') eq_(NavigationOrder.objects(order=2).first(), None)
def load_from_file(route, title, short_description, content_filename, show_in_navigation, **kwargs): content = Content() content.route = route content.title = title content.short_description = short_description content.show_in_navigation = show_in_navigation if show_in_navigation and (NavigationOrder.objects(route=route).first() is None): NavigationOrder.add(route=route) with open(content_filename) as content_file: content.content = '\n'.join(content_file.readlines()) content.save()
def testIndexRoute(self): content = Content() content.route = '/' content.title = 'Test Title' content.short_description = 'Test Description' content.content = 'Test Content' content.show_in_navigation = True content.save() NavigationOrder.add('/') rsp = self.app.get('/') eq_(rsp.status_code, 200) e = etree.HTML(rsp.data) eq_(e.find('./head/title').text, 'Test Title') eq_(e.find(".//div[@id='content']/p").text, 'Test Content') eq_(e.find(".//ul[@id='navigation']//a[@href='/']").text, 'Test Title')
def testNavigationOrderMoveOverExisting(self): NavigationOrder(route='a', order=0).save() n = NavigationOrder(route='b', order=1) n.save() n.move(0) eq_(NavigationOrder.objects(order=0).first().route, 'b') eq_(NavigationOrder.objects(order=1).first().route, 'a')
def test_no_nav_order(self): Content(route='a', show_in_navigation=True).save() navigation_move('a', 1) eq_(NavigationOrder.objects(route='a').first().order, 1)
def get_navigables_in_order(): return [Content.objects(route=r).first() for r in NavigationOrder.get_routes_in_order()]
def testAddToEmpty(self): NavigationOrder.add('a') eq_(NavigationOrder.objects(route='a').first().order, 0)
def testAdd(self): NavigationOrder(route='a', order=10).save() NavigationOrder.add('b') eq_(NavigationOrder.objects(route='b').first().order, 11)
def testMoveOverSelf(self): n = NavigationOrder(route='a', order=0) n.save() n.move(0) eq_(NavigationOrder.objects(order=0).first().route, 'a')