Skip to content

Commit

Permalink
Render LMS main navigation (tabs) with template, override templates f…
Browse files Browse the repository at this point in the history
…or a specific list item
  • Loading branch information
dmitry-viskov committed Feb 16, 2016
1 parent 57af11c commit d532f8d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## mako
<%namespace name='static' file='/static_content.html'/>
<%!
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
%>
<%page args="tab_list, active_page, default_tab, tab_image" />

<%
def url_class(is_active):
if is_active:
return "active"
return ""
%>
% for tab in tab_list:
<%
tab_is_active = tab.tab_id in (active_page, default_tab)
tab_class = url_class(tab_is_active)
%>
<li>
<a href="${tab.link_func(course, reverse) | h}" class="${tab_class}">
Test Microsite Tab: ${_(tab.name) | h}
% if tab_is_active:
<span class="sr">, current location</span>
%endif
% if tab_image:
## Translators: 'needs attention' is an alternative string for the
## notification image that indicates the tab "needs attention".
<img src="${tab_image}" alt="${_('needs attention')}" />
%endif
</a>
</li>
% endfor
15 changes: 15 additions & 0 deletions lms/djangoapps/courseware/tests/test_microsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ def test_microsite_course_enrollment(self):
self.assertNotContains(resp, 'Robot_Super_Course')
self.assertContains(resp, 'Robot_Course_Outside_Microsite')

def test_microsite_course_custom_tabs(self):
"""
Enroll user in a course scoped in a Microsite and make sure that
template with tabs is overridden
"""
self.setup_users()

email, password = self.STUDENT_INFO[1]
self.login(email, password)
self.enroll(self.course, True)

resp = self.client.get(reverse('courseware', args=[unicode(self.course.id)]),
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
self.assertContains(resp, 'Test Microsite Tab:')

@override_settings(SITE_NAME=settings.MICROSITE_TEST_HOSTNAME)
def test_visible_about_page_settings(self):
"""
Expand Down
32 changes: 7 additions & 25 deletions lms/templates/courseware/course_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
# If active_page is not passed in as an argument, it may be in the context as active_page_context
active_page = active_page_context

def url_class(is_active):
if is_active:
return "active"
return ""

def selected(is_selected):
return "selected" if is_selected else ""

Expand Down Expand Up @@ -83,27 +78,14 @@
% if disable_tabs is UNDEFINED or not disable_tabs:
<nav class="${active_page} wrapper-course-material" aria-label="${_('Course Material')}">
<div class="course-material">
<ol class="course-tabs">
% for tab in get_course_tab_list(request, course):
<%
tab_is_active = (tab.tab_id == active_page) or (tab.tab_id == default_tab)
%>
<li>
<a href="${tab.link_func(course, reverse) | h}" class="${url_class(tab_is_active)}">
${_(tab.name) | h}
% if tab_is_active:
<span class="sr">, current location</span>
%endif
% if tab_image:
## Translators: 'needs attention' is an alternative string for the
## notification image that indicates the tab "needs attention".
<img src="${tab_image}" alt="${_('needs attention')}" />
%endif
</a>
</li>
% endfor
<%
tab_list = get_course_tab_list(request, course)
tabs_tmpl = static.get_template_path('/courseware/tabs.html')
%>
<ol class="course-tabs">
<%include file="${tabs_tmpl}" args="tab_list=tab_list,active_page=active_page,default_tab=default_tab,tab_image=tab_image" />
<%block name="extratabs" />
</ol>
</ol>
</div>
</nav>
%endif
Expand Down
33 changes: 33 additions & 0 deletions lms/templates/courseware/tabs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## mako
<%namespace name='static' file='/static_content.html'/>
<%!
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
%>
<%page args="tab_list, active_page, default_tab, tab_image" />

<%
def url_class(is_active):
if is_active:
return "active"
return ""
%>
% for tab in tab_list:
<%
tab_is_active = tab.tab_id in (active_page, default_tab)
tab_class = url_class(tab_is_active)
%>
<li>
<a href="${tab.link_func(course, reverse) | h}" class="${tab_class}">
${_(tab.name) | h}
% if tab_is_active:
<span class="sr">, current location</span>
%endif
% if tab_image:
## Translators: 'needs attention' is an alternative string for the
## notification image that indicates the tab "needs attention".
<img src="${tab_image}" alt="${_('needs attention')}" />
%endif
</a>
</li>
% endfor

0 comments on commit d532f8d

Please sign in to comment.