Esempio n. 1
0
    def setUp(self):
        self.nav = Nav(title="Test Nav")
        self.nav.save()
        NavItem.objects.create(label="Test Item 1",
                               nav=self.nav,
                               level=0,
                               position=0)
        NavItem.objects.create(label="Test Item 2",
                               nav=self.nav,
                               level=0,
                               position=1)
        NavItem.objects.create(label="Test Item 3",
                               nav=self.nav,
                               level=0,
                               position=2)
        self.add_url = '/admin/navs/nav/add/'
        self.change_url = '/admin/navs/nav/%i/' % self.nav.id

        self.client = Client()
        username = '******'
        email = '*****@*****.**'
        password = '******'
        User.objects.create_superuser(username, email, password)
        result = self.client.login(username=username, password=password)
        self.assertEqual(result, True)
Esempio n. 2
0
def load_nav(context, nav_id, show_title=False, **kwargs):
    """
    Renders the nav and its nav items.
    This will call nav_item that will call itself recursively nesting
    the subnavs
    """
    user = AnonymousUser()
    association_id = get_association_id(context)
    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']
            if hasattr(user, 'profile'):
                association_id = user.profile.current_association_id

    is_site_map = kwargs.get('is_site_map', False)
    is_bootstrap = kwargs.get('is_bootstrap', False)

    # No perms check because load_nav is only called by the other tags
    try:
        # nav = Nav.objects.get(id=nav_id, association_id=association_id)
        filters = get_query_filters(user, 'navs.view_nav', association_id=association_id)
        navs = Nav.objects.filter(filters)  # .filter(id=nav_id)
        nav = Nav()
        items = []
        if navs and len(navs) > 0:
            nav = navs[0]
            if nav:
                items = nav.top_items
    except:
        return None
    context.update({
        "nav": nav,
        "items": items,
        "show_title": show_title,
        "is_bootstrap": is_bootstrap,
        'is_site_map': is_site_map,
        'user': user,
    })
    return context