Esempio n. 1
0
def get_nav_category(path):
    tc = ThemeController()
    settings = tc.get_template_settings()
                #   Search for current nav category based on request path
    first_level = ''.join(path.lstrip('/').split('/')[:1])
    for category in settings['nav_structure']:
        if category['header_link'].lstrip('/').startswith(first_level):
            return category
    #   Search failed - use default nav category
    default_nav_category = 'learn'
    for category in settings['nav_structure']:
        if category['header_link'].lstrip('/').startswith(default_nav_category):
            return category
Esempio n. 2
0
def get_nav_category(path):
    tc = ThemeController()
    settings = tc.get_template_settings()
    #   Search for current nav category based on request path
    first_level = ''.join(path.lstrip('/').split('/')[:1])
    for category in settings['nav_structure']:
        if category['header_link'].lstrip('/').startswith(first_level):
            return category
    #   Search failed - use default nav category
    default_nav_category = 'learn'
    for category in settings['nav_structure']:
        if category['header_link'].lstrip('/').startswith(
                default_nav_category):
            return category
Esempio n. 3
0
def extract_theme(url):
    #   Get the appropriate color scheme out of the Tag that controls nav structure
    #   (specific to MIT theme)
    tab_index = 0
    tc = ThemeController()
    settings = tc.get_template_settings()
    max_chars_matched = 0
    for category in settings['nav_structure']:
        num_chars_matched = count_matching_chars(url, category['header_link'])
        if num_chars_matched > max_chars_matched:
            max_chars_matched = num_chars_matched
            tab_index = 0
        i = 1
        for item in category['links']:
            num_chars_matched = count_matching_chars(url, item['link'])
            if num_chars_matched > max_chars_matched:
                max_chars_matched = num_chars_matched
                tab_index = i
            i += 1
    return 'tabcolor%d' % tab_index
Esempio n. 4
0
def extract_theme(url):
    #   Get the appropriate color scheme out of the Tag that controls nav structure
    #   (specific to MIT theme)
    tab_index = 0
    tc = ThemeController()
    settings = tc.get_template_settings()
    max_chars_matched = 0
    for category in settings['nav_structure']:
        num_chars_matched = count_matching_chars(url, category['header_link'])
        if num_chars_matched > max_chars_matched:
            max_chars_matched = num_chars_matched
            tab_index = 0
        i = 1
        for item in category['links']:
            num_chars_matched = count_matching_chars(url, item['link'])
            if num_chars_matched > max_chars_matched:
                max_chars_matched = num_chars_matched
                tab_index = i
            i += 1
    return 'tabcolor%d' % tab_index
Esempio n. 5
0
def extract_theme(str):
    #   Get the appropriate color scheme out of the Tag that controls nav structure
    #   (specific to MIT theme)
    tab_index = 0
    tc = ThemeController()
    settings = tc.get_template_settings()
    for category in settings['nav_structure']:
        if category['header_link'][:5] == str[:5]:
            i = 1
            for item in category['links']:
                if str == item['link']:
                    tab_index = i
                    break
                path_current = os.path.dirname(str)
                path_tab = os.path.dirname(item['link'])
                if len(path_current) > len(
                        path_tab) and path_current.startswith(path_tab):
                    tab_index = i
                    break
                i += 1
    return 'tabcolor%d' % tab_index
Esempio n. 6
0
def render_to_response(template,
                       request,
                       context,
                       prog=None,
                       auto_per_program_templates=True,
                       mimetype=None,
                       use_request_context=True):
    from esp.web.views.navBar import makeNavBar

    if isinstance(template, (basestring, )):
        template = [template]

    if isinstance(prog, (list, tuple)) and auto_per_program_templates:
        template = [_per_program_template_name(prog[0], t)
                    for t in template] + template

    section = request.path.split('/')[1]
    tc = ThemeController()
    context['theme'] = tc.get_template_settings()
    context['settings'] = settings

    # create nav bar list
    if not context.has_key('navbar_list'):
        category = None
        if context.has_key('nav_category'):
            category = context['nav_category']
        context['navbar_list'] = makeNavBar(section, category)

    if not use_request_context:
        context['request'] = request
        response = django.shortcuts.render_to_response(template,
                                                       context,
                                                       mimetype=mimetype)
        return response
    else:
        return render_response(request, template, context, mimetype=mimetype)
Esempio n. 7
0
def render_to_response(template, request, context, content_type=None, use_request_context=True):
    from esp.web.views.navBar import makeNavBar

    if isinstance(template, (basestring,)):
        template = [ template ]

    section = request.path.split('/')[1]
    tc = ThemeController()
    context['theme'] = tc.get_template_settings()
    context['settings'] = settings

    # create nav bar list
    if not 'navbar_list' in context:
        category = None
        if 'nav_category' in context:
            category = context['nav_category']
        context['navbar_list'] = makeNavBar(section, category, path=request.path[1:])

    if not use_request_context:
        context['request'] = request
        response = django.shortcuts.render_to_response(template, context, content_type=content_type)
        return response
    else:
        return render_response(request, template, context, content_type=content_type)