def test_resolve_to_name(self):
        # URL matching unnamed view should return its callable name.
        self.failUnlessEqual(resolve_to_name('/some/url/'), 'app.views.view', 'Return view callable name on unnamed view match')

        # URL matching named view should return its name.
        self.failUnlessEqual(resolve_to_name('/some/other/url/'), 'this_is_a_named_view', 'Return view name on named view match')

        # Bogus URL should result in Resolver404.
        self.failUnlessRaises(Resolver404, resolve_to_name, '/some/bogus/url/')
Beispiel #2
0
    def test_resolve_to_name(self):
        # URL matching unnamed view should return its callable name.
        self.failUnlessEqual(
            resolve_to_name('/some/url/'), 'app.views.view',
            'Return view callable name on unnamed view match')

        # URL matching named view should return its name.
        self.failUnlessEqual(resolve_to_name('/some/other/url/'),
                             'this_is_a_named_view',
                             'Return view name on named view match')

        # Bogus URL should result in Resolver404.
        self.failUnlessRaises(Resolver404, resolve_to_name, '/some/bogus/url/')
def section(request):
    """
    Determines the current site section from resolved view pattern and adds
    it to context['section']. Section defaults to the first specified section.
    """
    # If SECTIONS setting is not specified, don't do anything.
    try:
        sections = settings.SECTIONS
    except AttributeError:
        return {}

    # Default return is first section.
    section = sections[0]['name']

    try:
        pattern_name = resolve_to_name(request.path_info)
    except Resolver404:
        pattern_name = None

    if pattern_name:
        for option in settings.SECTIONS:
            if pattern_name in option['matching_pattern_names']:
                section = option['name']

    return {'section': section}
Beispiel #4
0
def active_tab(request):
    url_name = resolve_to_name(request.path)

    for tab_name, urls in tabs.TAB_URLS.iteritems():
        if url_name in urls:
            return tab_name

    return ''
Beispiel #5
0
def is_active_tab(request, tab_name):
    '''
    Returns 'active' if this tab is the active one.
    Otherwise returns ''.
    '''

    url_name = resolve_to_name(request.path)

    if url_name in tabs.TAB_URLS[tab_name]:
        return 'active'
    else:
        return ''
def section(request):
    
    section, subsection = None, None
    
    try:
        pattern_name = resolve_to_name(request.path_info)
        pattern_array = pattern_name.split('_')
        pattern_array.reverse()
        try:
            section = pattern_array.pop()
        except IndexError:
            pass
        try:
            subsection = pattern_array.pop()
        except IndexError:
            pass

    except Resolver404:
        pattern_name = None

    return {'section': section, 'subsection': subsection, }
Beispiel #7
0
    def is_active(self, request):
        """
        Determines whether or not the link can be consider active based on the
        request path. True if the request path can be resolved to the same view
        name as is contained in view_name field. Otherwise True if request path
        starts with URL as resolved for category contained in category field.
        Otherwise True if request path starts with URL as contained in url
        field (needs some work).
        """
        try:
            pattern_name = resolve_to_name(request.path_info)
        except Resolver404:
            pattern_name = None

        active = False
        if pattern_name:
            active = pattern_name == self.view_name
        if not active and self.category:
            active = request.path_info.startswith(self.category.get_absolute_url())
        if not active and self.target:
            active = request.path_info.startswith(self.target.get_absolute_url())
        if not active and self.url:
            active = request.path_info.startswith(self.url)
        return active