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 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 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 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)