def test_anchor_or_button(self): a = html.anchor_or_button('bla', href='/') self.assertEqual(a.tag, 'a') self.assertFalse(a.hasClass(classes.button)) self.assertEqual(a.attr('href'), '/') a = html.anchor_or_button('bla', href='/', asbutton=True) self.assertTrue(a.hasClass(classes.button))
def page_links(request, asbuttons=False, ul=None): '''Utility for displaying page navigation links.''' ul = ul if ul is not None else html.Widget('ul') view = request.view Page = view.Page if Page: # We are on a page application view if view.mapper == Page: page = request.instance if page: route = Route(page.url) urlargs = dict(request.GET.items()) try: path = route.url(**urlargs) except: path = '/' a = html.anchor_or_button('exit', href=path, icon='exit-page-edit', asbutton=asbuttons) ul.add(a) else: page = request.page page_request = request.for_model(Page) if page_request is not None: if page: kwargs = {NEXT_KEY: request.path} include = ('change',) else: kwargs = {'url': request.view.path} include = ('add',) for link in views.application_views_links( page_request, instance=page, include=include, asbuttons=asbuttons): kwargs.update(request.urlargs) href = link.attrs['href'] link.attrs['href'] = iri_to_uri(href, kwargs) ul.add(link) return ul
def application_links(views, asbuttons=True, icon=True, text=True, icon_size=None): '''A generator of two dimensional tuples containing the view name and a rendered html tag (either an anchor or a button). :parameter views: iterator over views obtained from :func:`application_views` :parameter asbuttons: optional flag for displaying links as button tags. :parameter icon_size: optional size for icon. ''' for elem in views: if not isinstance(elem, menu_link): elem = request_to_menu_link(elem) request = elem.view view = request.view icon = elem.icon if icon else None a = anchor_or_button(elem.display if text else '', href=elem.url, icon=icon, title=elem.title, asbutton=asbuttons, size=icon_size) a.addClass(view.name).addData({ 'view': view.name, 'method': elem.method, 'warning': view.warning_message(request), 'text': view.link_text }) if elem.ajax: method = elem.method.lower() a.addClass('ajax') if method == 'post': data = dict( view.site.submit_data_middleware.extra_form_data(request)) a.addData('submit', data) if asbuttons: a.addClass(view.link_class) yield view.name, a