Пример #1
0
def nav(context, nav_id):
    """
    Renders the nav from cache
    if not will use the navigation tag for rendering the nav
    """
    user = AnonymousUser()

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']
    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = navs[0]
        nav = get_nav(nav_object.pk)
        if not nav:
            cache_nav(nav_object)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
    })
    return context
Пример #2
0
def nav(context, nav_id, show_title=False, is_site_map=False):

    """
    Renders the nav from cache
    if not will use the navigation tag for rendering the nav
    """
    user = AnonymousUser()
    association_id = get_association_id(context)
    if is_site_map == 'False':
        is_site_map = False

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']
            if hasattr(user, 'profile'):
                association_id = user.profile.current_association_id

    try:
        nav_id = Variable(nav_id)
        nav_id = nav_id.resolve(context)
    except:
        pass

    try:
        filters = get_query_filters(user, 'navs.view_nav', association_id=association_id)
        navs = Nav.objects.filter(filters)  #.filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = None
        nav = None
        if navs and len(navs) > 0:
            nav_object = navs[0]
            if nav_object:
                nav = get_nav(nav_object.pk, is_site_map=is_site_map, association_id=association_id)
                if not nav:
                    nav = cache_nav(nav_object, show_title, is_site_map=is_site_map, association_id=association_id)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
        "show_title": show_title,
    })
    return context
Пример #3
0
def nav(context, nav_id, show_title=False, is_site_map=False):

    """
    Renders the nav from cache
    if not will use the navigation tag for rendering the nav
    """
    user = AnonymousUser()
    if is_site_map == 'False':
        is_site_map = False

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']

    try:
        nav_id = Variable(nav_id)
        nav_id = nav_id.resolve(context)
    except:
        pass

    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = navs[0]
        nav = get_nav(nav_object.pk, is_site_map=is_site_map)
        if not nav:
            nav = cache_nav(nav_object, show_title, is_site_map=is_site_map)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
        "show_title": show_title,
    })
    return context
Пример #4
0
def bootstrap_nav(context, nav_id, show_title=False):
    """
    Bootstrap version of the nav tag
    """
    user = AnonymousUser()

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']

    try:
        nav_id = Variable(nav_id)
        nav_id = nav_id.resolve(context)
    except:
        pass

    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated:
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = navs[0]
        nav = get_nav(nav_object.pk)
        if not nav:
            nav = cache_nav(nav_object, show_title)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
        "show_title": show_title,
        "is_bootstrap":
        True  # added context to enable to indicate bootstrap nav will be used
    })
    return context
Пример #5
0
def bootstrap_nav(context, nav_id, show_title=False):
    """
    Bootstrap version of the nav tag
    """
    user = AnonymousUser()

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']

    try:
        nav_id = Variable(nav_id)
        nav_id = nav_id.resolve(context)
    except:
        pass

    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = navs[0]
        nav = get_nav(nav_object.pk)
        if not nav:
            nav = cache_nav(nav_object, show_title)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
        "show_title": show_title,
        "is_bootstrap": True   # added context to enable to indicate bootstrap nav will be used
    })
    return context