merge from master. resolved conflict with test_responsetypes.py by using the version from master.
This commit is contained in:
@@ -342,6 +342,27 @@ def _does_course_group_name_exist(name):
|
||||
return len(Group.objects.filter(name=name)) > 0
|
||||
|
||||
|
||||
def _course_org_staff_group_name(location, course_context=None):
|
||||
"""
|
||||
Get the name of the staff group for an organization which corresponds
|
||||
to the organization in the course id.
|
||||
|
||||
location: something that can passed to Location
|
||||
course_context: A course_id that specifies the course run in which
|
||||
the location occurs.
|
||||
Required if location doesn't have category 'course'
|
||||
|
||||
"""
|
||||
loc = Location(location)
|
||||
if loc.category == 'course':
|
||||
course_id = loc.course_id
|
||||
else:
|
||||
if course_context is None:
|
||||
raise CourseContextRequired()
|
||||
course_id = course_context
|
||||
return 'staff_%s' % course_id.split('/')[0]
|
||||
|
||||
|
||||
def _course_staff_group_name(location, course_context=None):
|
||||
"""
|
||||
Get the name of the staff group for a location in the context of a course run.
|
||||
@@ -382,6 +403,27 @@ def course_beta_test_group_name(location):
|
||||
course_beta_test_group_name.__test__ = False
|
||||
|
||||
|
||||
def _course_org_instructor_group_name(location, course_context=None):
|
||||
"""
|
||||
Get the name of the instructor group for an organization which corresponds
|
||||
to the organization in the course id.
|
||||
|
||||
location: something that can passed to Location
|
||||
course_context: A course_id that specifies the course run in which
|
||||
the location occurs.
|
||||
Required if location doesn't have category 'course'
|
||||
|
||||
"""
|
||||
loc = Location(location)
|
||||
if loc.category == 'course':
|
||||
course_id = loc.course_id
|
||||
else:
|
||||
if course_context is None:
|
||||
raise CourseContextRequired()
|
||||
course_id = course_context
|
||||
return 'instructor_%s' % course_id.split('/')[0]
|
||||
|
||||
|
||||
def _course_instructor_group_name(location, course_context=None):
|
||||
"""
|
||||
Get the name of the instructor group for a location, in the context of a course run.
|
||||
@@ -499,14 +541,18 @@ def _has_access_to_location(user, location, access_level, course_context):
|
||||
|
||||
if access_level == 'staff':
|
||||
staff_group = _course_staff_group_name(location, course_context)
|
||||
if staff_group in user_groups:
|
||||
# org_staff_group is a group for an entire organization
|
||||
org_staff_group = _course_org_staff_group_name(location, course_context)
|
||||
if staff_group in user_groups or org_staff_group in user_groups:
|
||||
debug("Allow: user in group %s", staff_group)
|
||||
return True
|
||||
debug("Deny: user not in group %s", staff_group)
|
||||
|
||||
if access_level == 'instructor' or access_level == 'staff': # instructors get staff privileges
|
||||
instructor_group = _course_instructor_group_name(location, course_context)
|
||||
if instructor_group in user_groups:
|
||||
instructor_staff_group = _course_org_instructor_group_name(
|
||||
location, course_context)
|
||||
if instructor_group in user_groups or instructor_staff_group in user_groups:
|
||||
debug("Allow: user in group %s", instructor_group)
|
||||
return True
|
||||
debug("Deny: user not in group %s", instructor_group)
|
||||
|
||||
@@ -325,53 +325,3 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
msg += '<hr>'
|
||||
|
||||
return {'ok': False, 'msg': msg, 'ex': fexpect, 'got': fsym}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# tests
|
||||
|
||||
|
||||
def sctest1():
|
||||
x = "1/2*(1+(k_e* Q* q)/(m *g *h^2))"
|
||||
y = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mfrac>
|
||||
<mn>1</mn>
|
||||
<mn>2</mn>
|
||||
</mfrac>
|
||||
<mrow>
|
||||
<mo>(</mo>
|
||||
<mn>1</mn>
|
||||
<mo>+</mo>
|
||||
<mfrac>
|
||||
<mrow>
|
||||
<msub>
|
||||
<mi>k</mi>
|
||||
<mi>e</mi>
|
||||
</msub>
|
||||
<mo>⋅</mo>
|
||||
<mi>Q</mi>
|
||||
<mo>⋅</mo>
|
||||
<mi>q</mi>
|
||||
</mrow>
|
||||
<mrow>
|
||||
<mi>m</mi>
|
||||
<mo>⋅</mo>
|
||||
<mrow>
|
||||
<mi>g</mi>
|
||||
<mo>⋅</mo>
|
||||
</mrow>
|
||||
<msup>
|
||||
<mi>h</mi>
|
||||
<mn>2</mn>
|
||||
</msup>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
<mo>)</mo>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>
|
||||
'''.strip()
|
||||
z = "1/2(1+(k_e* Q* q)/(m *g *h^2))"
|
||||
r = sympy_check2(x, z, {'a': z, 'a_fromjs': y}, 'a')
|
||||
return r
|
||||
|
||||
@@ -10,6 +10,64 @@ class SymmathCheckTest(TestCase):
|
||||
number_list = [i + 0.01 for i in range(-100, 100)]
|
||||
self._symmath_check_numbers(number_list)
|
||||
|
||||
def test_symmath_check_same_symbols(self):
|
||||
expected_str = "x+2*y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mn>2</mn>
|
||||
<mo>*</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that the exact same symbolic string is marked correct
|
||||
result = symmath_check(expected_str, expected_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and result['ok'])
|
||||
|
||||
def test_symmath_check_equivalent_symbols(self):
|
||||
expected_str = "x+2*y"
|
||||
input_str = "x+y+y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that equivalent symbolic strings are marked correct
|
||||
result = symmath_check(expected_str, input_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and result['ok'])
|
||||
|
||||
def test_symmath_check_different_symbols(self):
|
||||
expected_str = "0"
|
||||
input_str = "x+y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that an incorrect response is marked incorrect
|
||||
result = symmath_check(expected_str, input_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and not result['ok'])
|
||||
self.assertFalse('fail' in result['msg'])
|
||||
|
||||
def _symmath_check_numbers(self, number_list):
|
||||
|
||||
for n in number_list:
|
||||
|
||||
@@ -90,41 +90,40 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
%if 'chapters' in textbook:
|
||||
<section aria-label="Textbook Navigation" class="book-sidebar">
|
||||
%if 'chapters' in textbook:
|
||||
<section aria-label="Textbook Navigation" class="book-sidebar">
|
||||
<ul id="booknav" class="treeview-booknav">
|
||||
<%def name="print_entry(entry, index_value)">
|
||||
<li id="pdfchapter-${index_value}">
|
||||
<a class="chapter">
|
||||
${entry.get('title')}
|
||||
</a>
|
||||
</li>
|
||||
</%def>
|
||||
|
||||
<ul id="booknav" class="treeview-booknav">
|
||||
<%def name="print_entry(entry, index_value)">
|
||||
<li id="pdfchapter-${index_value}">
|
||||
<a class="chapter">
|
||||
${entry.get('title')}
|
||||
</a>
|
||||
</li>
|
||||
</%def>
|
||||
|
||||
% for (index, entry) in enumerate(textbook['chapters']):
|
||||
${print_entry(entry, index+1)}
|
||||
% endfor
|
||||
</ul>
|
||||
</section>
|
||||
%endif
|
||||
% for (index, entry) in enumerate(textbook['chapters']):
|
||||
${print_entry(entry, index+1)}
|
||||
% endfor
|
||||
</ul>
|
||||
</section>
|
||||
%endif
|
||||
|
||||
<section id="viewerContainer" class="book">
|
||||
<!-- use same page-turning as used in image-based textbooks -->
|
||||
<nav>
|
||||
<ul>
|
||||
<li class="last">
|
||||
<a id="previous">Previous page</a>
|
||||
</li>
|
||||
<li class="next">
|
||||
<a id="next">Next page</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div id="viewer" contextmenu="viewerContextMenu"></div>
|
||||
</div>
|
||||
|
||||
<section class="page">
|
||||
<!-- use same page-turning as used in image-based textbooks -->
|
||||
<nav>
|
||||
<ul>
|
||||
<li class="last">
|
||||
<a id="previous">Previous page</a>
|
||||
</li>
|
||||
<li class="next">
|
||||
<a id="next">Next page</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div id="viewer" contextmenu="viewerContextMenu"></div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
</div> <!-- mainContainer -->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user