Commit 9211a383 by Vik Paruchuri

Merge remote-tracking branch 'origin/master' into feature/vik/oe-ui

Conflicts:
	common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py
parents 6f657c11 c9e0d36d
...@@ -5,12 +5,31 @@ These are notable changes in edx-platform. This is a rolling list of changes, ...@@ -5,12 +5,31 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected. the top. Include a label indicating the component affected.
Blades: Took videoalpha out of alpha, replacing the old video player
LMS: Enable beta instructor dashboard. The beta dashboard is a rearchitecture
of the existing instructor dashboard and is available by clicking a link at
the top right of the existing dashboard.
Common: CourseEnrollment has new fields `is_active` and `mode`. The mode will be
used to differentiate different kinds of enrollments (currently, all enrollments
are honor certificate enrollments). The `is_active` flag will be used to
deactivate enrollments without deleting them, so that we know what course you
*were* enrolled in. Because of the latter change, enrollment and unenrollment
logic has been consolidated into the model -- you should use new class methods
to `enroll()`, `unenroll()`, and to check `is_enrolled()`, instead of creating
CourseEnrollment objects or querying them directly.
Studio: Email will be sent to admin address when a user requests course creator Studio: Email will be sent to admin address when a user requests course creator
privileges for Studio (edge only). privileges for Studio (edge only).
Studio: Studio course authors (both instructors and staff) will be auto-enrolled Studio: Studio course authors (both instructors and staff) will be auto-enrolled
for their courses so that "View Live" works. for their courses so that "View Live" works.
Common: Add a new input type ``<formulaequationinput />`` for Formula/Numerical
Responses. It periodically makes AJAX calls to preview and validate the
student's input.
Common: Added ratelimiting to our authentication backend. Common: Added ratelimiting to our authentication backend.
Common: Add additional logging to cover login attempts and logouts. Common: Add additional logging to cover login attempts and logouts.
...@@ -214,6 +233,12 @@ LMS: Fixed failing numeric response (decimal but no trailing digits). ...@@ -214,6 +233,12 @@ LMS: Fixed failing numeric response (decimal but no trailing digits).
LMS: XML Error module no longer shows students a stack trace. LMS: XML Error module no longer shows students a stack trace.
Studio: Add feedback to end user if there is a problem exporting a course
Studio: Improve link re-writing on imports into a different course-id
Studio: Allow for intracourse linking in Capa Problems
Blades: Videoalpha. Blades: Videoalpha.
XModules: Added partial credit for foldit module. XModules: Added partial credit for foldit module.
...@@ -222,6 +247,10 @@ XModules: Added "randomize" XModule to list of XModule types. ...@@ -222,6 +247,10 @@ XModules: Added "randomize" XModule to list of XModule types.
XModules: Show errors with full descriptors. XModules: Show errors with full descriptors.
Studio: Add feedback to end user if there is a problem exporting a course
Studio: Improve link re-writing on imports into a different course-id
XQueue: Fixed (hopefully) worker crash when the connection to RabbitMQ is XQueue: Fixed (hopefully) worker crash when the connection to RabbitMQ is
dropped suddenly. dropped suddenly.
......
...@@ -146,12 +146,13 @@ def fill_in_course_info( ...@@ -146,12 +146,13 @@ def fill_in_course_info(
def log_into_studio( def log_into_studio(
uname='robot', uname='robot',
email='robot+studio@edx.org', email='robot+studio@edx.org',
password='test'): password='test',
name='Robot Studio'):
world.log_in(username=uname, password=password, email=email, name='Robot Studio') world.log_in(username=uname, password=password, email=email, name=name)
# Navigate to the studio dashboard # Navigate to the studio dashboard
world.visit('/') world.visit('/')
world.wait_for(lambda _driver: uname in world.css_find('h2.title')[0].text)
def create_a_course(): def create_a_course():
course = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') course = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')
...@@ -209,27 +210,6 @@ def set_date_and_time(date_css, desired_date, time_css, desired_time): ...@@ -209,27 +210,6 @@ def set_date_and_time(date_css, desired_date, time_css, desired_time):
time.sleep(float(1)) time.sleep(float(1))
@step('I have created a Video component$')
def i_created_a_video_component(step):
world.create_component_instance(
step, '.large-video-icon',
'video',
'.xmodule_VideoModule',
has_multiple_templates=False
)
@step('I have created a Video Alpha component$')
def i_created_video_alpha(step):
step.given('I have enabled the videoalpha advanced module')
world.css_click('a.course-link')
step.given('I have added a new subsection')
step.given('I expand the first section')
world.css_click('a.new-unit-item')
world.css_click('.large-advanced-icon')
world.click_component_from_menu('videoalpha', None, '.xmodule_VideoAlphaModule')
@step('I have enabled the (.*) advanced module$') @step('I have enabled the (.*) advanced module$')
def i_enabled_the_advanced_module(step, module): def i_enabled_the_advanced_module(step, module):
step.given('I have opened a new course section in Studio') step.given('I have opened a new course section in Studio')
...@@ -247,16 +227,6 @@ def open_new_unit(step): ...@@ -247,16 +227,6 @@ def open_new_unit(step):
world.css_click('a.new-unit-item') world.css_click('a.new-unit-item')
@step('when I view the (video.*) it (.*) show the captions')
def shows_captions(_step, video_type, show_captions):
# Prevent cookies from overriding course settings
world.browser.cookies.delete('hide_captions')
if show_captions == 'does not':
assert world.css_has_class('.%s' % video_type, 'closed')
else:
assert world.is_css_not_present('.%s.closed' % video_type)
@step('the save button is disabled$') @step('the save button is disabled$')
def save_button_disabled(step): def save_button_disabled(step):
button_css = '.action-save' button_css = '.action-save'
......
...@@ -71,7 +71,7 @@ Feature: Course Team ...@@ -71,7 +71,7 @@ Feature: Course Team
And she selects the new course And she selects the new course
And she views the course team settings And she views the course team settings
And she deletes me from the course team And she deletes me from the course team
And I log in And I am logged into studio
Then I do not see the course on my page Then I do not see the course on my page
Scenario: Admins should be able to remove their own admin rights Scenario: Admins should be able to remove their own admin rights
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
#pylint: disable=W0621 #pylint: disable=W0621
from lettuce import world, step from lettuce import world, step
from common import create_studio_user, log_into_studio from common import create_studio_user
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from auth.authz import get_course_groupname_for_role from auth.authz import get_course_groupname_for_role, get_user_by_email
from nose.tools import assert_true
PASSWORD = 'test' PASSWORD = 'test'
EMAIL_EXTENSION = '@edx.org' EMAIL_EXTENSION = '@edx.org'
...@@ -66,6 +67,7 @@ def other_delete_self(_step): ...@@ -66,6 +67,7 @@ def other_delete_self(_step):
email="robot+studio@edx.org") email="robot+studio@edx.org")
world.css_click(to_delete_css) world.css_click(to_delete_css)
# confirm prompt # confirm prompt
world.wait(.5)
world.css_click(".wrapper-prompt-warning .action-primary") world.css_click(".wrapper-prompt-warning .action-primary")
...@@ -89,7 +91,21 @@ def remove_course_team_admin(_step, outer_capture, name): ...@@ -89,7 +91,21 @@ def remove_course_team_admin(_step, outer_capture, name):
@step(u'"([^"]*)" logs in$') @step(u'"([^"]*)" logs in$')
def other_user_login(_step, name): def other_user_login(_step, name):
log_into_studio(uname=name, password=PASSWORD, email=name + EMAIL_EXTENSION) world.browser.cookies.delete()
world.visit('/')
signin_css = 'a.action-signin'
world.is_css_present(signin_css)
world.css_click(signin_css)
def fill_login_form():
login_form = world.browser.find_by_css('form#login_form')
login_form.find_by_name('email').fill(name + EMAIL_EXTENSION)
login_form.find_by_name('password').fill(PASSWORD)
login_form.find_by_name('submit').click()
world.retry_on_exception(fill_login_form)
assert_true(world.is_css_present('.new-course-button'))
world.scenario_dict['USER'] = get_user_by_email(name + EMAIL_EXTENSION)
@step(u'I( do not)? see the course on my page') @step(u'I( do not)? see the course on my page')
......
...@@ -8,6 +8,6 @@ Feature: Create Course ...@@ -8,6 +8,6 @@ Feature: Create Course
And I am logged into Studio And I am logged into Studio
When I click the New Course button When I click the New Course button
And I fill in the new course information And I fill in the new course information
And I press the "Save" button And I press the "Create" button
Then the Courseware page has loaded in Studio Then the Courseware page has loaded in Studio
And I see a link for adding a new section And I see a link for adding a new section
Feature: Video Component Editor Feature: Video Component Editor
As a course author, I want to be able to create video components. As a course author, I want to be able to create video components.
Scenario: User can view metadata Scenario: User can view Video metadata
Given I have created a Video component Given I have created a Video component
And I edit and select Settings And I edit the component
Then I see the correct settings and default values Then I see the correct video settings and default values
Scenario: User can modify display name Scenario: User can modify Video display name
Given I have created a Video component Given I have created a Video component
And I edit and select Settings And I edit the component
Then I can modify the display name Then I can modify the display name
And my display name change is persisted on save And my video display name change is persisted on save
Scenario: Captions are hidden when "show captions" is false Scenario: Captions are hidden when "show captions" is false
Given I have created a Video component Given I have created a Video component
......
...@@ -2,18 +2,7 @@ ...@@ -2,18 +2,7 @@
# pylint: disable=C0111 # pylint: disable=C0111
from lettuce import world, step from lettuce import world, step
from terrain.steps import reload_the_page
@step('I see the correct settings and default values$')
def i_see_the_correct_settings_and_values(step):
world.verify_all_setting_entries([['Default Speed', 'OEoXaMPEzfM', False],
['Display Name', 'Video', False],
['Download Track', '', False],
['Download Video', '', False],
['Show Captions', 'True', False],
['Speed: .75x', '', False],
['Speed: 1.25x', '', False],
['Speed: 1.5x', '', False]])
@step('I have set "show captions" to (.*)') @step('I have set "show captions" to (.*)')
...@@ -24,9 +13,19 @@ def set_show_captions(step, setting): ...@@ -24,9 +13,19 @@ def set_show_captions(step, setting):
world.css_click('a.save-button') world.css_click('a.save-button')
@step('I see the correct videoalpha settings and default values$') @step('when I view the (video.*) it (.*) show the captions')
def correct_videoalpha_settings(_step): def shows_captions(_step, video_type, show_captions):
world.verify_all_setting_entries([['Display Name', 'Video Alpha', False], # Prevent cookies from overriding course settings
world.browser.cookies.delete('hide_captions')
if show_captions == 'does not':
assert world.css_has_class('.%s' % video_type, 'closed')
else:
assert world.is_css_not_present('.%s.closed' % video_type)
@step('I see the correct video settings and default values$')
def correct_video_settings(_step):
world.verify_all_setting_entries([['Display Name', 'Video', False],
['Download Track', '', False], ['Download Track', '', False],
['Download Video', '', False], ['Download Video', '', False],
['End Time', '0', False], ['End Time', '0', False],
...@@ -38,3 +37,12 @@ def correct_videoalpha_settings(_step): ...@@ -38,3 +37,12 @@ def correct_videoalpha_settings(_step):
['Youtube ID for .75x speed', '', False], ['Youtube ID for .75x speed', '', False],
['Youtube ID for 1.25x speed', '', False], ['Youtube ID for 1.25x speed', '', False],
['Youtube ID for 1.5x speed', '', False]]) ['Youtube ID for 1.5x speed', '', False]])
@step('my video display name change is persisted on save')
def video_name_persisted(step):
world.css_click('a.save-button')
reload_the_page(step)
world.edit_component()
world.verify_setting_entry(world.get_setting_entry('Display Name'), 'Display Name', '3.4', True)
Feature: Video Component Feature: Video Component
As a course author, I want to be able to view my created videos in Studio. As a course author, I want to be able to view my created videos in Studio.
# Video Alpha Features will work in Firefox only when Firefox is the active window
Scenario: Autoplay is disabled in Studio Scenario: Autoplay is disabled in Studio
Given I have created a Video component Given I have created a Video component
Then when I view the video it does not have autoplay enabled Then when I view the video it does not have autoplay enabled
...@@ -23,32 +24,6 @@ Feature: Video Component ...@@ -23,32 +24,6 @@ Feature: Video Component
And I have toggled captions And I have toggled captions
Then when I view the video it does show the captions Then when I view the video it does show the captions
# Video Alpha Features will work in Firefox only when Firefox is the active window
Scenario: Autoplay is disabled in Studio for Video Alpha
Given I have created a Video Alpha component
Then when I view the videoalpha it does not have autoplay enabled
Scenario: User can view Video Alpha metadata
Given I have created a Video Alpha component
And I edit the component
Then I see the correct videoalpha settings and default values
Scenario: User can modify Video Alpha display name
Given I have created a Video Alpha component
And I edit the component
Then I can modify the display name
And my videoalpha display name change is persisted on save
Scenario: Video Alpha captions are hidden when "show captions" is false
Given I have created a Video Alpha component
And I have set "show captions" to False
Then when I view the videoalpha it does not show the captions
Scenario: Video Alpha captions are shown when "show captions" is true
Given I have created a Video Alpha component
And I have set "show captions" to True
Then when I view the videoalpha it does show the captions
Scenario: Video data is shown correctly Scenario: Video data is shown correctly
Given I have created a video with only XML data Given I have created a video with only XML data
Then the correct Youtube video is shown Then the correct Youtube video is shown
...@@ -9,6 +9,16 @@ from contentstore.utils import get_modulestore ...@@ -9,6 +9,16 @@ from contentstore.utils import get_modulestore
############### ACTIONS #################### ############### ACTIONS ####################
@step('I have created a Video component$')
def i_created_a_video_component(step):
world.create_component_instance(
step, '.large-video-icon',
'video',
'.xmodule_VideoModule',
has_multiple_templates=False
)
@step('when I view the (.*) it does not have autoplay enabled') @step('when I view the (.*) it does not have autoplay enabled')
def does_not_autoplay(_step, video_type): def does_not_autoplay(_step, video_type):
assert world.css_find('.%s' % video_type)[0]['data-autoplay'] == 'False' assert world.css_find('.%s' % video_type)[0]['data-autoplay'] == 'False'
...@@ -22,6 +32,11 @@ def video_takes_a_single_click(_step): ...@@ -22,6 +32,11 @@ def video_takes_a_single_click(_step):
assert(world.is_css_present('.xmodule_VideoModule')) assert(world.is_css_present('.xmodule_VideoModule'))
@step('I edit the component')
def i_edit_the_component(_step):
world.edit_component()
@step('I have (hidden|toggled) captions') @step('I have (hidden|toggled) captions')
def hide_or_show_captions(step, shown): def hide_or_show_captions(step, shown):
button_css = 'a.hide-subtitles' button_css = 'a.hide-subtitles'
...@@ -38,18 +53,6 @@ def hide_or_show_captions(step, shown): ...@@ -38,18 +53,6 @@ def hide_or_show_captions(step, shown):
button.mouse_out() button.mouse_out()
world.css_click(button_css) world.css_click(button_css)
@step('I edit the component')
def i_edit_the_component(_step):
world.edit_component()
@step('my videoalpha display name change is persisted on save')
def videoalpha_name_persisted(step):
world.css_click('a.save-button')
reload_the_page(step)
world.edit_component()
world.verify_setting_entry(world.get_setting_entry('Display Name'), 'Display Name', '3.4', True)
@step('I have created a video with only XML data') @step('I have created a video with only XML data')
def xml_only_video(step): def xml_only_video(step):
...@@ -84,4 +87,5 @@ def xml_only_video(step): ...@@ -84,4 +87,5 @@ def xml_only_video(step):
@step('The correct Youtube video is shown') @step('The correct Youtube video is shown')
def the_youtube_video_is_shown(_step): def the_youtube_video_is_shown(_step):
ele = world.css_find('.video').first ele = world.css_find('.video').first
assert ele['data-youtube-id-1-0'] == world.scenario_dict['YOUTUBE_ID'] assert ele['data-streams'].split(':')[1] == world.scenario_dict['YOUTUBE_ID']
...@@ -48,4 +48,7 @@ class Command(BaseCommand): ...@@ -48,4 +48,7 @@ class Command(BaseCommand):
print 'removing User permissions from course....' print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course # in the django layer, we need to remove all the user permissions groups associated with this course
if commit: if commit:
_delete_course_group(loc) try:
_delete_course_group(loc)
except Exception as err:
print("Error in deleting course groups for {0}: {1}".format(loc, err))
...@@ -34,7 +34,7 @@ class DeleteItem(CourseTestCase): ...@@ -34,7 +34,7 @@ class DeleteItem(CourseTestCase):
resp.content, resp.content,
"application/json" "application/json"
) )
self.assertEqual(resp.status_code, 200) self.assert2XX(resp.status_code)
class TestCreateItem(CourseTestCase): class TestCreateItem(CourseTestCase):
......
...@@ -6,7 +6,7 @@ from .utils import CourseTestCase ...@@ -6,7 +6,7 @@ from .utils import CourseTestCase
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from auth.authz import get_course_groupname_for_role from auth.authz import get_course_groupname_for_role
from student.views import is_enrolled_in_course from student.models import CourseEnrollment
class UsersTestCase(CourseTestCase): class UsersTestCase(CourseTestCase):
...@@ -372,13 +372,13 @@ class UsersTestCase(CourseTestCase): ...@@ -372,13 +372,13 @@ class UsersTestCase(CourseTestCase):
def assert_not_enrolled(self): def assert_not_enrolled(self):
""" Asserts that self.ext_user is not enrolled in self.course. """ """ Asserts that self.ext_user is not enrolled in self.course. """
self.assertFalse( self.assertFalse(
is_enrolled_in_course(self.ext_user, self.course.location.course_id), CourseEnrollment.is_enrolled(self.ext_user, self.course.location.course_id),
'Did not expect ext_user to be enrolled in course' 'Did not expect ext_user to be enrolled in course'
) )
def assert_enrolled(self): def assert_enrolled(self):
""" Asserts that self.ext_user is enrolled in self.course. """ """ Asserts that self.ext_user is enrolled in self.course. """
self.assertTrue( self.assertTrue(
is_enrolled_in_course(self.ext_user, self.course.location.course_id), CourseEnrollment.is_enrolled(self.ext_user, self.course.location.course_id),
'User ext_user should have been enrolled in the course' 'User ext_user should have been enrolled in the course'
) )
...@@ -315,6 +315,8 @@ def import_course(request, org, course, name): ...@@ -315,6 +315,8 @@ def import_course(request, org, course, name):
create_all_course_groups(request.user, course_items[0].location) create_all_course_groups(request.user, course_items[0].location)
logging.debug('created all course groups at {0}'.format(course_items[0].location))
return HttpResponse(json.dumps({'Status': 'OK'})) return HttpResponse(json.dumps({'Status': 'OK'}))
else: else:
course_module = modulestore().get_item(location) course_module = modulestore().get_item(location)
......
...@@ -49,7 +49,6 @@ NOTE_COMPONENT_TYPES = ['notes'] ...@@ -49,7 +49,6 @@ NOTE_COMPONENT_TYPES = ['notes']
ADVANCED_COMPONENT_TYPES = [ ADVANCED_COMPONENT_TYPES = [
'annotatable', 'annotatable',
'word_cloud', 'word_cloud',
'videoalpha',
'graphical_slider_tool' 'graphical_slider_tool'
] + OPEN_ENDED_COMPONENT_TYPES + NOTE_COMPONENT_TYPES ] + OPEN_ENDED_COMPONENT_TYPES + NOTE_COMPONENT_TYPES
ADVANCED_COMPONENT_CATEGORY = 'advanced' ADVANCED_COMPONENT_CATEGORY = 'advanced'
......
...@@ -44,7 +44,7 @@ from .component import ( ...@@ -44,7 +44,7 @@ from .component import (
from django_comment_common.utils import seed_permissions_roles from django_comment_common.utils import seed_permissions_roles
from student.views import enroll_in_course from student.models import CourseEnrollment
from xmodule.html_module import AboutDescriptor from xmodule.html_module import AboutDescriptor
__all__ = ['course_index', 'create_new_course', 'course_info', __all__ = ['course_index', 'create_new_course', 'course_info',
...@@ -165,7 +165,7 @@ def create_new_course(request): ...@@ -165,7 +165,7 @@ def create_new_course(request):
seed_permissions_roles(new_course.location.course_id) seed_permissions_roles(new_course.location.course_id)
# auto-enroll the course creator in the course so that "View Live" will work. # auto-enroll the course creator in the course so that "View Live" will work.
enroll_in_course(request.user, new_course.location.course_id) CourseEnrollment.enroll(request.user, new_course.location.course_id)
return JsonResponse({'id': new_course.location.url()}) return JsonResponse({'id': new_course.location.url()})
......
import json
from uuid import uuid4 from uuid import uuid4
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
from util.json_request import expect_json from util.json_request import expect_json, JsonResponse
from ..utils import get_modulestore from ..utils import get_modulestore
from .access import has_access from .access import has_access
from .requests import _xmodule_recurse from .requests import _xmodule_recurse
...@@ -20,6 +18,7 @@ __all__ = ['save_item', 'create_item', 'delete_item'] ...@@ -20,6 +18,7 @@ __all__ = ['save_item', 'create_item', 'delete_item']
# cdodge: these are categories which should not be parented, they are detached from the hierarchy # cdodge: these are categories which should not be parented, they are detached from the hierarchy
DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info'] DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info']
@login_required @login_required
@expect_json @expect_json
def save_item(request): def save_item(request):
...@@ -80,7 +79,7 @@ def save_item(request): ...@@ -80,7 +79,7 @@ def save_item(request):
# commit to datastore # commit to datastore
store.update_metadata(item_location, own_metadata(existing_item)) store.update_metadata(item_location, own_metadata(existing_item))
return HttpResponse() return JsonResponse()
# [DHM] A hack until we implement a permanent soln. Proposed perm solution is to make namespace fields also top level # [DHM] A hack until we implement a permanent soln. Proposed perm solution is to make namespace fields also top level
...@@ -139,13 +138,17 @@ def create_item(request): ...@@ -139,13 +138,17 @@ def create_item(request):
if display_name is not None: if display_name is not None:
metadata['display_name'] = display_name metadata['display_name'] = display_name
get_modulestore(category).create_and_save_xmodule(dest_location, definition_data=data, get_modulestore(category).create_and_save_xmodule(
metadata=metadata, system=parent.system) dest_location,
definition_data=data,
metadata=metadata,
system=parent.system,
)
if category not in DETACHED_CATEGORIES: if category not in DETACHED_CATEGORIES:
get_modulestore(parent.location).update_children(parent_location, parent.children + [dest_location.url()]) get_modulestore(parent.location).update_children(parent_location, parent.children + [dest_location.url()])
return HttpResponse(json.dumps({'id': dest_location.url()})) return JsonResponse({'id': dest_location.url()})
@login_required @login_required
...@@ -184,4 +187,4 @@ def delete_item(request): ...@@ -184,4 +187,4 @@ def delete_item(request):
parent.children = children parent.children = children
modulestore('direct').update_children(parent.location, parent.children) modulestore('direct').update_children(parent.location, parent.children)
return HttpResponse() return JsonResponse()
...@@ -75,9 +75,15 @@ def preview_component(request, location): ...@@ -75,9 +75,15 @@ def preview_component(request, location):
component = modulestore().get_item(location) component = modulestore().get_item(location)
component.get_html = wrap_xmodule(
component.get_html,
component,
'xmodule_edit.html'
)
return render_to_response('component.html', { return render_to_response('component.html', {
'preview': get_module_previews(request, component)[0], 'preview': get_preview_html(request, component, 0),
'editor': wrap_xmodule(component.get_html, component, 'xmodule_edit.html')(), 'editor': component.runtime.render(component, None, 'studio_view').content,
}) })
...@@ -163,15 +169,10 @@ def load_preview_module(request, preview_id, descriptor): ...@@ -163,15 +169,10 @@ def load_preview_module(request, preview_id, descriptor):
return module return module
def get_module_previews(request, descriptor): def get_preview_html(request, descriptor, idx):
""" """
Returns a list of preview XModule html contents. One preview is returned for each Returns the HTML returned by the XModule's student_view,
pair of states returned by get_sample_state() for the supplied descriptor. specified by the descriptor and idx.
descriptor: An XModuleDescriptor
""" """
preview_html = [] module = load_preview_module(request, str(idx), descriptor)
for idx, (_instance_state, _shared_state) in enumerate(descriptor.get_sample_state()): return module.runtime.render(module, None, "student_view").content
module = load_preview_module(request, str(idx), descriptor)
preview_html.append(module.get_html())
return preview_html
...@@ -13,6 +13,7 @@ from django.core.context_processors import csrf ...@@ -13,6 +13,7 @@ from django.core.context_processors import csrf
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.error_module import ErrorDescriptor
from contentstore.utils import get_lms_link_for_item from contentstore.utils import get_lms_link_for_item
from util.json_request import JsonResponse from util.json_request import JsonResponse
from auth.authz import ( from auth.authz import (
...@@ -23,7 +24,7 @@ from course_creators.views import ( ...@@ -23,7 +24,7 @@ from course_creators.views import (
from .access import has_access from .access import has_access
from student.views import enroll_in_course from student.models import CourseEnrollment
@login_required @login_required
...@@ -62,7 +63,7 @@ def index(request): ...@@ -62,7 +63,7 @@ def index(request):
) )
return render_to_response('index.html', { return render_to_response('index.html', {
'courses': [format_course_for_view(c) for c in courses], 'courses': [format_course_for_view(c) for c in courses if not isinstance(c, ErrorDescriptor)],
'user': request.user, 'user': request.user,
'request_course_creator_url': reverse('request_course_creator'), 'request_course_creator_url': reverse('request_course_creator'),
'course_creator_status': _get_course_creator_status(request.user), 'course_creator_status': _get_course_creator_status(request.user),
...@@ -207,7 +208,7 @@ def course_team_user(request, org, course, name, email): ...@@ -207,7 +208,7 @@ def course_team_user(request, org, course, name, email):
user.groups.add(groups["instructor"]) user.groups.add(groups["instructor"])
user.save() user.save()
# auto-enroll the course creator in the course so that "View Live" will work. # auto-enroll the course creator in the course so that "View Live" will work.
enroll_in_course(user, location.course_id) CourseEnrollment.enroll(user, location.course_id)
elif role == "staff": elif role == "staff":
# if we're trying to downgrade a user from "instructor" to "staff", # if we're trying to downgrade a user from "instructor" to "staff",
# make sure we have at least one other instructor in the course team. # make sure we have at least one other instructor in the course team.
...@@ -222,7 +223,7 @@ def course_team_user(request, org, course, name, email): ...@@ -222,7 +223,7 @@ def course_team_user(request, org, course, name, email):
user.groups.add(groups["staff"]) user.groups.add(groups["staff"])
user.save() user.save()
# auto-enroll the course creator in the course so that "View Live" will work. # auto-enroll the course creator in the course so that "View Live" will work.
enroll_in_course(user, location.course_id) CourseEnrollment.enroll(user, location.course_id)
return JsonResponse() return JsonResponse()
......
...@@ -173,7 +173,7 @@ class CourseDetails(object): ...@@ -173,7 +173,7 @@ class CourseDetails(object):
# the right thing # the right thing
result = None result = None
if video_key: if video_key:
result = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + \ result = '<iframe width="560" height="315" src="//www.youtube.com/embed/' + \
video_key + '?autoplay=1&rel=0" frameborder="0" allowfullscreen=""></iframe>' video_key + '?autoplay=1&rel=0" frameborder="0" allowfullscreen=""></iframe>'
return result return result
......
...@@ -107,6 +107,7 @@ DEFAULT_FEEDBACK_EMAIL = ENV_TOKENS.get('DEFAULT_FEEDBACK_EMAIL', DEFAULT_FEEDBA ...@@ -107,6 +107,7 @@ DEFAULT_FEEDBACK_EMAIL = ENV_TOKENS.get('DEFAULT_FEEDBACK_EMAIL', DEFAULT_FEEDBA
ADMINS = ENV_TOKENS.get('ADMINS', ADMINS) ADMINS = ENV_TOKENS.get('ADMINS', ADMINS)
SERVER_EMAIL = ENV_TOKENS.get('SERVER_EMAIL', SERVER_EMAIL) SERVER_EMAIL = ENV_TOKENS.get('SERVER_EMAIL', SERVER_EMAIL)
MKTG_URLS = ENV_TOKENS.get('MKTG_URLS', MKTG_URLS) MKTG_URLS = ENV_TOKENS.get('MKTG_URLS', MKTG_URLS)
TECH_SUPPORT_EMAIL = ENV_TOKENS.get('TECH_SUPPORT_EMAIL', TECH_SUPPORT_EMAIL)
COURSES_WITH_UNSAFE_CODE = ENV_TOKENS.get("COURSES_WITH_UNSAFE_CODE", []) COURSES_WITH_UNSAFE_CODE = ENV_TOKENS.get("COURSES_WITH_UNSAFE_CODE", [])
......
...@@ -25,7 +25,7 @@ Longer TODO: ...@@ -25,7 +25,7 @@ Longer TODO:
import sys import sys
import lms.envs.common import lms.envs.common
from lms.envs.common import USE_TZ from lms.envs.common import USE_TZ, TECH_SUPPORT_EMAIL, PLATFORM_NAME, BUGS_EMAIL
from path import path from path import path
############################ FEATURE CONFIGURATION ############################# ############################ FEATURE CONFIGURATION #############################
...@@ -39,9 +39,6 @@ MITX_FEATURES = { ...@@ -39,9 +39,6 @@ MITX_FEATURES = {
'AUTH_USE_MIT_CERTIFICATES': False, 'AUTH_USE_MIT_CERTIFICATES': False,
# do not display video when running automated acceptance tests
'STUB_VIDEO_FOR_TESTING': False,
# email address for studio staff (eg to request course creation) # email address for studio staff (eg to request course creation)
'STUDIO_REQUEST_EMAIL': '', 'STUDIO_REQUEST_EMAIL': '',
...@@ -204,7 +201,7 @@ STATICFILES_DIRS = [ ...@@ -204,7 +201,7 @@ STATICFILES_DIRS = [
TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name TIME_ZONE = 'America/New_York' # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en' # http://www.i18nguy.com/unicode/language-identifiers.html
USE_I18N = True USE_I18N = False
USE_L10N = True USE_L10N = True
# Localization strings (e.g. django.po) are under this directory # Localization strings (e.g. django.po) are under this directory
......
...@@ -150,14 +150,13 @@ DEBUG_TOOLBAR_PANELS = ( ...@@ -150,14 +150,13 @@ DEBUG_TOOLBAR_PANELS = (
'debug_toolbar.panels.sql.SQLDebugPanel', 'debug_toolbar.panels.sql.SQLDebugPanel',
'debug_toolbar.panels.signals.SignalDebugPanel', 'debug_toolbar.panels.signals.SignalDebugPanel',
'debug_toolbar.panels.logger.LoggingPanel', 'debug_toolbar.panels.logger.LoggingPanel',
'debug_toolbar_mongo.panel.MongoDebugPanel',
# Enabling the profiler has a weird bug as of django-debug-toolbar==0.9.4 and # Enabling the profiler has a weird bug as of django-debug-toolbar==0.9.4 and
# Django=1.3.1/1.4 where requests to views get duplicated (your method gets # Django=1.3.1/1.4 where requests to views get duplicated (your method gets
# hit twice). So you can uncomment when you need to diagnose performance # hit twice). So you can uncomment when you need to diagnose performance
# problems, but you shouldn't leave it on. # problems, but you shouldn't leave it on.
# 'debug_toolbar.panels.profiling.ProfilingDebugPanel', # 'debug_toolbar.panels.profiling.ProfilingDebugPanel',
) )
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False 'INTERCEPT_REDIRECTS': False
...@@ -165,7 +164,7 @@ DEBUG_TOOLBAR_CONFIG = { ...@@ -165,7 +164,7 @@ DEBUG_TOOLBAR_CONFIG = {
# To see stacktraces for MongoDB queries, set this to True. # To see stacktraces for MongoDB queries, set this to True.
# Stacktraces slow down page loads drastically (for pages with lots of queries). # Stacktraces slow down page loads drastically (for pages with lots of queries).
DEBUG_TOOLBAR_MONGO_STACKTRACES = True DEBUG_TOOLBAR_MONGO_STACKTRACES = False
# disable NPS survey in dev mode # disable NPS survey in dev mode
MITX_FEATURES['STUDIO_NPS_SURVEY'] = False MITX_FEATURES['STUDIO_NPS_SURVEY'] = False
......
"""
This configuration is to turn on the Django Toolbar stats for DB access stats, for performance analysis
"""
# We intentionally define lots of variables that aren't used, and
# want to import all variables from base settings files
# pylint: disable=W0401, W0614
from .dev import *
DEBUG_TOOLBAR_PANELS = (
'debug_toolbar.panels.version.VersionDebugPanel',
'debug_toolbar.panels.timer.TimerDebugPanel',
'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
'debug_toolbar.panels.headers.HeaderDebugPanel',
'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
'debug_toolbar.panels.sql.SQLDebugPanel',
'debug_toolbar.panels.signals.SignalDebugPanel',
'debug_toolbar.panels.logger.LoggingPanel',
'debug_toolbar_mongo.panel.MongoDebugPanel'
# Enabling the profiler has a weird bug as of django-debug-toolbar==0.9.4 and
# Django=1.3.1/1.4 where requests to views get duplicated (your method gets
# hit twice). So you can uncomment when you need to diagnose performance
# problems, but you shouldn't leave it on.
# 'debug_toolbar.panels.profiling.ProfilingDebugPanel',
)
# To see stacktraces for MongoDB queries, set this to True.
# Stacktraces slow down page loads drastically (for pages with lots of queries).
DEBUG_TOOLBAR_MONGO_STACKTRACES = True
verifyInputType = (input, expectedType) ->
# Some browsers (e.g. FireFox) do not support the "number"
# input type. We can accept a "text" input instead
# and still get acceptable behavior in the UI.
if expectedType == 'number' and input.type != 'number'
expectedType = 'text'
expect(input.type).toBe(expectedType)
describe "Test Metadata Editor", -> describe "Test Metadata Editor", ->
editorTemplate = readFixtures('metadata-editor.underscore') editorTemplate = readFixtures('metadata-editor.underscore')
numberEntryTemplate = readFixtures('metadata-number-entry.underscore') numberEntryTemplate = readFixtures('metadata-number-entry.underscore')
...@@ -113,7 +121,7 @@ describe "Test Metadata Editor", -> ...@@ -113,7 +121,7 @@ describe "Test Metadata Editor", ->
verifyEntry = (index, display_name, type) -> verifyEntry = (index, display_name, type) ->
expect(childModels[index].get('display_name')).toBe(display_name) expect(childModels[index].get('display_name')).toBe(display_name)
expect(childViews[index].type).toBe(type) verifyInputType(childViews[index], type)
verifyEntry(0, 'Display Name', 'text') verifyEntry(0, 'Display Name', 'text')
verifyEntry(1, 'Inputs', 'number') verifyEntry(1, 'Inputs', 'number')
...@@ -164,7 +172,7 @@ describe "Test Metadata Editor", -> ...@@ -164,7 +172,7 @@ describe "Test Metadata Editor", ->
assertInputType = (view, expectedType) -> assertInputType = (view, expectedType) ->
input = view.$el.find('.setting-input') input = view.$el.find('.setting-input')
expect(input.length).toEqual(1) expect(input.length).toEqual(1)
expect(input[0].type).toEqual(expectedType) verifyInputType(input[0], expectedType)
assertValueInView = (view, expectedValue) -> assertValueInView = (view, expectedValue) ->
expect(view.getValueFromEditor()).toEqual(expectedValue) expect(view.getValueFromEditor()).toEqual(expectedValue)
......
...@@ -120,6 +120,7 @@ class CMS.Views.UnitEdit extends Backbone.View ...@@ -120,6 +120,7 @@ class CMS.Views.UnitEdit extends Backbone.View
@model.save() @model.save()
deleteComponent: (event) => deleteComponent: (event) =>
event.preventDefault()
msg = new CMS.Views.Prompt.Warning( msg = new CMS.Views.Prompt.Warning(
title: gettext('Delete this component?'), title: gettext('Delete this component?'),
message: gettext('Deleting this component is permanent and cannot be undone.'), message: gettext('Deleting this component is permanent and cannot be undone.'),
......
...@@ -605,80 +605,117 @@ function cancelNewSection(e) { ...@@ -605,80 +605,117 @@ function cancelNewSection(e) {
function addNewCourse(e) { function addNewCourse(e) {
e.preventDefault(); e.preventDefault();
$('.new-course-button').addClass('is-disabled'); $('.new-course-button').addClass('is-disabled');
$('.new-course-save').addClass('is-disabled');
var $newCourse = $('.wrapper-create-course').addClass('is-shown'); var $newCourse = $('.wrapper-create-course').addClass('is-shown');
var $cancelButton = $newCourse.find('.new-course-cancel'); var $cancelButton = $newCourse.find('.new-course-cancel');
$newCourse.find('.new-course-name').focus().select(); var $courseName = $('.new-course-name');
$newCourse.find('form').bind('submit', saveNewCourse); $courseName.focus().select();
$('.new-course-save').on('click', saveNewCourse);
$cancelButton.bind('click', cancelNewCourse); $cancelButton.bind('click', cancelNewCourse);
$body.bind('keyup', { $body.bind('keyup', {
$cancelButton: $cancelButton $cancelButton: $cancelButton
}, checkForCancel); }, checkForCancel);
}
function saveNewCourse(e) {
e.preventDefault();
var $newCourseForm = $(this).closest('#create-course-form');
var display_name = $newCourseForm.find('.new-course-name').val();
var org = $newCourseForm.find('.new-course-org').val();
var number = $newCourseForm.find('.new-course-number').val();
var run = $newCourseForm.find('.new-course-run').val();
var required_field_text = gettext('Required field');
var display_name_errMsg = (display_name === '') ? required_field_text : null;
var org_errMsg = (org === '') ? required_field_text : null;
var number_errMsg = (number === '') ? required_field_text : null;
var run_errMsg = (run === '') ? required_field_text : null;
var bInErr = (display_name_errMsg || org_errMsg || number_errMsg || run_errMsg); // Check that a course (org, number, run) doesn't use any special characters
var validateCourseItemEncoding = function(item) {
// check for suitable encoding var required = validateRequiredField(item);
if (!bInErr) { if(required) {
var encoding_errMsg = gettext('Please do not use any spaces or special characters in this field.'); return required;
}
if (encodeURIComponent(org) != org) if(item !== encodeURIComponent(item)) {
org_errMsg = encoding_errMsg; return gettext('Please do not use any spaces or special characters in this field.');
if (encodeURIComponent(number) != number) }
number_errMsg = encoding_errMsg; return '';
if (encodeURIComponent(run) != run)
run_errMsg = encoding_errMsg;
bInErr = (org_errMsg || number_errMsg || run_errMsg);
} }
var header_err_msg = (bInErr) ? gettext('Please correct the fields below.') : null; // Ensure that all items are less than 80 characters.
var validateTotalCourseItemsLength = function() {
var setNewCourseErrMsgs = function(header_err_msg, display_name_errMsg, org_errMsg, number_errMsg, run_errMsg) { var totalLength = _.reduce(
if (header_err_msg) { ['.new-course-name', '.new-course-org', '.new-course-number', '.new-course-run'],
$('.wrapper-create-course').addClass('has-errors'); function(sum, ele) {
return sum + $(ele).val().length;
}, 0
);
if(totalLength > 80) {
$('.wrap-error').addClass('is-shown'); $('.wrap-error').addClass('is-shown');
$('#course_creation_error').html('<p>' + header_err_msg + '</p>'); $('#course_creation_error').html('<p>' + gettext('Course fields must have a combined length of no more than 80 characters.') + '</p>');
} else { $('.new-course-save').addClass('is-disabled');
}
else {
$('.wrap-error').removeClass('is-shown'); $('.wrap-error').removeClass('is-shown');
$('#course_creation_error').html('');
} }
}
var setNewCourseFieldInErr = function(el, msg) { // Handle validation asynchronously
el.children('.tip-error').remove(); _.each(
if (msg !== null && msg !== '') { ['.new-course-org', '.new-course-number', '.new-course-run'],
el.addClass('error'); function(ele) {
el.append('<span class="tip tip-error">' + msg + '</span>'); var $ele = $(ele);
} else { $ele.on('keyup', function(event) {
el.removeClass('error'); // Don't bother showing "required field" error when
} // the user tabs into a new field; this is distracting
}; // and unnecessary
if(event.keyCode === 9) {
return;
}
var error = validateCourseItemEncoding($ele.val());
setNewCourseFieldInErr($ele.parent('li'), error);
validateTotalCourseItemsLength();
});
}
);
var $name = $('.new-course-name');
$name.on('keyup', function() {
var error = validateRequiredField($name.val());
setNewCourseFieldInErr($name.parent('li'), error);
validateTotalCourseItemsLength();
});
}
function validateRequiredField(msg) {
return msg.length === 0 ? gettext('Required field.') : '';
}
function setNewCourseFieldInErr(el, msg) {
if(msg) {
el.addClass('error');
el.children('span.tip-error').addClass('is-showing').removeClass('is-hiding').text(msg);
$('.new-course-save').addClass('is-disabled');
}
else {
el.removeClass('error');
el.children('span.tip-error').addClass('is-hiding').removeClass('is-showing');
// One "error" div is always present, but hidden or shown
if($('.error').length === 1) {
$('.new-course-save').removeClass('is-disabled');
}
}
};
setNewCourseFieldInErr($('#field-course-name'), display_name_errMsg); function saveNewCourse(e) {
setNewCourseFieldInErr($('#field-organization'), org_errMsg); e.preventDefault();
setNewCourseFieldInErr($('#field-course-number'), number_errMsg);
setNewCourseFieldInErr($('#field-course-run'), run_errMsg);
};
setNewCourseErrMsgs(header_err_msg, display_name_errMsg, org_errMsg, number_errMsg, run_errMsg); // One final check for empty values
var errors = _.reduce(
['.new-course-name', '.new-course-org', '.new-course-number', '.new-course-run'],
function(acc, ele) {
var $ele = $(ele);
var error = validateRequiredField($ele.val());
setNewCourseFieldInErr($ele.parent('li'), error);
return error ? true : acc;
},
false
);
if (bInErr) if(errors) {
return; return;
}
var $newCourseForm = $(this).closest('#create-course-form');
var display_name = $newCourseForm.find('.new-course-name').val();
var org = $newCourseForm.find('.new-course-org').val();
var number = $newCourseForm.find('.new-course-number').val();
var run = $newCourseForm.find('.new-course-run').val();
analytics.track('Created a Course', { analytics.track('Created a Course', {
'org': org, 'org': org,
...@@ -697,9 +734,9 @@ function saveNewCourse(e) { ...@@ -697,9 +734,9 @@ function saveNewCourse(e) {
if (data.id !== undefined) { if (data.id !== undefined) {
window.location = '/' + data.id.replace(/.*:\/\//, ''); window.location = '/' + data.id.replace(/.*:\/\//, '');
} else if (data.ErrMsg !== undefined) { } else if (data.ErrMsg !== undefined) {
var orgErrMsg = (data.OrgErrMsg !== undefined) ? data.OrgErrMsg : null; $('.wrap-error').addClass('is-shown');
var courseErrMsg = (data.CourseErrMsg !== undefined) ? data.CourseErrMsg : null; $('#course_creation_error').html('<p>' + data.ErrMsg + '</p>');
setNewCourseErrMsgs(data.ErrMsg, null, orgErrMsg, courseErrMsg, null); $('.new-course-save').addClass('is-disabled');
} }
} }
); );
...@@ -709,6 +746,16 @@ function cancelNewCourse(e) { ...@@ -709,6 +746,16 @@ function cancelNewCourse(e) {
e.preventDefault(); e.preventDefault();
$('.new-course-button').removeClass('is-disabled'); $('.new-course-button').removeClass('is-disabled');
$('.wrapper-create-course').removeClass('is-shown'); $('.wrapper-create-course').removeClass('is-shown');
// Clear out existing fields and errors
_.each(
['.new-course-name', '.new-course-org', '.new-course-number', '.new-course-run'],
function(field) {
$(field).val('');
}
);
$('#course_creation_error').html('');
$('.wrap-error').removeClass('is-shown');
$('.new-course-save').off('click');
} }
function addNewSubsection(e) { function addNewSubsection(e) {
......
...@@ -75,7 +75,7 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({ ...@@ -75,7 +75,7 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
return this.videosourceSample(); return this.videosourceSample();
}, },
videosourceSample : function() { videosourceSample : function() {
if (this.has('intro_video')) return "http://www.youtube.com/embed/" + this.get('intro_video'); if (this.has('intro_video')) return "//www.youtube.com/embed/" + this.get('intro_video');
else return ""; else return "";
} }
}); });
...@@ -225,8 +225,15 @@ form[class^="create-"] { ...@@ -225,8 +225,15 @@ form[class^="create-"] {
color: $red; color: $red;
} }
.is-showing {
@extend .anim-fadeIn;
}
.is-hiding {
@extend .anim-fadeOut;
}
.tip-error { .tip-error {
@extend .anim-fadeIn;
display: block; display: block;
color: $red; color: $red;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// ==================== // ====================
// Video Alpha // Video Alpha
.xmodule_VideoAlphaModule { .xmodule_VideoModule {
// display mode // display mode
&.xmodule_display { &.xmodule_display {
......
...@@ -99,23 +99,27 @@ ...@@ -99,23 +99,27 @@
<label for="new-course-name">${_("Course Name")}</label> <label for="new-course-name">${_("Course Name")}</label>
<input class="new-course-name" id="new-course-name" type="text" name="new-course-name" aria-required="true" placeholder="${_('e.g. Introduction to Computer Science')}" /> <input class="new-course-name" id="new-course-name" type="text" name="new-course-name" aria-required="true" placeholder="${_('e.g. Introduction to Computer Science')}" />
<span class="tip tip-stacked">${_("The public display name for your course.")}</span> <span class="tip tip-stacked">${_("The public display name for your course.")}</span>
<span class="tip tip-error is-hiding"></span>
</li> </li>
<li class="field field-inline text required" id="field-organization"> <li class="field field-inline text required" id="field-organization">
<label for="new-course-org">${_("Organization")}</label> <label for="new-course-org">${_("Organization")}</label>
<input class="new-course-org" id="new-course-org" type="text" name="new-course-org" aria-required="true" placeholder="${_('e.g. MITX or IMF')}" /> <input class="new-course-org" id="new-course-org" type="text" name="new-course-org" aria-required="true" placeholder="${_('e.g. MITX or IMF')}" />
<span class="tip tip-stacked">${_("The name of the organization sponsoring the course")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span> <span class="tip tip-stacked">${_("The name of the organization sponsoring the course")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span>
<span class="tip tip-error is-hiding"></span>
</li> </li>
<li class="field field-inline text required" id="field-course-number"> <li class="field field-inline text required" id="field-course-number">
<label for="new-course-number">${_("Course Number")}</label> <label for="new-course-number">${_("Course Number")}</label>
<input class="new-course-number" id="new-course-number" type="text" name="new-course-number" aria-required="true" placeholder="${_('e.g. CS101')}" /> <input class="new-course-number" id="new-course-number" type="text" name="new-course-number" aria-required="true" placeholder="${_('e.g. CS101')}" />
<span class="tip tip-stacked">${_("The unique number that identifies your course within your organization")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span> <span class="tip tip-stacked">${_("The unique number that identifies your course within your organization")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span>
<span class="tip tip-error is-hiding"></span>
</li> </li>
<li class="field field-inline text required" id="field-course-run"> <li class="field field-inline text required" id="field-course-run">
<label for="new-course-run">${_("Course Run")}</label> <label for="new-course-run">${_("Course Run")}</label>
<input class="new-course-run" id="new-course-run" type="text" name="new-course-run" aria-required="true"placeholder="${_('e.g. 2013_Spring')}" /> <input class="new-course-run" id="new-course-run" type="text" name="new-course-run" aria-required="true"placeholder="${_('e.g. 2013_Spring')}" />
<span class="tip tip-stacked">${_("The term in which your course will run")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span> <span class="tip tip-stacked">${_("The term in which your course will run")} - <strong>${_("Note: No spaces or special characters are allowed. This cannot be changed.")}</strong></span>
<span class="tip tip-error is-hiding"></span>
</li> </li>
</ol> </ol>
...@@ -123,7 +127,7 @@ ...@@ -123,7 +127,7 @@
</div> </div>
<div class="actions"> <div class="actions">
<input type="submit" value="${_('Save')}" class="action action-primary new-course-save" /> <input type="submit" value="${_('Create')}" class="action action-primary new-course-save" />
<input type="button" value="${_('Cancel')}" class="action action-secondary action-cancel new-course-cancel" /> <input type="button" value="${_('Cancel')}" class="action action-secondary action-cancel new-course-cancel" />
</div> </div>
</form> </form>
......
...@@ -19,6 +19,20 @@ FORUM_ROLE_STUDENT = 'Student' ...@@ -19,6 +19,20 @@ FORUM_ROLE_STUDENT = 'Student'
@receiver(post_save, sender=CourseEnrollment) @receiver(post_save, sender=CourseEnrollment)
def assign_default_role(sender, instance, **kwargs): def assign_default_role(sender, instance, **kwargs):
# The code below would remove all forum Roles from a user when they unenroll
# from a course. Concerns were raised that it should apply only to students,
# or that even the history of student roles is important for research
# purposes. Since this was new functionality being added in this release,
# I'm just going to comment it out for now and let the forums team deal with
# implementing the right behavior.
#
# # We've unenrolled the student, so remove all roles for this course
# if not instance.is_active:
# course_roles = list(Role.objects.filter(course_id=instance.course_id))
# instance.user.roles.remove(*course_roles)
# return
# We've enrolled the student, so make sure they have a default role
if instance.user.is_staff: if instance.user.is_staff:
role = Role.objects.get_or_create(course_id=instance.course_id, name="Moderator")[0] role = Role.objects.get_or_create(course_id=instance.course_id, name="Moderator")[0]
else: else:
......
from django.test import TestCase
from django_comment_common.models import Role
from student.models import CourseEnrollment, User
class RoleAssignmentTest(TestCase):
"""
Basic checks to make sure our Roles get assigned and unassigned as students
are enrolled and unenrolled from a course.
"""
def setUp(self):
self.staff_user = User.objects.create_user(
"patty",
"patty@fake.edx.org",
)
self.staff_user.is_staff = True
self.student_user = User.objects.create_user(
"hacky",
"hacky@fake.edx.org"
)
self.course_id = "edX/Fake101/2012"
CourseEnrollment.enroll(self.staff_user, self.course_id)
CourseEnrollment.enroll(self.student_user, self.course_id)
def test_enrollment_auto_role_creation(self):
moderator_role = Role.objects.get(
course_id=self.course_id,
name="Moderator"
)
student_role = Role.objects.get(
course_id=self.course_id,
name="Student"
)
self.assertIn(moderator_role, self.staff_user.roles.all())
self.assertIn(student_role, self.student_user.roles.all())
self.assertNotIn(moderator_role, self.student_user.roles.all())
# The following was written on the assumption that unenrolling from a course
# should remove all forum Roles for that student for that course. This is
# not necessarily the case -- please see comments at the top of
# django_comment_client.models.assign_default_role(). Leaving it for the
# forums team to sort out.
#
# def test_unenrollment_auto_role_removal(self):
# another_student = User.objects.create_user("sol", "sol@fake.edx.org")
# CourseEnrollment.enroll(another_student, self.course_id)
#
# CourseEnrollment.unenroll(self.student_user, self.course_id)
# # Make sure we didn't delete the actual Role
# student_role = Role.objects.get(
# course_id=self.course_id,
# name="Student"
# )
# self.assertNotIn(student_role, self.student_user.roles.all())
# self.assertIn(student_role, another_student.roles.all())
...@@ -431,12 +431,12 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -431,12 +431,12 @@ class ShibSPTest(ModuleStoreTestCase):
# If course is not limited or student has correct shib extauth then enrollment should be allowed # If course is not limited or student has correct shib extauth then enrollment should be allowed
if course is open_enroll_course or student is shib_student: if course is open_enroll_course or student is shib_student:
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(CourseEnrollment.objects.filter(user=student, course_id=course.id).count(), 1) self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
# Clean up # Clean up
CourseEnrollment.objects.filter(user=student, course_id=course.id).delete() CourseEnrollment.unenroll(student, course.id)
else: else:
self.assertEqual(response.status_code, 400) self.assertEqual(response.status_code, 400)
self.assertEqual(CourseEnrollment.objects.filter(user=student, course_id=course.id).count(), 0) self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
@unittest.skipUnless(settings.MITX_FEATURES.get('AUTH_USE_SHIB'), True) @unittest.skipUnless(settings.MITX_FEATURES.get('AUTH_USE_SHIB'), True)
def test_shib_login_enrollment(self): def test_shib_login_enrollment(self):
...@@ -462,7 +462,7 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -462,7 +462,7 @@ class ShibSPTest(ModuleStoreTestCase):
# use django test client for sessions and url processing # use django test client for sessions and url processing
# no enrollment before trying # no enrollment before trying
self.assertEqual(CourseEnrollment.objects.filter(user=student, course_id=course.id).count(), 0) self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
self.client.logout() self.client.logout()
request_kwargs = {'path': '/shib-login/', request_kwargs = {'path': '/shib-login/',
'data': {'enrollment_action': 'enroll', 'course_id': course.id}, 'data': {'enrollment_action': 'enroll', 'course_id': course.id},
...@@ -474,4 +474,4 @@ class ShibSPTest(ModuleStoreTestCase): ...@@ -474,4 +474,4 @@ class ShibSPTest(ModuleStoreTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], 'http://testserver/') self.assertEqual(response['location'], 'http://testserver/')
# now there is enrollment # now there is enrollment
self.assertEqual(CourseEnrollment.objects.filter(user=student, course_id=course.id).count(), 1) self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
# -*- coding: utf8 -*-
"""Dump username,unique_id_for_user pairs as CSV.
Give instructors easy access to the mapping from anonymized IDs to user IDs
with a simple Django management command to generate a CSV mapping. To run, use
the following:
rake django-admin[anonymized_id_mapping,x,y,z]
[Naturally, substitute the appropriate values for x, y, and z. (I.e.,
lms, dev, and MITx/6.002x/Circuits)]"""
import csv
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError
from student.models import unique_id_for_user
class Command(BaseCommand):
"""Add our handler to the space where django-admin looks up commands."""
# It appears that with the way Rake invokes these commands, we can't
# have more than one arg passed through...annoying.
args = ("course_id", )
help = """Export a CSV mapping usernames to anonymized ids
Exports a CSV document mapping each username in the specified course to
the anonymized, unique user ID.
"""
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Usage: unique_id_mapping %s" %
" ".join(("<%s>" % arg for arg in Command.args)))
course_id = args[0]
# Generate the output filename from the course ID.
# Change slashes to dashes first, and then append .csv extension.
output_filename = course_id.replace('/', '-') + ".csv"
# Figure out which students are enrolled in the course
students = User.objects.filter(courseenrollment__course_id=course_id)
if len(students) == 0:
self.stdout.write("No students enrolled in %s" % course_id)
return
# Write mapping to output file in CSV format with a simple header
try:
with open(output_filename, 'wb') as output_file:
csv_writer = csv.writer(output_file)
csv_writer.writerow(("User ID", "Anonymized user ID"))
for student in students:
csv_writer.writerow((student.id, unique_id_for_user(student)))
except IOError:
raise CommandError("Error writing to file: %s" % output_filename)
...@@ -12,7 +12,7 @@ def create(n, course_id): ...@@ -12,7 +12,7 @@ def create(n, course_id):
for i in range(n): for i in range(n):
(user, user_profile, _) = _do_create_account(get_random_post_override()) (user, user_profile, _) = _do_create_account(get_random_post_override())
if course_id is not None: if course_id is not None:
CourseEnrollment.objects.create(user=user, course_id=course_id) CourseEnrollment.enroll(user, course_id)
class Command(BaseCommand): class Command(BaseCommand):
......
from courseware import grades, courses
from django.test.client import RequestFactory
from django.core.management.base import BaseCommand, CommandError
import os
from django.contrib.auth.models import User
from optparse import make_option
import datetime
from django.core.handlers.base import BaseHandler
import csv
class RequestMock(RequestFactory):
def request(self, **request):
"Construct a generic request object."
request = RequestFactory.request(self, **request)
handler = BaseHandler()
handler.load_middleware()
for middleware_method in handler._request_middleware:
if middleware_method(request):
raise Exception("Couldn't create request mock object - "
"request middleware returned a response")
return request
class Command(BaseCommand):
help = """
Generate a list of grades for all students
that are enrolled in a course.
Outputs grades to a csv file.
Example:
sudo -u www-data SERVICE_VARIANT=lms /opt/edx/bin/django-admin.py get_grades \
-c MITx/Chi6.00intro/A_Taste_of_Python_Programming -o /tmp/20130813-6.00x.csv \
--settings=lms.envs.aws --pythonpath=/opt/wwc/edx-platform
"""
option_list = BaseCommand.option_list + (
make_option('-c', '--course',
metavar='COURSE_ID',
dest='course',
default=False,
help='Course ID for grade distribution'),
make_option('-o', '--output',
metavar='FILE',
dest='output',
default=False,
help='Filename for grade output'))
def handle(self, *args, **options):
if os.path.exists(options['output']):
raise CommandError("File {0} already exists".format(
options['output']))
STATUS_INTERVAL = 100
course_id = options['course']
print "Fetching enrolled students for {0}".format(course_id)
enrolled_students = User.objects.filter(
courseenrollment__course_id=course_id).prefetch_related(
"groups").order_by('username')
factory = RequestMock()
request = factory.get('/')
total = enrolled_students.count()
print "Total enrolled: {0}".format(total)
course = courses.get_course_by_id(course_id)
total = enrolled_students.count()
start = datetime.datetime.now()
rows = []
header = None
for count, student in enumerate(enrolled_students):
count += 1
if count % STATUS_INTERVAL == 0:
# Print a status update with an approximation of
# how much time is left based on how long the last
# interval took
diff = datetime.datetime.now() - start
timeleft = diff * (total - count) / STATUS_INTERVAL
hours, remainder = divmod(timeleft.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
print "{0}/{1} completed ~{2:02}:{3:02}m remaining".format(
count, total, hours, minutes)
start = datetime.datetime.now()
request.user = student
grade = grades.grade(student, request, course)
if not header:
header = [section['label'] for section in grade[u'section_breakdown']]
rows.append(["email", "username"] + header)
percents = {section['label']: section['percent'] for section in grade[u'section_breakdown']}
row_percents = [percents[label] for label in header]
rows.append([student.email, student.username] + row_percents)
with open(options['output'], 'wb') as f:
writer = csv.writer(f)
writer.writerows(rows)
...@@ -21,7 +21,7 @@ class Migration(SchemaMigration): ...@@ -21,7 +21,7 @@ class Migration(SchemaMigration):
('eligibility_appointment_date_first', self.gf('django.db.models.fields.DateField')(db_index=True)), ('eligibility_appointment_date_first', self.gf('django.db.models.fields.DateField')(db_index=True)),
('eligibility_appointment_date_last', self.gf('django.db.models.fields.DateField')(db_index=True)), ('eligibility_appointment_date_last', self.gf('django.db.models.fields.DateField')(db_index=True)),
('accommodation_code', self.gf('django.db.models.fields.CharField')(max_length=64, blank=True)), ('accommodation_code', self.gf('django.db.models.fields.CharField')(max_length=64, blank=True)),
('accommodation_request', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=1024, blank=True)), ('accommodation_request', self.gf('django.db.models.fields.CharField')(db_index=False, max_length=1024, blank=True)),
('uploaded_at', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)), ('uploaded_at', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)),
('processed_at', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)), ('processed_at', self.gf('django.db.models.fields.DateTimeField')(null=True, db_index=True)),
('upload_status', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=20, blank=True)), ('upload_status', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=20, blank=True)),
...@@ -163,7 +163,7 @@ class Migration(SchemaMigration): ...@@ -163,7 +163,7 @@ class Migration(SchemaMigration):
'student.testcenterregistration': { 'student.testcenterregistration': {
'Meta': {'object_name': 'TestCenterRegistration'}, 'Meta': {'object_name': 'TestCenterRegistration'},
'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), 'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1024', 'blank': 'True'}), 'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'False', 'max_length': '1024', 'blank': 'True'}),
'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}), 'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}),
'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}), 'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}),
'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}), 'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}),
......
...@@ -93,7 +93,7 @@ class Migration(SchemaMigration): ...@@ -93,7 +93,7 @@ class Migration(SchemaMigration):
'student.testcenterregistration': { 'student.testcenterregistration': {
'Meta': {'object_name': 'TestCenterRegistration'}, 'Meta': {'object_name': 'TestCenterRegistration'},
'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), 'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1024', 'blank': 'True'}), 'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'False', 'max_length': '1024', 'blank': 'True'}),
'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}), 'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}),
'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}), 'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}),
'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}), 'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}),
......
...@@ -94,7 +94,7 @@ class Migration(SchemaMigration): ...@@ -94,7 +94,7 @@ class Migration(SchemaMigration):
'student.testcenterregistration': { 'student.testcenterregistration': {
'Meta': {'object_name': 'TestCenterRegistration'}, 'Meta': {'object_name': 'TestCenterRegistration'},
'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), 'accommodation_code': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1024', 'blank': 'True'}), 'accommodation_request': ('django.db.models.fields.CharField', [], {'db_index': 'False', 'max_length': '1024', 'blank': 'True'}),
'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}), 'authorization_id': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}),
'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}), 'client_authorization_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'db_index': 'True'}),
'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}), 'confirmed_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'db_index': 'True'}),
......
...@@ -21,9 +21,8 @@ from django.utils.http import int_to_base36 ...@@ -21,9 +21,8 @@ from django.utils.http import int_to_base36
from mock import Mock, patch from mock import Mock, patch
from textwrap import dedent from textwrap import dedent
from student.models import unique_id_for_user from student.models import unique_id_for_user, CourseEnrollment
from student.views import process_survey_link, _cert_info, password_reset, password_reset_confirm_wrapper from student.views import process_survey_link, _cert_info, password_reset, password_reset_confirm_wrapper
from student.views import enroll_in_course, is_enrolled_in_course
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from student.tests.test_email import mock_render_to_string from student.tests.test_email import mock_render_to_string
COURSE_1 = 'edX/toy/2012_Fall' COURSE_1 = 'edX/toy/2012_Fall'
...@@ -209,12 +208,127 @@ class CourseEndingTest(TestCase): ...@@ -209,12 +208,127 @@ class CourseEndingTest(TestCase):
class EnrollInCourseTest(TestCase): class EnrollInCourseTest(TestCase):
""" Tests the helper method for enrolling a user in a class """ """Tests enrolling and unenrolling in courses."""
def test_enroll_in_course(self): def test_enrollment(self):
user = User.objects.create_user("joe", "joe@joe.com", "password") user = User.objects.create_user("joe", "joe@joe.com", "password")
user.save() course_id = "edX/Test101/2013"
course_id = "course_id"
self.assertFalse(is_enrolled_in_course(user, course_id)) # Test basic enrollment
enroll_in_course(user, course_id) self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assertTrue(is_enrolled_in_course(user, course_id)) CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
# Enrolling them again should be harmless
CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
# Now unenroll the user
CourseEnrollment.unenroll(user, course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Unenrolling them again should also be harmless
CourseEnrollment.unenroll(user, course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# The enrollment record should still exist, just be inactive
enrollment_record = CourseEnrollment.objects.get(
user=user,
course_id=course_id
)
self.assertFalse(enrollment_record.is_active)
def test_enrollment_non_existent_user(self):
# Testing enrollment of newly unsaved user (i.e. no database entry)
user = User(username="rusty", email="rusty@fake.edx.org")
course_id = "edX/Test101/2013"
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Unenroll does nothing
CourseEnrollment.unenroll(user, course_id)
# Implicit save() happens on new User object when enrolling, so this
# should still work
CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
def test_enrollment_by_email(self):
user = User.objects.create(username="jack", email="jack@fake.edx.org")
course_id = "edX/Test101/2013"
CourseEnrollment.enroll_by_email("jack@fake.edx.org", course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
# This won't throw an exception, even though the user is not found
self.assertIsNone(
CourseEnrollment.enroll_by_email("not_jack@fake.edx.org", course_id)
)
self.assertRaises(
User.DoesNotExist,
CourseEnrollment.enroll_by_email,
"not_jack@fake.edx.org",
course_id,
ignore_errors=False
)
# Now unenroll them by email
CourseEnrollment.unenroll_by_email("jack@fake.edx.org", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Harmless second unenroll
CourseEnrollment.unenroll_by_email("jack@fake.edx.org", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Unenroll on non-existent user shouldn't throw an error
CourseEnrollment.unenroll_by_email("not_jack@fake.edx.org", course_id)
def test_enrollment_multiple_classes(self):
user = User(username="rusty", email="rusty@fake.edx.org")
course_id1 = "edX/Test101/2013"
course_id2 = "MITx/6.003z/2012"
CourseEnrollment.enroll(user, course_id1)
CourseEnrollment.enroll(user, course_id2)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id1))
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id2))
CourseEnrollment.unenroll(user, course_id1)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id1))
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id2))
CourseEnrollment.unenroll(user, course_id2)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id1))
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id2))
def test_activation(self):
user = User.objects.create(username="jack", email="jack@fake.edx.org")
course_id = "edX/Test101/2013"
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Creating an enrollment doesn't actually enroll a student
# (calling CourseEnrollment.enroll() would have)
enrollment = CourseEnrollment.create_enrollment(user, course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Until you explicitly activate it
enrollment.activate()
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
# Activating something that's already active does nothing
enrollment.activate()
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
# Now deactive
enrollment.deactivate()
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# Deactivating something that's already inactive does nothing
enrollment.deactivate()
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
# A deactivated enrollment should be activated if enroll() is called
# for that user/course_id combination
CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
...@@ -254,13 +254,12 @@ def register_user(request, extra_context=None): ...@@ -254,13 +254,12 @@ def register_user(request, extra_context=None):
@ensure_csrf_cookie @ensure_csrf_cookie
def dashboard(request): def dashboard(request):
user = request.user user = request.user
enrollments = CourseEnrollment.objects.filter(user=user)
# Build our courses list for the user, but ignore any courses that no longer # Build our courses list for the user, but ignore any courses that no longer
# exist (because the course IDs have changed). Still, we don't delete those # exist (because the course IDs have changed). Still, we don't delete those
# enrollments, because it could have been a data push snafu. # enrollments, because it could have been a data push snafu.
courses = [] courses = []
for enrollment in enrollments: for enrollment in CourseEnrollment.enrollments_for_user(user):
try: try:
courses.append(course_from_id(enrollment.course_id)) courses.append(course_from_id(enrollment.course_id))
except ItemNotFoundError: except ItemNotFoundError:
...@@ -377,18 +376,13 @@ def change_enrollment(request): ...@@ -377,18 +376,13 @@ def change_enrollment(request):
"course:{0}".format(course_num), "course:{0}".format(course_num),
"run:{0}".format(run)]) "run:{0}".format(run)])
try: CourseEnrollment.enroll(user, course.id)
enroll_in_course(user, course.id)
except IntegrityError:
# If we've already created this enrollment in a separate transaction,
# then just continue
pass
return HttpResponse() return HttpResponse()
elif action == "unenroll": elif action == "unenroll":
try: try:
enrollment = CourseEnrollment.objects.get(user=user, course_id=course_id) CourseEnrollment.unenroll(user, course_id)
enrollment.delete()
org, course_num, run = course_id.split("/") org, course_num, run = course_id.split("/")
statsd.increment("common.student.unenrollment", statsd.increment("common.student.unenrollment",
...@@ -402,30 +396,10 @@ def change_enrollment(request): ...@@ -402,30 +396,10 @@ def change_enrollment(request):
else: else:
return HttpResponseBadRequest(_("Enrollment action is invalid")) return HttpResponseBadRequest(_("Enrollment action is invalid"))
def enroll_in_course(user, course_id):
"""
Helper method to enroll a user in a particular class.
It is expected that this method is called from a method which has already
verified the user authentication and access.
"""
CourseEnrollment.objects.get_or_create(user=user, course_id=course_id)
def is_enrolled_in_course(user, course_id):
"""
Helper method that returns whether or not the user is enrolled in a particular course.
"""
return CourseEnrollment.objects.filter(user=user, course_id=course_id).count() > 0
@ensure_csrf_cookie @ensure_csrf_cookie
def accounts_login(request, error=""): def accounts_login(request, error=""):
return render_to_response('login.html', {'error': error}) return render_to_response('login.html', {'error': error})
# Need different levels of logging # Need different levels of logging
@ensure_csrf_cookie @ensure_csrf_cookie
def login_user(request, error=""): def login_user(request, error=""):
...@@ -1008,13 +982,21 @@ def activate_account(request, key): ...@@ -1008,13 +982,21 @@ def activate_account(request, key):
ceas = CourseEnrollmentAllowed.objects.filter(email=student[0].email) ceas = CourseEnrollmentAllowed.objects.filter(email=student[0].email)
for cea in ceas: for cea in ceas:
if cea.auto_enroll: if cea.auto_enroll:
course_id = cea.course_id CourseEnrollment.enroll(student[0], cea.course_id)
_enrollment, _created = CourseEnrollment.objects.get_or_create(user_id=student[0].id, course_id=course_id)
resp = render_to_response(
resp = render_to_response("registration/activation_complete.html", {'user_logged_in': user_logged_in, 'already_active': already_active}) "registration/activation_complete.html",
{
'user_logged_in': user_logged_in,
'already_active': already_active
}
)
return resp return resp
if len(r) == 0: if len(r) == 0:
return render_to_response("registration/activation_invalid.html", {'csrf': csrf(request)['csrf_token']}) return render_to_response(
"registration/activation_invalid.html",
{'csrf': csrf(request)['csrf_token']}
)
return HttpResponse(_("Unknown error. Please e-mail us to let us know how it happened.")) return HttpResponse(_("Unknown error. Please e-mail us to let us know how it happened."))
...@@ -1037,7 +1019,11 @@ def password_reset(request): ...@@ -1037,7 +1019,11 @@ def password_reset(request):
'error': _('Invalid e-mail or user')})) 'error': _('Invalid e-mail or user')}))
def password_reset_confirm_wrapper(request, uidb36=None, token=None): def password_reset_confirm_wrapper(
request,
uidb36=None,
token=None,
):
''' A wrapper around django.contrib.auth.views.password_reset_confirm. ''' A wrapper around django.contrib.auth.views.password_reset_confirm.
Needed because we want to set the user as active at this step. Needed because we want to set the user as active at this step.
''' '''
...@@ -1049,7 +1035,12 @@ def password_reset_confirm_wrapper(request, uidb36=None, token=None): ...@@ -1049,7 +1035,12 @@ def password_reset_confirm_wrapper(request, uidb36=None, token=None):
user.save() user.save()
except (ValueError, User.DoesNotExist): except (ValueError, User.DoesNotExist):
pass pass
return password_reset_confirm(request, uidb36=uidb36, token=token) # we also want to pass settings.PLATFORM_NAME in as extra_context
extra_context = {"platform_name": settings.PLATFORM_NAME}
return password_reset_confirm(
request, uidb36=uidb36, token=token, extra_context=extra_context
)
def reactivation_email_for_user(user): def reactivation_email_for_user(user):
......
...@@ -54,7 +54,7 @@ def register_by_course_id(course_id, is_staff=False): ...@@ -54,7 +54,7 @@ def register_by_course_id(course_id, is_staff=False):
if is_staff: if is_staff:
u.is_staff = True u.is_staff = True
u.save() u.save()
CourseEnrollment.objects.get_or_create(user=u, course_id=course_id) CourseEnrollment.enroll(u, course_id)
@world.absorb @world.absorb
......
# -*- coding: utf-8 -*-
"""
Unit tests for preview.py
"""
import unittest
import preview
import pyparsing
class LatexRenderedTest(unittest.TestCase):
"""
Test the initializing code for LatexRendered.
Specifically that it stores the correct data and handles parens well.
"""
def test_simple(self):
"""
Test that the data values are stored without changing.
"""
math = 'x^2'
obj = preview.LatexRendered(math, tall=True)
self.assertEquals(obj.latex, math)
self.assertEquals(obj.sans_parens, math)
self.assertEquals(obj.tall, True)
def _each_parens(self, with_parens, math, parens, tall=False):
"""
Helper method to test the way parens are wrapped.
"""
obj = preview.LatexRendered(math, parens=parens, tall=tall)
self.assertEquals(obj.latex, with_parens)
self.assertEquals(obj.sans_parens, math)
self.assertEquals(obj.tall, tall)
def test_parens(self):
""" Test curvy parens. """
self._each_parens('(x+y)', 'x+y', '(')
def test_brackets(self):
""" Test brackets. """
self._each_parens('[x+y]', 'x+y', '[')
def test_squiggles(self):
""" Test curly braces. """
self._each_parens(r'\{x+y\}', 'x+y', '{')
def test_parens_tall(self):
""" Test curvy parens with the tall parameter. """
self._each_parens(r'\left(x^y\right)', 'x^y', '(', tall=True)
def test_brackets_tall(self):
""" Test brackets, also tall. """
self._each_parens(r'\left[x^y\right]', 'x^y', '[', tall=True)
def test_squiggles_tall(self):
""" Test tall curly braces. """
self._each_parens(r'\left\{x^y\right\}', 'x^y', '{', tall=True)
def test_bad_parens(self):
""" Check that we get an error with invalid parens. """
with self.assertRaisesRegexp(Exception, 'Unknown parenthesis'):
preview.LatexRendered('x^2', parens='not parens')
class LatexPreviewTest(unittest.TestCase):
"""
Run integrative tests for `latex_preview`.
All functionality was tested `RenderMethodsTest`, but see if it combines
all together correctly.
"""
def test_no_input(self):
"""
With no input (including just whitespace), see that no error is thrown.
"""
self.assertEquals('', preview.latex_preview(''))
self.assertEquals('', preview.latex_preview(' '))
self.assertEquals('', preview.latex_preview(' \t '))
def test_number_simple(self):
""" Simple numbers should pass through. """
self.assertEquals(preview.latex_preview('3.1415'), '3.1415')
def test_number_suffix(self):
""" Suffixes should be escaped. """
self.assertEquals(preview.latex_preview('1.618k'), r'1.618\text{k}')
def test_number_sci_notation(self):
""" Numbers with scientific notation should display nicely """
self.assertEquals(
preview.latex_preview('6.0221413E+23'),
r'6.0221413\!\times\!10^{+23}'
)
self.assertEquals(
preview.latex_preview('-6.0221413E+23'),
r'-6.0221413\!\times\!10^{+23}'
)
def test_number_sci_notation_suffix(self):
""" Test numbers with both of these. """
self.assertEquals(
preview.latex_preview('6.0221413E+23k'),
r'6.0221413\!\times\!10^{+23}\text{k}'
)
self.assertEquals(
preview.latex_preview('-6.0221413E+23k'),
r'-6.0221413\!\times\!10^{+23}\text{k}'
)
def test_variable_simple(self):
""" Simple valid variables should pass through. """
self.assertEquals(preview.latex_preview('x', variables=['x']), 'x')
def test_greek(self):
""" Variable names that are greek should be formatted accordingly. """
self.assertEquals(preview.latex_preview('pi'), r'\pi')
def test_variable_subscript(self):
""" Things like 'epsilon_max' should display nicely """
self.assertEquals(
preview.latex_preview('epsilon_max', variables=['epsilon_max']),
r'\epsilon_{max}'
)
def test_function_simple(self):
""" Valid function names should be escaped. """
self.assertEquals(
preview.latex_preview('f(3)', functions=['f']),
r'\text{f}(3)'
)
def test_function_tall(self):
r""" Functions surrounding a tall element should have \left, \right """
self.assertEquals(
preview.latex_preview('f(3^2)', functions=['f']),
r'\text{f}\left(3^{2}\right)'
)
def test_function_sqrt(self):
""" Sqrt function should be handled specially. """
self.assertEquals(preview.latex_preview('sqrt(3)'), r'\sqrt{3}')
def test_function_log10(self):
""" log10 function should be handled specially. """
self.assertEquals(preview.latex_preview('log10(3)'), r'\log_{10}(3)')
def test_function_log2(self):
""" log2 function should be handled specially. """
self.assertEquals(preview.latex_preview('log2(3)'), r'\log_2(3)')
def test_power_simple(self):
""" Powers should wrap the elements with braces correctly. """
self.assertEquals(preview.latex_preview('2^3^4'), '2^{3^{4}}')
def test_power_parens(self):
""" Powers should ignore the parenthesis of the last math. """
self.assertEquals(preview.latex_preview('2^3^(4+5)'), '2^{3^{4+5}}')
def test_parallel(self):
r""" Parallel items should combine with '\|'. """
self.assertEquals(preview.latex_preview('2||3'), r'2\|3')
def test_product_mult_only(self):
r""" Simple products should combine with a '\cdot'. """
self.assertEquals(preview.latex_preview('2*3'), r'2\cdot 3')
def test_product_big_frac(self):
""" Division should combine with '\frac'. """
self.assertEquals(
preview.latex_preview('2*3/4/5'),
r'\frac{2\cdot 3}{4\cdot 5}'
)
def test_product_single_frac(self):
""" Division should ignore parens if they are extraneous. """
self.assertEquals(
preview.latex_preview('(2+3)/(4+5)'),
r'\frac{2+3}{4+5}'
)
def test_product_keep_going(self):
"""
Complex products/quotients should split into many '\frac's when needed.
"""
self.assertEquals(
preview.latex_preview('2/3*4/5*6'),
r'\frac{2}{3}\cdot \frac{4}{5}\cdot 6'
)
def test_sum(self):
""" Sums should combine its elements. """
# Use 'x' as the first term (instead of, say, '1'), so it can't be
# interpreted as a negative number.
self.assertEquals(
preview.latex_preview('-x+2-3+4', variables=['x']),
'-x+2-3+4'
)
def test_sum_tall(self):
""" A complicated expression should not hide the tallness. """
self.assertEquals(
preview.latex_preview('(2+3^2)'),
r'\left(2+3^{2}\right)'
)
def test_complicated(self):
"""
Given complicated input, ensure that exactly the correct string is made.
"""
self.assertEquals(
preview.latex_preview('11*f(x)+x^2*(3||4)/sqrt(pi)'),
r'11\cdot \text{f}(x)+\frac{x^{2}\cdot (3\|4)}{\sqrt{\pi}}'
)
self.assertEquals(
preview.latex_preview('log10(1+3/4/Cos(x^2)*(x+1))',
case_sensitive=True),
(r'\log_{10}\left(1+\frac{3}{4\cdot \text{Cos}\left(x^{2}\right)}'
r'\cdot (x+1)\right)')
)
def test_syntax_errors(self):
"""
Test a lot of math strings that give syntax errors
Rather than have a lot of self.assertRaises, make a loop and keep track
of those that do not throw a `ParseException`, and assert at the end.
"""
bad_math_list = [
'11+',
'11*',
'f((x)',
'sqrt(x^)',
'3f(x)', # Not 3*f(x)
'3|4',
'3|||4'
]
bad_exceptions = {}
for math in bad_math_list:
try:
preview.latex_preview(math)
except pyparsing.ParseException:
pass # This is what we were expecting. (not excepting :P)
except Exception as error: # pragma: no cover
bad_exceptions[math] = error
else: # pragma: no cover
# If there is no exception thrown, this is a problem
bad_exceptions[math] = None
self.assertEquals({}, bad_exceptions)
...@@ -16,6 +16,8 @@ Module containing the problem elements which render into input objects ...@@ -16,6 +16,8 @@ Module containing the problem elements which render into input objects
- crystallography - crystallography
- vsepr_input - vsepr_input
- drag_and_drop - drag_and_drop
- formulaequationinput
- chemicalequationinput
These are matched by *.html files templates/*.html which are mako templates with the These are matched by *.html files templates/*.html which are mako templates with the
actual html. actual html.
...@@ -47,6 +49,7 @@ import pyparsing ...@@ -47,6 +49,7 @@ import pyparsing
from .registry import TagRegistry from .registry import TagRegistry
from chem import chemcalc from chem import chemcalc
from preview import latex_preview
import xqueue_interface import xqueue_interface
from datetime import datetime from datetime import datetime
...@@ -531,7 +534,7 @@ class TextLine(InputTypeBase): ...@@ -531,7 +534,7 @@ class TextLine(InputTypeBase):
is used e.g. for embedding simulations turned into questions. is used e.g. for embedding simulations turned into questions.
Example: Example:
<texline math="1" trailing_text="m/s" /> <textline math="1" trailing_text="m/s" />
This example will render out a text line with a math preview and the text 'm/s' This example will render out a text line with a math preview and the text 'm/s'
after the end of the text line. after the end of the text line.
...@@ -1037,15 +1040,16 @@ class ChemicalEquationInput(InputTypeBase): ...@@ -1037,15 +1040,16 @@ class ChemicalEquationInput(InputTypeBase):
result = {'preview': '', result = {'preview': '',
'error': ''} 'error': ''}
formula = data['formula'] try:
if formula is None: formula = data['formula']
except KeyError:
result['error'] = "No formula specified." result['error'] = "No formula specified."
return result return result
try: try:
result['preview'] = chemcalc.render_to_html(formula) result['preview'] = chemcalc.render_to_html(formula)
except pyparsing.ParseException as p: except pyparsing.ParseException as p:
result['error'] = "Couldn't parse formula: {0}".format(p) result['error'] = u"Couldn't parse formula: {0}".format(p.msg)
except Exception: except Exception:
# this is unexpected, so log # this is unexpected, so log
log.warning( log.warning(
...@@ -1056,6 +1060,98 @@ class ChemicalEquationInput(InputTypeBase): ...@@ -1056,6 +1060,98 @@ class ChemicalEquationInput(InputTypeBase):
registry.register(ChemicalEquationInput) registry.register(ChemicalEquationInput)
#-------------------------------------------------------------------------
class FormulaEquationInput(InputTypeBase):
"""
An input type for entering formula equations. Supports live preview.
Example:
<formulaequationinput size="50"/>
options: size -- width of the textbox.
"""
template = "formulaequationinput.html"
tags = ['formulaequationinput']
@classmethod
def get_attributes(cls):
"""
Can set size of text field.
"""
return [Attribute('size', '20'), ]
def _extra_context(self):
"""
TODO (vshnayder): Get rid of 'previewer' once we have a standard way of requiring js to be loaded.
"""
# `reported_status` is basically `status`, except we say 'unanswered'
reported_status = ''
if self.status == 'unsubmitted':
reported_status = 'unanswered'
elif self.status in ('correct', 'incorrect', 'incomplete'):
reported_status = self.status
return {
'previewer': '/static/js/capa/src/formula_equation_preview.js',
'reported_status': reported_status
}
def handle_ajax(self, dispatch, get):
'''
Since we only have formcalc preview this input, check to see if it
matches the corresponding dispatch and send it through if it does
'''
if dispatch == 'preview_formcalc':
return self.preview_formcalc(get)
return {}
def preview_formcalc(self, get):
"""
Render an preview of a formula or equation. `get` should
contain a key 'formula' with a math expression.
Returns a json dictionary:
{
'preview' : '<some latex>' or ''
'error' : 'the-error' or ''
'request_start' : <time sent with request>
}
"""
result = {'preview': '',
'error': ''}
try:
formula = get['formula']
except KeyError:
result['error'] = "No formula specified."
return result
result['request_start'] = int(get.get('request_start', 0))
try:
# TODO add references to valid variables and functions
# At some point, we might want to mark invalid variables as red
# or something, and this is where we would need to pass those in.
result['preview'] = latex_preview(formula)
except pyparsing.ParseException as err:
result['error'] = "Sorry, couldn't parse formula"
result['formula'] = formula
except Exception:
# this is unexpected, so log
log.warning(
"Error while previewing formula", exc_info=True
)
result['error'] = "Error while rendering preview"
return result
registry.register(FormulaEquationInput)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
......
...@@ -822,7 +822,7 @@ class NumericalResponse(LoncapaResponse): ...@@ -822,7 +822,7 @@ class NumericalResponse(LoncapaResponse):
response_tag = 'numericalresponse' response_tag = 'numericalresponse'
hint_tag = 'numericalhint' hint_tag = 'numericalhint'
allowed_inputfields = ['textline'] allowed_inputfields = ['textline', 'formulaequationinput']
required_attributes = ['answer'] required_attributes = ['answer']
max_inputfields = 1 max_inputfields = 1
...@@ -837,11 +837,6 @@ class NumericalResponse(LoncapaResponse): ...@@ -837,11 +837,6 @@ class NumericalResponse(LoncapaResponse):
self.tolerance = contextualize_text(self.tolerance_xml, context) self.tolerance = contextualize_text(self.tolerance_xml, context)
except IndexError: # xpath found an empty list, so (...)[0] is the error except IndexError: # xpath found an empty list, so (...)[0] is the error
self.tolerance = '0' self.tolerance = '0'
try:
self.answer_id = xml.xpath('//*[@id=$id]//textline/@id',
id=xml.get('id'))[0]
except IndexError: # Same as above
self.answer_id = None
def get_score(self, student_answers): def get_score(self, student_answers):
'''Grade a numeric response ''' '''Grade a numeric response '''
...@@ -936,7 +931,7 @@ class CustomResponse(LoncapaResponse): ...@@ -936,7 +931,7 @@ class CustomResponse(LoncapaResponse):
'chemicalequationinput', 'vsepr_input', 'chemicalequationinput', 'vsepr_input',
'drag_and_drop_input', 'editamoleculeinput', 'drag_and_drop_input', 'editamoleculeinput',
'designprotein2dinput', 'editageneinput', 'designprotein2dinput', 'editageneinput',
'annotationinput', 'jsinput'] 'annotationinput', 'jsinput', 'formulaequationinput']
def setup_response(self): def setup_response(self):
xml = self.xml xml = self.xml
...@@ -1692,7 +1687,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -1692,7 +1687,7 @@ class FormulaResponse(LoncapaResponse):
response_tag = 'formularesponse' response_tag = 'formularesponse'
hint_tag = 'formulahint' hint_tag = 'formulahint'
allowed_inputfields = ['textline'] allowed_inputfields = ['textline', 'formulaequationinput']
required_attributes = ['answer', 'samples'] required_attributes = ['answer', 'samples']
max_inputfields = 1 max_inputfields = 1
...@@ -1737,7 +1732,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -1737,7 +1732,7 @@ class FormulaResponse(LoncapaResponse):
samples.split('@')[1].split('#')[0].split(':'))) samples.split('@')[1].split('#')[0].split(':')))
ranges = dict(zip(variables, sranges)) ranges = dict(zip(variables, sranges))
for i in range(numsamples): for _ in range(numsamples):
instructor_variables = self.strip_dict(dict(self.context)) instructor_variables = self.strip_dict(dict(self.context))
student_variables = dict() student_variables = dict()
# ranges give numerical ranges for testing # ranges give numerical ranges for testing
...@@ -1748,38 +1743,58 @@ class FormulaResponse(LoncapaResponse): ...@@ -1748,38 +1743,58 @@ class FormulaResponse(LoncapaResponse):
student_variables[str(var)] = value student_variables[str(var)] = value
# log.debug('formula: instructor_vars=%s, expected=%s' % # log.debug('formula: instructor_vars=%s, expected=%s' %
# (instructor_variables,expected)) # (instructor_variables,expected))
instructor_result = evaluator(instructor_variables, dict(),
expected, cs=self.case_sensitive) # Call `evaluator` on the instructor's answer and get a number
instructor_result = evaluator(
instructor_variables, dict(),
expected, case_sensitive=self.case_sensitive
)
try: try:
# log.debug('formula: student_vars=%s, given=%s' % # log.debug('formula: student_vars=%s, given=%s' %
# (student_variables,given)) # (student_variables,given))
student_result = evaluator(student_variables,
dict(), # Call `evaluator` on the student's answer; look for exceptions
given, student_result = evaluator(
cs=self.case_sensitive) student_variables,
dict(),
given,
case_sensitive=self.case_sensitive
)
except UndefinedVariable as uv: except UndefinedVariable as uv:
log.debug( log.debug(
'formularesponse: undefined variable in given=%s' % given) 'formularesponse: undefined variable in given=%s',
given
)
raise StudentInputError( raise StudentInputError(
"Invalid input: " + uv.message + " not permitted in answer") "Invalid input: " + uv.message + " not permitted in answer"
)
except ValueError as ve: except ValueError as ve:
if 'factorial' in ve.message: if 'factorial' in ve.message:
# This is thrown when fact() or factorial() is used in a formularesponse answer # This is thrown when fact() or factorial() is used in a formularesponse answer
# that tests on negative and/or non-integer inputs # that tests on negative and/or non-integer inputs
# ve.message will be: `factorial() only accepts integral values` or `factorial() not defined for negative values` # ve.message will be: `factorial() only accepts integral values` or
# `factorial() not defined for negative values`
log.debug( log.debug(
'formularesponse: factorial function used in response that tests negative and/or non-integer inputs. given={0}'.format(given)) ('formularesponse: factorial function used in response '
'that tests negative and/or non-integer inputs. '
'given={0}').format(given)
)
raise StudentInputError( raise StudentInputError(
"factorial function not permitted in answer for this problem. Provided answer was: {0}".format(given)) ("factorial function not permitted in answer "
"for this problem. Provided answer was: "
"{0}").format(cgi.escape(given))
)
# If non-factorial related ValueError thrown, handle it the same as any other Exception # If non-factorial related ValueError thrown, handle it the same as any other Exception
log.debug('formularesponse: error {0} in formula'.format(ve)) log.debug('formularesponse: error {0} in formula'.format(ve))
raise StudentInputError("Invalid input: Could not parse '%s' as a formula" % raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %
cgi.escape(given)) cgi.escape(given))
except Exception as err: except Exception as err:
# traceback.print_exc() # traceback.print_exc()
log.debug('formularesponse: error %s in formula' % err) log.debug('formularesponse: error %s in formula', err)
raise StudentInputError("Invalid input: Could not parse '%s' as a formula" % raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %
cgi.escape(given)) cgi.escape(given))
# No errors in student's response--actually test for correctness
if not compare_with_tolerance(student_result, instructor_result, self.tolerance): if not compare_with_tolerance(student_result, instructor_result, self.tolerance):
return "incorrect" return "incorrect"
return "correct" return "correct"
......
<section id="formulaequationinput_${id}" class="formulaequationinput">
<div class="${reported_status}" id="status_${id}">
<input type="text" name="input_${id}" id="input_${id}"
data-input-id="${id}" value="${value|h}"
% if size:
size="${size}"
% endif
/>
<p class="status">${reported_status}</p>
<div id="input_${id}_preview" class="equation">
\[\]
<img src="/static/images/spinner.gif" class="loading"/>
</div>
<p id="answer_${id}" class="answer"></p>
</div>
<div class="script_placeholder" data-src="${previewer}"/>
</section>
...@@ -448,6 +448,32 @@ class TextlineTemplateTest(TemplateTestCase): ...@@ -448,6 +448,32 @@ class TextlineTemplateTest(TemplateTestCase):
self.assert_has_text(xml, xpath, self.context['msg']) self.assert_has_text(xml, xpath, self.context['msg'])
class FormulaEquationInputTemplateTest(TemplateTestCase):
"""
Test make template for `<formulaequationinput>`s.
"""
TEMPLATE_NAME = 'formulaequationinput.html'
def setUp(self):
self.context = {
'id': 2,
'value': 'PREFILLED_VALUE',
'status': 'unsubmitted',
'previewer': 'file.js',
'reported_status': 'REPORTED_STATUS',
}
super(FormulaEquationInputTemplateTest, self).setUp()
def test_no_size(self):
xml = self.render_to_xml(self.context)
self.assert_no_xpath(xml, "//input[@size]", self.context)
def test_size(self):
self.context['size'] = '40'
xml = self.render_to_xml(self.context)
self.assert_has_xpath(xml, "//input[@size='40']", self.context)
class AnnotationInputTemplateTest(TemplateTestCase): class AnnotationInputTemplateTest(TemplateTestCase):
""" """
Test mako template for `<annotationinput>` input. Test mako template for `<annotationinput>` input.
......
...@@ -72,7 +72,7 @@ def get_logger_config(log_dir, ...@@ -72,7 +72,7 @@ def get_logger_config(log_dir,
'level': console_loglevel, 'level': console_loglevel,
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': 'standard', 'formatter': 'standard',
'stream': sys.stdout, 'stream': sys.stderr,
}, },
'syslogger-remote': { 'syslogger-remote': {
'level': 'INFO', 'level': 'INFO',
......
...@@ -40,7 +40,7 @@ setup( ...@@ -40,7 +40,7 @@ setup(
"timelimit = xmodule.timelimit_module:TimeLimitDescriptor", "timelimit = xmodule.timelimit_module:TimeLimitDescriptor",
"vertical = xmodule.vertical_module:VerticalDescriptor", "vertical = xmodule.vertical_module:VerticalDescriptor",
"video = xmodule.video_module:VideoDescriptor", "video = xmodule.video_module:VideoDescriptor",
"videoalpha = xmodule.videoalpha_module:VideoAlphaDescriptor", "videoalpha = xmodule.video_module:VideoDescriptor",
"videodev = xmodule.backcompat_module:TranslateCustomTagDescriptor", "videodev = xmodule.backcompat_module:TranslateCustomTagDescriptor",
"videosequence = xmodule.seq_module:SequenceDescriptor", "videosequence = xmodule.seq_module:SequenceDescriptor",
"discussion = xmodule.discussion_module:DiscussionDescriptor", "discussion = xmodule.discussion_module:DiscussionDescriptor",
......
...@@ -32,7 +32,7 @@ $wrongans</tt> to see a hint.</p> ...@@ -32,7 +32,7 @@ $wrongans</tt> to see a hint.</p>
<formularesponse samples="x@-5:5#11" id="11" answer="$answer"> <formularesponse samples="x@-5:5#11" id="11" answer="$answer">
<responseparam description="Numerical Tolerance" type="tolerance" default="0.001" name="tol" /> <responseparam description="Numerical Tolerance" type="tolerance" default="0.001" name="tol" />
<text>y = <textline size="25" /></text> <text>y = <formulaequationinput size="25" /></text>
<hintgroup> <hintgroup>
<formulahint samples="x@-5:5#11" answer="$wrongans" name="inversegrad"> <formulahint samples="x@-5:5#11" answer="$wrongans" name="inversegrad">
</formulahint> </formulahint>
......
...@@ -13,8 +13,11 @@ import textwrap ...@@ -13,8 +13,11 @@ import textwrap
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
V1_SETTINGS_ATTRIBUTES = ["display_name", "max_attempts", "graded", "accept_file_upload", V1_SETTINGS_ATTRIBUTES = [
"skip_spelling_checks", "due", "graceperiod", "weight"] "display_name", "max_attempts", "graded", "accept_file_upload",
"skip_spelling_checks", "due", "graceperiod", "weight", "min_to_calibrate",
"max_to_calibrate", "peer_grader_count", "required_peer_grading",
]
V1_STUDENT_ATTRIBUTES = ["current_task_number", "task_states", "state", V1_STUDENT_ATTRIBUTES = ["current_task_number", "task_states", "state",
"student_attempts", "ready_to_reset"] "student_attempts", "ready_to_reset"]
...@@ -37,7 +40,7 @@ DEFAULT_DATA = textwrap.dedent("""\ ...@@ -37,7 +40,7 @@ DEFAULT_DATA = textwrap.dedent("""\
</p> </p>
<p> <p>
Write a persuasive essay to a newspaper reflecting your vies on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading. Write a persuasive essay to a newspaper reflecting your views on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading.
</p> </p>
</prompt> </prompt>
...@@ -242,6 +245,34 @@ class CombinedOpenEndedFields(object): ...@@ -242,6 +245,34 @@ class CombinedOpenEndedFields(object):
values={"min" : 0 , "step": ".1"}, values={"min" : 0 , "step": ".1"},
default=1 default=1
) )
min_to_calibrate = Integer(
display_name="Minimum Peer Grading Calibrations",
help="The minimum number of calibration essays each student will need to complete for peer grading.",
default=3,
scope=Scope.settings,
values={"min" : 1, "max" : 20, "step" : "1"}
)
max_to_calibrate = Integer(
display_name="Maximum Peer Grading Calibrations",
help="The maximum number of calibration essays each student will need to complete for peer grading.",
default=6,
scope=Scope.settings,
values={"min" : 1, "max" : 20, "step" : "1"}
)
peer_grader_count = Integer(
display_name="Peer Graders per Response",
help="The number of peers who will grade each submission.",
default=3,
scope=Scope.settings,
values={"min" : 1, "step" : "1", "max" : 5}
)
required_peer_grading = Integer(
display_name="Required Peer Grading",
help="The number of other students each student making a submission will have to grade.",
default=3,
scope=Scope.settings,
values={"min" : 1, "step" : "1", "max" : 5}
)
markdown = String( markdown = String(
help="Markdown source of this module", help="Markdown source of this module",
default=textwrap.dedent("""\ default=textwrap.dedent("""\
......
...@@ -172,7 +172,7 @@ section.problem { ...@@ -172,7 +172,7 @@ section.problem {
} }
} }
&.incorrect, &.ui-icon-close { &.incorrect, &.incomplete, &.ui-icon-close {
p.status { p.status {
@include inline-block(); @include inline-block();
width: 20px; width: 20px;
...@@ -213,6 +213,16 @@ section.problem { ...@@ -213,6 +213,16 @@ section.problem {
clear: both; clear: both;
margin-top: 3px; margin-top: 3px;
.MathJax_Display {
display: inline-block;
width: auto;
}
img.loading {
display: inline-block;
padding-left: 10px;
}
span { span {
margin-bottom: 0; margin-bottom: 0;
...@@ -264,7 +274,7 @@ section.problem { ...@@ -264,7 +274,7 @@ section.problem {
background: url('../images/partially-correct-icon.png') center center no-repeat; background: url('../images/partially-correct-icon.png') center center no-repeat;
} }
&.incorrect, &.ui-icon-close { &.incorrect, &.incomplete, &.ui-icon-close {
@include inline-block(); @include inline-block();
position: relative; position: relative;
top: 3px; top: 3px;
......
...@@ -10,11 +10,30 @@ div.video { ...@@ -10,11 +10,30 @@ div.video {
padding: 12px; padding: 12px;
border-radius: 5px; border-radius: 5px;
div.tc-wrapper {
position: relative;
@include clearfix;
}
article.video-wrapper { article.video-wrapper {
float: left; float: left;
margin-right: flex-gutter(9); margin-right: flex-gutter(9);
width: flex-grid(6, 9); width: flex-grid(6, 9);
background-color: black;
position: relative;
div.video-player-pre {
height: 50px;
background-color: black;
}
div.video-player-post {
height: 50px;
background-color: black;
}
section.video-player { section.video-player {
height: 0; height: 0;
overflow: hidden; overflow: hidden;
...@@ -52,10 +71,19 @@ div.video { ...@@ -52,10 +71,19 @@ div.video {
border-radius: 0; border-radius: 0;
border-top: 1px solid #000; border-top: 1px solid #000;
box-shadow: inset 0 1px 0 #eee, 0 1px 0 #555; box-shadow: inset 0 1px 0 #eee, 0 1px 0 #555;
height: 7px; position: absolute;
z-index: 1;
bottom: 100%;
left: 0;
right: 0;
height: 14px;
margin-left: -1px; margin-left: -1px;
margin-right: -1px; margin-right: -1px;
@include transition(height 2.0s ease-in-out 0s); -webkit-transition: -webkit-transform 0.7s ease-in-out;
-moz-transition: -moz-transform 0.7s ease-in-out;
-ms-transition: -ms-transform 0.7s ease-in-out;
transition: transform 0.7s ease-in-out;
@include transform(scaleY(0.5) translate3d(0, 50%, 0));
div.ui-widget-header { div.ui-widget-header {
background: #777; background: #777;
...@@ -66,14 +94,18 @@ div.video { ...@@ -66,14 +94,18 @@ div.video {
background: $pink url(../images/slider-handle.png) center center no-repeat; background: $pink url(../images/slider-handle.png) center center no-repeat;
background-size: 50%; background-size: 50%;
border: 1px solid darken($pink, 20%); border: 1px solid darken($pink, 20%);
border-radius: 15px; border-radius: 50%;
box-shadow: inset 0 1px 0 lighten($pink, 10%); box-shadow: inset 0 1px 0 lighten($pink, 10%);
cursor: pointer; cursor: pointer;
height: 15px; height: 20px;
margin-left: -7px; margin-left: 0;
top: -4px; top: 0;
@include transition(height 2.0s ease-in-out 0s, width 2.0s ease-in-out 0s); -webkit-transition: -webkit-transform 0.7s ease-in-out;
width: 15px; -moz-transition: -moz-transform 0.7s ease-in-out;
-ms-transition: -ms-transform 0.7s ease-in-out;
transition: transform 0.7s ease-in-out;
@include transform(scale(.7, 1.3) translate3d(-80%, -15%, 0));
width: 20px;
&:focus, &:hover { &:focus, &:hover {
background-color: lighten($pink, 10%); background-color: lighten($pink, 10%);
...@@ -101,7 +133,6 @@ div.video { ...@@ -101,7 +133,6 @@ div.video {
line-height: 46px; line-height: 46px;
padding: 0 lh(.75); padding: 0 lh(.75);
text-indent: -9999px; text-indent: -9999px;
@include transition(background-color 0.75s linear 0s, opacity 0.75s linear 0s);
width: 14px; width: 14px;
background: url('../images/vcr.png') 15px 15px no-repeat; background: url('../images/vcr.png') 15px 15px no-repeat;
outline: 0; outline: 0;
...@@ -118,7 +149,7 @@ div.video { ...@@ -118,7 +149,7 @@ div.video {
&.play { &.play {
background-position: 17px -114px; background-position: 17px -114px;
&:hover { &:hover, &:focus {
background-color: #444; background-color: #444;
} }
} }
...@@ -126,7 +157,7 @@ div.video { ...@@ -126,7 +157,7 @@ div.video {
&.pause { &.pause {
background-position: 16px -50px; background-position: 16px -50px;
&:hover { &:hover, &:focus {
background-color: #444; background-color: #444;
} }
} }
...@@ -213,7 +244,7 @@ div.video { ...@@ -213,7 +244,7 @@ div.video {
// fix for now // fix for now
ol.video_speeds { ol.video_speeds {
box-shadow: inset 1px 0 0 #555, 0 3px 0 #444; box-shadow: inset 1px 0 0 #555, 0 4px 0 #444;
@include transition(none); @include transition(none);
background-color: #444; background-color: #444;
border: 1px solid #000; border: 1px solid #000;
...@@ -221,7 +252,7 @@ div.video { ...@@ -221,7 +252,7 @@ div.video {
display: none; display: none;
opacity: 0.0; opacity: 0.0;
position: absolute; position: absolute;
width: 133px; width: 131px;
z-index: 10; z-index: 10;
li { li {
...@@ -268,12 +299,15 @@ div.video { ...@@ -268,12 +299,15 @@ div.video {
&.muted { &.muted {
&>a { &>a {
background: url('../images/mute.png') 10px center no-repeat; background-image: url('../images/mute.png');
} }
} }
> a { > a {
background: url('../images/volume.png') 10px center no-repeat; background-image: url('../images/volume.png');
background-position: 10px center;
background-repeat: no-repeat;
border-right: 1px solid #000; border-right: 1px solid #000;
box-shadow: 1px 0 0 #555, inset 1px 0 0 #555; box-shadow: 1px 0 0 #555, inset 1px 0 0 #555;
@include clearfix(); @include clearfix();
...@@ -350,7 +384,7 @@ div.video { ...@@ -350,7 +384,7 @@ div.video {
@include transition(none); @include transition(none);
width: 30px; width: 30px;
&:hover { &:hover, &:active, &:focus {
background-color: #444; background-color: #444;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
...@@ -362,7 +396,7 @@ div.video { ...@@ -362,7 +396,7 @@ div.video {
border-right: 1px solid #000; border-right: 1px solid #000;
box-shadow: 1px 0 0 #555, inset 1px 0 0 #555; box-shadow: 1px 0 0 #555, inset 1px 0 0 #555;
color: #797979; color: #797979;
display: block; display: none;
float: left; float: left;
line-height: 46px; //height of play pause buttons line-height: 46px; //height of play pause buttons
margin-left: 0; margin-left: 0;
...@@ -371,7 +405,7 @@ div.video { ...@@ -371,7 +405,7 @@ div.video {
@include transition(none); @include transition(none);
width: 30px; width: 30px;
&:hover { &:hover, &:focus {
background-color: #444; background-color: #444;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
...@@ -387,8 +421,6 @@ div.video { ...@@ -387,8 +421,6 @@ div.video {
a.hide-subtitles { a.hide-subtitles {
background: url('../images/cc.png') center no-repeat; background: url('../images/cc.png') center no-repeat;
color: #797979;
display: block;
float: left; float: left;
font-weight: 800; font-weight: 800;
line-height: 46px; //height of play pause buttons line-height: 46px; //height of play pause buttons
...@@ -401,7 +433,7 @@ div.video { ...@@ -401,7 +433,7 @@ div.video {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
width: 30px; width: 30px;
&:hover { &:hover, &:focus {
background-color: #444; background-color: #444;
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
...@@ -410,6 +442,8 @@ div.video { ...@@ -410,6 +442,8 @@ div.video {
&.off { &.off {
opacity: 0.7; opacity: 0.7;
} }
color: #797979;
} }
} }
} }
...@@ -420,15 +454,10 @@ div.video { ...@@ -420,15 +454,10 @@ div.video {
} }
div.slider { div.slider {
height: 14px; @include transform(scaleY(1) translate3d(0, 0, 0));
margin-top: -7px;
a.ui-slider-handle { a.ui-slider-handle {
border-radius: 20px; @include transform(scale(1) translate3d(-50%, -15%, 0));
height: 20px;
margin-left: -10px;
top: -4px;
width: 20px;
} }
} }
} }
...@@ -471,22 +500,47 @@ div.video { ...@@ -471,22 +500,47 @@ div.video {
article.video-wrapper { article.video-wrapper {
width: flex-grid(9,9); width: flex-grid(9,9);
background-color: inherit;
}
article.video-wrapper section.video-controls.html5 {
bottom: 0px;
left: 0px;
right: 0px;
position: absolute;
z-index: 1;
}
article.video-wrapper div.video-player-pre, article.video-wrapper div.video-player-post {
height: 0px;
} }
ol.subtitles { ol.subtitles {
width: 0; width: 0;
height: 0; height: 0;
}
ol.subtitles.html5 {
background-color: rgba(243, 243, 243, 0.8);
height: 100%;
position: absolute;
right: 0;
bottom: 0;
top: 0;
width: 275px;
padding: 0 20px;
z-index: 0;
} }
} }
&.fullscreen { &.video-fullscreen {
background: rgba(#000, .95); background: rgba(#000, .95);
border: 0; border: 0;
bottom: 0; bottom: 0;
height: 100%; height: 100%;
left: 0; left: 0;
margin: 0; margin: 0;
overflow: hidden;
padding: 0; padding: 0;
position: fixed; position: fixed;
top: 0; top: 0;
...@@ -501,12 +555,22 @@ div.video { ...@@ -501,12 +555,22 @@ div.video {
} }
} }
article.video-wrapper div.video-player-pre, article.video-wrapper div.video-player-post {
height: 0px;
}
article.video-wrapper {
position: static;
}
div.tc-wrapper { div.tc-wrapper {
@include clearfix; @include clearfix;
display: table; display: table;
width: 100%; width: 100%;
height: 100%; height: 100%;
position: static;
article.video-wrapper { article.video-wrapper {
width: 100%; width: 100%;
display: table-cell; display: table-cell;
...@@ -536,7 +600,7 @@ div.video { ...@@ -536,7 +600,7 @@ div.video {
background: rgba(#000, .8); background: rgba(#000, .8);
bottom: 0; bottom: 0;
height: 100%; height: 100%;
max-height: 100%; max-height: 460px;
max-width: flex-grid(3); max-width: flex-grid(3);
padding: lh(); padding: lh();
position: fixed; position: fixed;
......
...@@ -82,6 +82,9 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?) ...@@ -82,6 +82,9 @@ TIMEDELTA_REGEX = re.compile(r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?)
class Timedelta(ModelType): class Timedelta(ModelType):
# Timedeltas are immutable, see http://docs.python.org/2/library/datetime.html#available-types
MUTABLE = False
def from_json(self, time_str): def from_json(self, time_str):
""" """
time_str: A string with the following components: time_str: A string with the following components:
......
<div class="course-content"> <div class="course-content">
<div id="video_example"> <div id="video_example">
<div id="example"> <div id="example">
<div id="video_id" class="video" <div
data-youtube-id-0-75="7tqY6eQzVhE" id="video_id"
data-youtube-id-1-0="cogebirgzzM" class="video"
data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM"
data-show-captions="true" data-show-captions="true"
data-start="" data-start=""
data-end="" data-end=""
data-caption-asset-path="/static/subs/"> data-caption-asset-path="/static/subs/"
data-autoplay="False"
>
<div class="tc-wrapper"> <div class="tc-wrapper">
<article class="video-wrapper"> <article class="video-wrapper">
<div class="video-player-pre"></div>
<section class="video-player"> <section class="video-player">
<div id="id"></div> <div id="id"></div>
</section> </section>
<section class="video-controls"></section> <div class="video-player-post"></div>
<section class="video-controls">
<div class="slider"></div>
<div>
<ul class="vcr">
<li><a class="video_control" href="#" title="Play"></a></li>
<li><div class="vidtime">0:00 / 0:00</div></li>
</ul>
<div class="secondary-controls">
<div class="speeds">
<a href="#">
<h3>Speed</h3>
<p class="active"></p>
</a>
<ol class="video_speeds"></ol>
</div>
<div class="volume">
<a href="#"></a>
<div class="volume-slider-container">
<div class="volume-slider"></div>
</div>
</div>
<a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a>
<a href="#" class="quality_control" title="HD">HD</a>
<a href="#" class="hide-subtitles" title="Turn off captions">Captions</a>
</div>
</div>
</section>
</article> </article>
<ol class="subtitles"><li></li></ol>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div id="example"> <div id="example">
<div <div
id="video_id" id="video_id"
class="videoalpha" class="video"
data-show-captions="true" data-show-captions="true"
data-start="" data-start=""
data-end="" data-end=""
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div id="example"> <div id="example">
<div <div
id="video_id" id="video_id"
class="videoalpha" class="video"
data-show-captions="true" data-show-captions="true"
data-start="" data-start=""
data-end="" data-end=""
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<div id="example"> <div id="example">
<div <div
id="video_id" id="video_id"
class="videoalpha" class="video"
data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM" data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM"
data-show-captions="false" data-show-captions="false"
data-start="" data-start=""
......
<div class="course-content">
<div id="video_example">
<div id="example">
<div
id="video_id"
class="videoalpha"
data-streams="0.75:7tqY6eQzVhE,1.0:cogebirgzzM"
data-show-captions="true"
data-start=""
data-end=""
data-caption-asset-path="/static/subs/"
data-autoplay="False"
>
<div class="tc-wrapper">
<article class="video-wrapper">
<div class="video-player-pre"></div>
<section class="video-player">
<div id="id"></div>
</section>
<div class="video-player-post"></div>
<section class="video-controls">
<div class="slider"></div>
<div>
<ul class="vcr">
<li><a class="video_control" href="#" title="Play"></a></li>
<li><div class="vidtime">0:00 / 0:00</div></li>
</ul>
<div class="secondary-controls">
<div class="speeds">
<a href="#">
<h3>Speed</h3>
<p class="active"></p>
</a>
<ol class="video_speeds"></ol>
</div>
<div class="volume">
<a href="#"></a>
<div class="volume-slider-container">
<div class="volume-slider"></div>
</div>
</div>
<a href="#" class="add-fullscreen" title="Fill browser">Fill Browser</a>
<a href="#" class="quality_control" title="HD">HD</a>
<a href="#" class="hide-subtitles" title="Turn off captions">Captions</a>
</div>
</div>
</section>
</article>
<ol class="subtitles"><li></li></ol>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
*.js *.js
# Tests for videoalpha are written in pure JavaScript. # Tests for video are written in pure JavaScript.
!videoalpha/*.js !video/*.js
...@@ -111,34 +111,18 @@ jasmine.stubYoutubePlayer = -> ...@@ -111,34 +111,18 @@ jasmine.stubYoutubePlayer = ->
obj['getAvailablePlaybackRates'] = jasmine.createSpy('getAvailablePlaybackRates').andReturn [0.75, 1.0, 1.25, 1.5] obj['getAvailablePlaybackRates'] = jasmine.createSpy('getAvailablePlaybackRates').andReturn [0.75, 1.0, 1.25, 1.5]
obj obj
jasmine.stubVideoPlayer = (context, enableParts, createPlayer=true) -> jasmine.stubVideoPlayer = (context, enableParts, html5=false) ->
enableParts = [enableParts] unless $.isArray(enableParts)
suite = context.suite
currentPartName = suite.description while suite = suite.parentSuite
enableParts.push currentPartName
loadFixtures 'video.html'
jasmine.stubRequests()
YT.Player = undefined
videosDefinition = '0.75:7tqY6eQzVhE,1.0:cogebirgzzM'
context.video = new Video '#example', videosDefinition
jasmine.stubYoutubePlayer()
if createPlayer
return new VideoPlayer(video: context.video)
jasmine.stubVideoPlayerAlpha = (context, enableParts, html5=false) ->
console.log('stubVideoPlayerAlpha called')
suite = context.suite suite = context.suite
currentPartName = suite.description while suite = suite.parentSuite currentPartName = suite.description while suite = suite.parentSuite
if html5 == false if html5 == false
loadFixtures 'videoalpha.html' loadFixtures 'video.html'
else else
loadFixtures 'videoalpha_html5.html' loadFixtures 'video_html5.html'
jasmine.stubRequests() jasmine.stubRequests()
YT.Player = undefined YT.Player = undefined
window.OldVideoPlayerAlpha = undefined window.OldVideoPlayer = undefined
jasmine.stubYoutubePlayer() jasmine.stubYoutubePlayer()
return new VideoAlpha '#example', '.75:7tqY6eQzVhE,1.0:cogebirgzzM' return new Video '#example', '.75:7tqY6eQzVhE,1.0:cogebirgzzM'
# Stub jQuery.cookie # Stub jQuery.cookie
......
...@@ -121,18 +121,18 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -121,18 +121,18 @@ describe 'MarkdownEditingDescriptor', ->
<p>Enter the numerical value of Pi:</p> <p>Enter the numerical value of Pi:</p>
<numericalresponse answer="3.14159"> <numericalresponse answer="3.14159">
<responseparam type="tolerance" default=".02" /> <responseparam type="tolerance" default=".02" />
<textline /> <formulaequationinput />
</numericalresponse> </numericalresponse>
<p>Enter the approximate value of 502*9:</p> <p>Enter the approximate value of 502*9:</p>
<numericalresponse answer="4518"> <numericalresponse answer="4518">
<responseparam type="tolerance" default="15%" /> <responseparam type="tolerance" default="15%" />
<textline /> <formulaequationinput />
</numericalresponse> </numericalresponse>
<p>Enter the number of fingers on a human hand:</p> <p>Enter the number of fingers on a human hand:</p>
<numericalresponse answer="5"> <numericalresponse answer="5">
<textline /> <formulaequationinput />
</numericalresponse> </numericalresponse>
<solution> <solution>
...@@ -157,7 +157,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -157,7 +157,7 @@ describe 'MarkdownEditingDescriptor', ->
<p>Enter 0 with a tolerance:</p> <p>Enter 0 with a tolerance:</p>
<numericalresponse answer="0"> <numericalresponse answer="0">
<responseparam type="tolerance" default=".02" /> <responseparam type="tolerance" default=".02" />
<textline /> <formulaequationinput />
</numericalresponse> </numericalresponse>
......
describe 'VideoControl', ->
beforeEach ->
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false
loadFixtures 'video.html'
$('.video-controls').html ''
describe 'constructor', ->
it 'render the video controls', ->
@control = new window.VideoControl(el: $('.video-controls'))
expect($('.video-controls')).toContain
['.slider', 'ul.vcr', 'a.play', '.vidtime', '.add-fullscreen'].join(',')
expect($('.video-controls').find('.vidtime')).toHaveText '0:00 / 0:00'
it 'bind the playback button', ->
@control = new window.VideoControl(el: $('.video-controls'))
expect($('.video_control')).toHandleWith 'click', @control.togglePlayback
describe 'when on a touch based device', ->
beforeEach ->
window.onTouchBasedDevice.andReturn true
@control = new window.VideoControl(el: $('.video-controls'))
it 'does not add the play class to video control', ->
expect($('.video_control')).not.toHaveClass 'play'
expect($('.video_control')).not.toHaveHtml 'Play'
describe 'when on a non-touch based device', ->
beforeEach ->
@control = new window.VideoControl(el: $('.video-controls'))
it 'add the play class to video control', ->
expect($('.video_control')).toHaveClass 'play'
expect($('.video_control')).toHaveHtml 'Play'
describe 'play', ->
beforeEach ->
@control = new window.VideoControl(el: $('.video-controls'))
@control.play()
it 'switch playback button to play state', ->
expect($('.video_control')).not.toHaveClass 'play'
expect($('.video_control')).toHaveClass 'pause'
expect($('.video_control')).toHaveHtml 'Pause'
describe 'pause', ->
beforeEach ->
@control = new window.VideoControl(el: $('.video-controls'))
@control.pause()
it 'switch playback button to pause state', ->
expect($('.video_control')).not.toHaveClass 'pause'
expect($('.video_control')).toHaveClass 'play'
expect($('.video_control')).toHaveHtml 'Play'
describe 'togglePlayback', ->
beforeEach ->
@control = new window.VideoControl(el: $('.video-controls'))
describe 'when the control does not have play or pause class', ->
beforeEach ->
$('.video_control').removeClass('play').removeClass('pause')
describe 'when the video is playing', ->
beforeEach ->
$('.video_control').addClass('play')
spyOnEvent @control, 'pause'
@control.togglePlayback jQuery.Event('click')
it 'does not trigger the pause event', ->
expect('pause').not.toHaveBeenTriggeredOn @control
describe 'when the video is paused', ->
beforeEach ->
$('.video_control').addClass('pause')
spyOnEvent @control, 'play'
@control.togglePlayback jQuery.Event('click')
it 'does not trigger the play event', ->
expect('play').not.toHaveBeenTriggeredOn @control
describe 'when the video is playing', ->
beforeEach ->
spyOnEvent @control, 'pause'
$('.video_control').addClass 'pause'
@control.togglePlayback jQuery.Event('click')
it 'trigger the pause event', ->
expect('pause').toHaveBeenTriggeredOn @control
describe 'when the video is paused', ->
beforeEach ->
spyOnEvent @control, 'play'
$('.video_control').addClass 'play'
@control.togglePlayback jQuery.Event('click')
it 'trigger the play event', ->
expect('play').toHaveBeenTriggeredOn @control
describe 'VideoProgressSlider', ->
beforeEach ->
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false
describe 'constructor', ->
describe 'on a non-touch based device', ->
beforeEach ->
spyOn($.fn, 'slider').andCallThrough()
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
it 'build the slider', ->
expect(@progressSlider.slider).toBe '.slider'
expect($.fn.slider).toHaveBeenCalledWith
range: 'min'
change: @progressSlider.onChange
slide: @progressSlider.onSlide
stop: @progressSlider.onStop
it 'build the seek handle', ->
expect(@progressSlider.handle).toBe '.slider .ui-slider-handle'
expect($.fn.qtip).toHaveBeenCalledWith
content: "0:00"
position:
my: 'bottom center'
at: 'top center'
container: @progressSlider.handle
hide:
delay: 700
style:
classes: 'ui-tooltip-slider'
widget: true
describe 'on a touch-based device', ->
beforeEach ->
window.onTouchBasedDevice.andReturn true
spyOn($.fn, 'slider').andCallThrough()
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
it 'does not build the slider', ->
expect(@progressSlider.slider).toBeUndefined
expect($.fn.slider).not.toHaveBeenCalled()
describe 'play', ->
beforeEach ->
spyOn(VideoProgressSlider.prototype, 'buildSlider').andCallThrough()
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
describe 'when the slider was already built', ->
beforeEach ->
@progressSlider.play()
it 'does not build the slider', ->
expect(@progressSlider.buildSlider.calls.length).toEqual 1
describe 'when the slider was not already built', ->
beforeEach ->
spyOn($.fn, 'slider').andCallThrough()
@progressSlider.slider = null
@progressSlider.play()
it 'build the slider', ->
expect(@progressSlider.slider).toBe '.slider'
expect($.fn.slider).toHaveBeenCalledWith
range: 'min'
change: @progressSlider.onChange
slide: @progressSlider.onSlide
stop: @progressSlider.onStop
it 'build the seek handle', ->
expect(@progressSlider.handle).toBe '.ui-slider-handle'
expect($.fn.qtip).toHaveBeenCalledWith
content: "0:00"
position:
my: 'bottom center'
at: 'top center'
container: @progressSlider.handle
hide:
delay: 700
style:
classes: 'ui-tooltip-slider'
widget: true
describe 'updatePlayTime', ->
beforeEach ->
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
describe 'when frozen', ->
beforeEach ->
spyOn($.fn, 'slider').andCallThrough()
@progressSlider.frozen = true
@progressSlider.updatePlayTime 20, 120
it 'does not update the slider', ->
expect($.fn.slider).not.toHaveBeenCalled()
describe 'when not frozen', ->
beforeEach ->
spyOn($.fn, 'slider').andCallThrough()
@progressSlider.frozen = false
@progressSlider.updatePlayTime 20, 120
it 'update the max value of the slider', ->
expect($.fn.slider).toHaveBeenCalledWith 'option', 'max', 120
it 'update current value of the slider', ->
expect($.fn.slider).toHaveBeenCalledWith 'value', 20
describe 'onSlide', ->
beforeEach ->
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
@time = null
$(@progressSlider).bind 'seek', (event, time) => @time = time
spyOnEvent @progressSlider, 'seek'
@progressSlider.onSlide {}, value: 20
it 'freeze the slider', ->
expect(@progressSlider.frozen).toBeTruthy()
it 'update the tooltip', ->
expect($.fn.qtip).toHaveBeenCalled()
it 'trigger seek event', ->
expect('seek').toHaveBeenTriggeredOn @progressSlider
expect(@time).toEqual 20
describe 'onChange', ->
beforeEach ->
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
@progressSlider.onChange {}, value: 20
it 'update the tooltip', ->
expect($.fn.qtip).toHaveBeenCalled()
describe 'onStop', ->
beforeEach ->
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
@time = null
$(@progressSlider).bind 'seek', (event, time) => @time = time
spyOnEvent @progressSlider, 'seek'
@progressSlider.onStop {}, value: 20
it 'freeze the slider', ->
expect(@progressSlider.frozen).toBeTruthy()
it 'trigger seek event', ->
expect('seek').toHaveBeenTriggeredOn @progressSlider
expect(@time).toEqual 20
it 'set timeout to unfreeze the slider', ->
expect(window.setTimeout).toHaveBeenCalledWith jasmine.any(Function), 200
window.setTimeout.mostRecentCall.args[0]()
expect(@progressSlider.frozen).toBeFalsy()
describe 'updateTooltip', ->
beforeEach ->
@player = jasmine.stubVideoPlayer @
@progressSlider = @player.progressSlider
@progressSlider.updateTooltip 90
it 'set the tooltip value', ->
expect($.fn.qtip).toHaveBeenCalledWith 'option', 'content.text', '1:30'
describe 'VideoSpeedControl', ->
beforeEach ->
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn false
jasmine.stubVideoPlayer @
$('.speeds').remove()
describe 'constructor', ->
describe 'always', ->
beforeEach ->
@speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
it 'add the video speed control to player', ->
secondaryControls = $('.secondary-controls')
li = secondaryControls.find('.video_speeds li')
expect(secondaryControls).toContain '.speeds'
expect(secondaryControls).toContain '.video_speeds'
expect(secondaryControls.find('p.active').text()).toBe '1.0x'
expect(li.filter('.active')).toHaveData 'speed', @speedControl.currentSpeed
expect(li.length).toBe @speedControl.speeds.length
$.each li.toArray().reverse(), (index, link) =>
expect($(link)).toHaveData 'speed', @speedControl.speeds[index]
expect($(link).find('a').text()).toBe @speedControl.speeds[index] + 'x'
it 'bind to change video speed link', ->
expect($('.video_speeds a')).toHandleWith 'click', @speedControl.changeVideoSpeed
describe 'when running on touch based device', ->
beforeEach ->
window.onTouchBasedDevice.andReturn true
$('.speeds').removeClass 'open'
@speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
it 'open the speed toggle on click', ->
$('.speeds').click()
expect($('.speeds')).toHaveClass 'open'
$('.speeds').click()
expect($('.speeds')).not.toHaveClass 'open'
describe 'when running on non-touch based device', ->
beforeEach ->
$('.speeds').removeClass 'open'
@speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
it 'open the speed toggle on hover', ->
$('.speeds').mouseenter()
expect($('.speeds')).toHaveClass 'open'
$('.speeds').mouseleave()
expect($('.speeds')).not.toHaveClass 'open'
it 'close the speed toggle on mouse out', ->
$('.speeds').mouseenter().mouseleave()
expect($('.speeds')).not.toHaveClass 'open'
it 'close the speed toggle on click', ->
$('.speeds').mouseenter().click()
expect($('.speeds')).not.toHaveClass 'open'
describe 'changeVideoSpeed', ->
beforeEach ->
@speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
@video.setSpeed '1.0'
describe 'when new speed is the same', ->
beforeEach ->
spyOnEvent @speedControl, 'speedChange'
$('li[data-speed="1.0"] a').click()
it 'does not trigger speedChange event', ->
expect('speedChange').not.toHaveBeenTriggeredOn @speedControl
describe 'when new speed is not the same', ->
beforeEach ->
@newSpeed = null
$(@speedControl).bind 'speedChange', (event, newSpeed) => @newSpeed = newSpeed
spyOnEvent @speedControl, 'speedChange'
$('li[data-speed="0.75"] a').click()
it 'trigger speedChange event', ->
expect('speedChange').toHaveBeenTriggeredOn @speedControl
expect(@newSpeed).toEqual 0.75
describe 'onSpeedChange', ->
beforeEach ->
@speedControl = new VideoSpeedControl el: $('.secondary-controls'), speeds: @video.speeds, currentSpeed: '1.0'
$('li[data-speed="1.0"] a').addClass 'active'
@speedControl.setSpeed '0.75'
it 'set the new speed as active', ->
expect($('.video_speeds li[data-speed="1.0"]')).not.toHaveClass 'active'
expect($('.video_speeds li[data-speed="0.75"]')).toHaveClass 'active'
expect($('.speeds p.active')).toHaveHtml '0.75x'
describe 'VideoVolumeControl', ->
beforeEach ->
jasmine.stubVideoPlayer @
$('.volume').remove()
describe 'constructor', ->
beforeEach ->
spyOn($.fn, 'slider')
@volumeControl = new VideoVolumeControl el: $('.secondary-controls')
it 'initialize currentVolume to 100', ->
expect(@volumeControl.currentVolume).toEqual 100
it 'render the volume control', ->
expect($('.secondary-controls').html()).toContain """
<div class="volume">
<a href="#"></a>
<div class="volume-slider-container">
<div class="volume-slider"></div>
</div>
</div>
"""
it 'create the slider', ->
expect($.fn.slider).toHaveBeenCalledWith
orientation: "vertical"
range: "min"
min: 0
max: 100
value: 100
change: @volumeControl.onChange
slide: @volumeControl.onChange
it 'bind the volume control', ->
expect($('.volume>a')).toHandleWith 'click', @volumeControl.toggleMute
expect($('.volume')).not.toHaveClass 'open'
$('.volume').mouseenter()
expect($('.volume')).toHaveClass 'open'
$('.volume').mouseleave()
expect($('.volume')).not.toHaveClass 'open'
describe 'onChange', ->
beforeEach ->
spyOnEvent @volumeControl, 'volumeChange'
@newVolume = undefined
@volumeControl = new VideoVolumeControl el: $('.secondary-controls')
$(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume
describe 'when the new volume is more than 0', ->
beforeEach ->
@volumeControl.onChange undefined, value: 60
it 'set the player volume', ->
expect(@newVolume).toEqual 60
it 'remote muted class', ->
expect($('.volume')).not.toHaveClass 'muted'
describe 'when the new volume is 0', ->
beforeEach ->
@volumeControl.onChange undefined, value: 0
it 'set the player volume', ->
expect(@newVolume).toEqual 0
it 'add muted class', ->
expect($('.volume')).toHaveClass 'muted'
describe 'toggleMute', ->
beforeEach ->
@newVolume = undefined
@volumeControl = new VideoVolumeControl el: $('.secondary-controls')
$(@volumeControl).bind 'volumeChange', (event, volume) => @newVolume = volume
describe 'when the current volume is more than 0', ->
beforeEach ->
@volumeControl.currentVolume = 60
@volumeControl.toggleMute()
it 'save the previous volume', ->
expect(@volumeControl.previousVolume).toEqual 60
it 'set the player volume', ->
expect(@newVolume).toEqual 0
describe 'when the current volume is 0', ->
beforeEach ->
@volumeControl.currentVolume = 0
@volumeControl.previousVolume = 60
@volumeControl.toggleMute()
it 'set the player volume to previous volume', ->
expect(@newVolume).toEqual 60
describe 'Video', ->
metadata = undefined
beforeEach ->
loadFixtures 'video.html'
jasmine.stubRequests()
@['7tqY6eQzVhE'] = '7tqY6eQzVhE'
@['cogebirgzzM'] = 'cogebirgzzM'
metadata =
'7tqY6eQzVhE':
id: @['7tqY6eQzVhE']
duration: 300
'cogebirgzzM':
id: @['cogebirgzzM']
duration: 200
afterEach ->
window.player = undefined
window.onYouTubePlayerAPIReady = undefined
describe 'constructor', ->
beforeEach ->
@stubVideoPlayer = jasmine.createSpy('VideoPlayer')
$.cookie.andReturn '0.75'
window.player = undefined
describe 'by default', ->
beforeEach ->
spyOn(window.Video.prototype, 'fetchMetadata').andCallFake ->
@metadata = metadata
@video = new Video '#example'
it 'reset the current video player', ->
expect(window.player).toBeNull()
it 'set the elements', ->
expect(@video.el).toBe '#video_id'
it 'parse the videos', ->
expect(@video.videos).toEqual
'0.75': @['7tqY6eQzVhE']
'1.0': @['cogebirgzzM']
it 'fetch the video metadata', ->
expect(@video.fetchMetadata).toHaveBeenCalled
expect(@video.metadata).toEqual metadata
it 'parse available video speeds', ->
expect(@video.speeds).toEqual ['0.75', '1.0']
it 'set current video speed via cookie', ->
expect(@video.speed).toEqual '0.75'
it 'store a reference for this video player in the element', ->
expect($('.video').data('video')).toEqual @video
describe 'when the Youtube API is already available', ->
beforeEach ->
@originalYT = window.YT
window.YT = { Player: true }
spyOn(window, 'VideoPlayer').andReturn(@stubVideoPlayer)
@video = new Video '#example'
afterEach ->
window.YT = @originalYT
it 'create the Video Player', ->
expect(window.VideoPlayer).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayer
describe 'when the Youtube API is not ready', ->
beforeEach ->
@originalYT = window.YT
window.YT = {}
@video = new Video '#example'
afterEach ->
window.YT = @originalYT
it 'set the callback on the window object', ->
expect(window.onYouTubePlayerAPIReady).toEqual jasmine.any(Function)
describe 'when the Youtube API becoming ready', ->
beforeEach ->
@originalYT = window.YT
window.YT = {}
spyOn(window, 'VideoPlayer').andReturn(@stubVideoPlayer)
@video = new Video '#example'
window.onYouTubePlayerAPIReady()
afterEach ->
window.YT = @originalYT
it 'create the Video Player for all video elements', ->
expect(window.VideoPlayer).toHaveBeenCalledWith(video: @video)
expect(@video.player).toEqual @stubVideoPlayer
describe 'youtubeId', ->
beforeEach ->
$.cookie.andReturn '1.0'
@video = new Video '#example'
describe 'with speed', ->
it 'return the video id for given speed', ->
expect(@video.youtubeId('0.75')).toEqual @['7tqY6eQzVhE']
expect(@video.youtubeId('1.0')).toEqual @['cogebirgzzM']
describe 'without speed', ->
it 'return the video id for current speed', ->
expect(@video.youtubeId()).toEqual @cogebirgzzM
describe 'setSpeed', ->
beforeEach ->
@video = new Video '#example'
describe 'when new speed is available', ->
beforeEach ->
@video.setSpeed '0.75'
it 'set new speed', ->
expect(@video.speed).toEqual '0.75'
it 'save setting for new speed', ->
expect($.cookie).toHaveBeenCalledWith 'video_speed', '0.75', expires: 3650, path: '/'
describe 'when new speed is not available', ->
beforeEach ->
@video.setSpeed '1.75'
it 'set speed to 1.0x', ->
expect(@video.speed).toEqual '1.0'
describe 'getDuration', ->
beforeEach ->
@video = new Video '#example'
it 'return duration for current video', ->
expect(@video.getDuration()).toEqual 200
describe 'log', ->
beforeEach ->
@video = new Video '#example'
@video.setSpeed '1.0'
spyOn Logger, 'log'
@video.player = { currentTime: 25 }
@video.log 'someEvent'
it 'call the logger with valid parameters', ->
expect(Logger.log).toHaveBeenCalledWith 'someEvent',
id: 'id'
code: @cogebirgzzM
currentTime: 25
speed: '1.0'
(function () { (function () {
xdescribe('VideoAlpha', function () { xdescribe('Video', function () {
var oldOTBD; var oldOTBD;
beforeEach(function () { beforeEach(function () {
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
}); });
afterEach(function () { afterEach(function () {
window.OldVideoPlayerAlpha = undefined; window.OldVideoPlayer = undefined;
window.onYouTubePlayerAPIReady = undefined; window.onYouTubePlayerAPIReady = undefined;
window.onHTML5PlayerAPIReady = undefined; window.onHTML5PlayerAPIReady = undefined;
$('source').remove(); $('source').remove();
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
describe('constructor', function () { describe('constructor', function () {
describe('YT', function () { describe('YT', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha.html'); loadFixtures('video.html');
$.cookie.andReturn('0.75'); $.cookie.andReturn('0.75');
}); });
describe('by default', function () { describe('by default', function () {
beforeEach(function () { beforeEach(function () {
this.state = new window.VideoAlpha('#example'); this.state = new window.Video('#example');
}); });
it('check videoType', function () { it('check videoType', function () {
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
}); });
it('reset the current video player', function () { it('reset the current video player', function () {
expect(window.OldVideoPlayerAlpha).toBeUndefined(); expect(window.OldVideoPlayer).toBeUndefined();
}); });
it('set the elements', function () { it('set the elements', function () {
...@@ -64,14 +64,14 @@ ...@@ -64,14 +64,14 @@
var state; var state;
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha_html5.html'); loadFixtures('video_html5.html');
this.stubVideoPlayerAlpha = jasmine.createSpy('VideoPlayerAlpha'); this.stubVideoPlayer = jasmine.createSpy('VideoPlayer');
$.cookie.andReturn('0.75'); $.cookie.andReturn('0.75');
}); });
describe('by default', function () { describe('by default', function () {
beforeEach(function () { beforeEach(function () {
state = new window.VideoAlpha('#example'); state = new window.Video('#example');
}); });
afterEach(function () { afterEach(function () {
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
}); });
it('reset the current video player', function () { it('reset the current video player', function () {
expect(window.OldVideoPlayerAlpha).toBeUndefined(); expect(window.OldVideoPlayer).toBeUndefined();
}); });
it('set the elements', function () { it('set the elements', function () {
...@@ -104,8 +104,8 @@ ...@@ -104,8 +104,8 @@
it('parse the videos if subtitles do not exist', function () { it('parse the videos if subtitles do not exist', function () {
var sub = ''; var sub = '';
$('#example').find('.videoalpha').data('sub', ''); $('#example').find('.video').data('sub', '');
state = new window.VideoAlpha('#example'); state = new window.Video('#example');
expect(state.videos).toEqual({ expect(state.videos).toEqual({
'0.75': sub, '0.75': sub,
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
// is required. // is required.
describe('HTML5 API is available', function () { describe('HTML5 API is available', function () {
beforeEach(function () { beforeEach(function () {
state = new VideoAlpha('#example'); state = new Video('#example');
}); });
afterEach(function () { afterEach(function () {
...@@ -158,9 +158,9 @@ ...@@ -158,9 +158,9 @@
describe('youtubeId', function () { describe('youtubeId', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha.html'); loadFixtures('video.html');
$.cookie.andReturn('1.0'); $.cookie.andReturn('1.0');
state = new VideoAlpha('#example'); state = new Video('#example');
}); });
describe('with speed', function () { describe('with speed', function () {
...@@ -180,13 +180,13 @@ ...@@ -180,13 +180,13 @@
describe('setSpeed', function () { describe('setSpeed', function () {
describe('YT', function () { describe('YT', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha.html'); loadFixtures('video.html');
state = new VideoAlpha('#example'); state = new Video('#example');
}); });
describe('when new speed is available', function () { describe('when new speed is available', function () {
beforeEach(function () { beforeEach(function () {
state.setSpeed('0.75'); state.setSpeed('0.75', true);
}); });
it('set new speed', function () { it('set new speed', function () {
...@@ -214,13 +214,13 @@ ...@@ -214,13 +214,13 @@
describe('HTML5', function () { describe('HTML5', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha_html5.html'); loadFixtures('video_html5.html');
state = new VideoAlpha('#example'); state = new Video('#example');
}); });
describe('when new speed is available', function () { describe('when new speed is available', function () {
beforeEach(function () { beforeEach(function () {
state.setSpeed('0.75'); state.setSpeed('0.75', true);
}); });
it('set new speed', function () { it('set new speed', function () {
...@@ -249,8 +249,8 @@ ...@@ -249,8 +249,8 @@
describe('getDuration', function () { describe('getDuration', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha.html'); loadFixtures('video.html');
state = new VideoAlpha('#example'); state = new Video('#example');
}); });
it('return duration for current video', function () { it('return duration for current video', function () {
...@@ -260,8 +260,8 @@ ...@@ -260,8 +260,8 @@
describe('log', function () { describe('log', function () {
beforeEach(function () { beforeEach(function () {
loadFixtures('videoalpha_html5.html'); loadFixtures('video_html5.html');
state = new VideoAlpha('#example'); state = new Video('#example');
spyOn(Logger, 'log'); spyOn(Logger, 'log');
state.videoPlayer.log('someEvent', { state.videoPlayer.log('someEvent', {
currentTime: 25, currentTime: 25,
......
(function () { (function () {
xdescribe('VideoAlpha HTML5Video', function () { xdescribe('Video HTML5Video', function () {
var state, player, oldOTBD, playbackRates = [0.75, 1.0, 1.25, 1.5]; var state, player, oldOTBD, playbackRates = [0.75, 1.0, 1.25, 1.5];
function initialize() { function initialize() {
loadFixtures('videoalpha_html5.html'); loadFixtures('video_html5.html');
state = new VideoAlpha('#example'); state = new Video('#example');
player = state.videoPlayer.player; player = state.videoPlayer.player;
} }
......
(function() { (function() {
xdescribe('VideoCaptionAlpha', function() { xdescribe('VideoCaption', function() {
var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD; var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoPlayer = state.videoPlayer; videoPlayer = state.videoPlayer;
videoCaption = state.videoCaption; videoCaption = state.videoCaption;
videoSpeedControl = state.videoSpeedControl; videoSpeedControl = state.videoSpeedControl;
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
}); });
it('create the caption element', function() { it('create the caption element', function() {
expect($('.videoalpha')).toContain('ol.subtitles'); expect($('.video')).toContain('ol.subtitles');
}); });
it('add caption control to video player', function() { it('add caption control to video player', function() {
expect($('.videoalpha')).toContain('a.hide-subtitles'); expect($('.video')).toContain('a.hide-subtitles');
}); });
it('fetch the caption', function() { it('fetch the caption', function() {
......
(function() { (function() {
xdescribe('VideoControlAlpha', function() { xdescribe('VideoControl', function() {
var state, videoControl, oldOTBD; var state, videoControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoControl = state.videoControl; videoControl = state.videoControl;
} }
......
(function() { (function() {
xdescribe('VideoPlayerAlpha', function() { xdescribe('VideoPlayer', function() {
var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD; var state, videoPlayer, player, videoControl, videoCaption, videoProgressSlider, videoSpeedControl, videoVolumeControl, oldOTBD;
function initialize(fixture) { function initialize(fixture) {
if (typeof fixture === 'undefined') { if (typeof fixture === 'undefined') {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
} else { } else {
loadFixtures(fixture); loadFixtures(fixture);
} }
state = new VideoAlpha('#example'); state = new Video('#example');
videoPlayer = state.videoPlayer; videoPlayer = state.videoPlayer;
player = videoPlayer.player; player = videoPlayer.player;
videoControl = state.videoControl; videoControl = state.videoControl;
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
} }
function initializeYouTube() { function initializeYouTube() {
initialize('videoalpha.html'); initialize('video.html');
} }
beforeEach(function () { beforeEach(function () {
...@@ -71,9 +71,9 @@ ...@@ -71,9 +71,9 @@
expect(videoProgressSlider.el).toHaveClass('slider'); expect(videoProgressSlider.el).toHaveClass('slider');
}); });
// All the toHandleWith() expect tests are not necessary for this version of Video Alpha. // All the toHandleWith() expect tests are not necessary for this version of Video.
// jQuery event system is not used to trigger and invoke methods. This is an artifact from // jQuery event system is not used to trigger and invoke methods. This is an artifact from
// previous version of Video Alpha. // previous version of Video.
}); });
it('create Youtube player', function() { it('create Youtube player', function() {
......
(function() { (function() {
xdescribe('VideoProgressSliderAlpha', function() { xdescribe('VideoProgressSlider', function() {
var state, videoPlayer, videoProgressSlider, oldOTBD; var state, videoPlayer, videoProgressSlider, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoPlayer = state.videoPlayer; videoPlayer = state.videoPlayer;
videoProgressSlider = state.videoProgressSlider; videoProgressSlider = state.videoProgressSlider;
} }
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
expect(videoProgressSlider.slider).toBeUndefined(); expect(videoProgressSlider.slider).toBeUndefined();
// We can't expect $.fn.slider not to have been called, // We can't expect $.fn.slider not to have been called,
// because sliders are used in other parts of VideoAlpha. // because sliders are used in other parts of Video.
}); });
}); });
}); });
......
(function() { (function() {
xdescribe('VideoQualityControlAlpha', function() { xdescribe('VideoQualityControl', function() {
var state, videoControl, videoQualityControl, oldOTBD; var state, videoControl, videoQualityControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha.html'); loadFixtures('video.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoControl = state.videoControl; videoControl = state.videoControl;
videoQualityControl = state.videoQualityControl; videoQualityControl = state.videoQualityControl;
} }
......
(function() { (function() {
xdescribe('VideoSpeedControlAlpha', function() { xdescribe('VideoSpeedControl', function() {
var state, videoPlayer, videoControl, videoSpeedControl; var state, videoPlayer, videoControl, videoSpeedControl;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoPlayer = state.videoPlayer; videoPlayer = state.videoPlayer;
videoControl = state.videoControl; videoControl = state.videoControl;
videoSpeedControl = state.videoSpeedControl; videoSpeedControl = state.videoSpeedControl;
......
(function() { (function() {
xdescribe('VideoVolumeControlAlpha', function() { xdescribe('VideoVolumeControl', function() {
var state, videoControl, videoVolumeControl, oldOTBD; var state, videoControl, videoVolumeControl, oldOTBD;
function initialize() { function initialize() {
loadFixtures('videoalpha_all.html'); loadFixtures('video_all.html');
state = new VideoAlpha('#example'); state = new Video('#example');
videoControl = state.videoControl; videoControl = state.videoControl;
videoVolumeControl = state.videoVolumeControl; videoVolumeControl = state.videoVolumeControl;
} }
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
*.js *.js
# Videoalpha are written in pure JavaScript. # Video are written in pure JavaScript.
!videoalpha/*.js !video/*.js
\ No newline at end of file \ No newline at end of file
...@@ -239,7 +239,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -239,7 +239,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
} else { } else {
string = '<numericalresponse answer="' + floatValue + '">\n'; string = '<numericalresponse answer="' + floatValue + '">\n';
} }
string += ' <textline />\n'; string += ' <formulaequationinput />\n';
string += '</numericalresponse>\n\n'; string += '</numericalresponse>\n\n';
} else { } else {
string = '<stringresponse answer="' + p + '" type="ci">\n <textline size="20"/>\n</stringresponse>\n\n'; string = '<stringresponse answer="' + p + '" type="ci">\n <textline size="20"/>\n</stringresponse>\n\n';
......
...@@ -88,7 +88,7 @@ class @Sequence ...@@ -88,7 +88,7 @@ class @Sequence
$.postWithPrefix modx_full_url, position: new_position $.postWithPrefix modx_full_url, position: new_position
# On Sequence change, fire custom event "sequence:change" on element. # On Sequence change, fire custom event "sequence:change" on element.
# Added for aborting video bufferization, see ../videoalpha/10_main.js # Added for aborting video bufferization, see ../video/10_main.js
@el.trigger "sequence:change" @el.trigger "sequence:change"
@mark_active new_position @mark_active new_position
@$('#seq_content').html @contents.eq(new_position - 1).text() @$('#seq_content').html @contents.eq(new_position - 1).text()
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
(function (requirejs, require, define) { (function (requirejs, require, define) {
define( define(
'videoalpha/01_initialize.js', 'video/01_initialize.js',
['videoalpha/03_video_player.js'], ['video/03_video_player.js'],
function (VideoPlayer) { function (VideoPlayer) {
if (typeof(window.gettext) == "undefined") { if (typeof(window.gettext) == "undefined") {
...@@ -25,8 +25,8 @@ function (VideoPlayer) { ...@@ -25,8 +25,8 @@ function (VideoPlayer) {
* *
* Initialize module exports this function. * Initialize module exports this function.
* *
* @param {Object} state A place for all properties, and methods of Video Alpha. * @param {Object} state A place for all properties, and methods of Video.
* @param {DOM element} element Container of the entire Video Alpha DOM element. * @param {DOM element} element Container of the entire Video DOM element.
*/ */
return function (state, element) { return function (state, element) {
_makeFunctionsPublic(state); _makeFunctionsPublic(state);
...@@ -44,7 +44,7 @@ function (VideoPlayer) { ...@@ -44,7 +44,7 @@ function (VideoPlayer) {
* Functions which will be accessible via 'state' object. When called, these functions will get the 'state' * Functions which will be accessible via 'state' object. When called, these functions will get the 'state'
* object as a context. * object as a context.
* *
* @param {Object} state A place for all properties, and methods of Video Alpha. * @param {Object} state A place for all properties, and methods of Video.
*/ */
function _makeFunctionsPublic(state) { function _makeFunctionsPublic(state) {
state.setSpeed = _.bind(setSpeed, state); state.setSpeed = _.bind(setSpeed, state);
...@@ -70,7 +70,7 @@ function (VideoPlayer) { ...@@ -70,7 +70,7 @@ function (VideoPlayer) {
state.isFullScreen = false; state.isFullScreen = false;
// The parent element of the video, and the ID. // The parent element of the video, and the ID.
state.el = $(element).find('.videoalpha'); state.el = $(element).find('.video');
state.id = state.el.attr('id').replace(/video_/, ''); state.id = state.el.attr('id').replace(/video_/, '');
// We store all settings passed to us by the server in one place. These are "read only", so don't // We store all settings passed to us by the server in one place. These are "read only", so don't
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
(function (requirejs, require, define) { (function (requirejs, require, define) {
define( define(
'videoalpha/02_html5_video.js', 'video/02_html5_video.js',
[], [],
function () { function () {
var HTML5Video = {}; var HTML5Video = {};
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// VideoPlayer module. // VideoPlayer module.
define( define(
'videoalpha/03_video_player.js', 'video/03_video_player.js',
['videoalpha/02_html5_video.js'], ['video/02_html5_video.js'],
function (HTML5Video) { function (HTML5Video) {
// VideoPlayer() function - what this module "exports". // VideoPlayer() function - what this module "exports".
...@@ -315,7 +315,21 @@ function (HTML5Video) { ...@@ -315,7 +315,21 @@ function (HTML5Video) {
this.videoPlayer.log('load_video'); this.videoPlayer.log('load_video');
availablePlaybackRates = this.videoPlayer.player.getAvailablePlaybackRates(); availablePlaybackRates = this.videoPlayer.player
.getAvailablePlaybackRates();
// Because of problems with muting sound outside of range 0.25 and
// 5.0, we should filter our available playback rates.
// Issues:
// https://code.google.com/p/chromium/issues/detail?id=264341
// https://bugzilla.mozilla.org/show_bug.cgi?id=840745
// https://developer.mozilla.org/en-US/docs/DOM/HTMLMediaElement
availablePlaybackRates = _.filter(availablePlaybackRates, function(item){
var speed = Number(item);
return speed > 0.25 && speed <= 5;
});
if ((this.currentPlayerMode === 'html5') && (this.videoType === 'youtube')) { if ((this.currentPlayerMode === 'html5') && (this.videoType === 'youtube')) {
if (availablePlaybackRates.length === 1) { if (availablePlaybackRates.length === 1) {
// This condition is needed in cases when Firefox version is less than 20. In those versions // This condition is needed in cases when Firefox version is less than 20. In those versions
...@@ -359,7 +373,7 @@ function (HTML5Video) { ...@@ -359,7 +373,7 @@ function (HTML5Video) {
this.videoPlayer.player.setPlaybackRate(this.speed); this.videoPlayer.player.setPlaybackRate(this.speed);
} }
if (!onTouchBasedDevice() && $('.videoalpha:first').data('autoplay') === 'True') { if (!onTouchBasedDevice() && $('.video:first').data('autoplay') === 'True') {
this.videoPlayer.play(); this.videoPlayer.play();
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// VideoControl module. // VideoControl module.
define( define(
'videoalpha/04_video_control.js', 'video/04_video_control.js',
[], [],
function () { function () {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// VideoQualityControl module. // VideoQualityControl module.
define( define(
'videoalpha/05_video_quality_control.js', 'video/05_video_quality_control.js',
[], [],
function () { function () {
......
...@@ -9,7 +9,7 @@ mind, or whether to act, and in acting, to live." ...@@ -9,7 +9,7 @@ mind, or whether to act, and in acting, to live."
// VideoProgressSlider module. // VideoProgressSlider module.
define( define(
'videoalpha/06_video_progress_slider.js', 'video/06_video_progress_slider.js',
[], [],
function () { function () {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// VideoVolumeControl module. // VideoVolumeControl module.
define( define(
'videoalpha/07_video_volume_control.js', 'video/07_video_volume_control.js',
[], [],
function () { function () {
...@@ -61,37 +61,71 @@ function () { ...@@ -61,37 +61,71 @@ function () {
slide: state.videoVolumeControl.onChange slide: state.videoVolumeControl.onChange
}); });
// Make sure that we can focus the actual volume slider while Tabing.
state.videoVolumeControl.volumeSliderEl.find('a').attr('tabindex', '0');
state.videoVolumeControl.el.toggleClass('muted', state.videoVolumeControl.currentVolume === 0); state.videoVolumeControl.el.toggleClass('muted', state.videoVolumeControl.currentVolume === 0);
} }
// function _bindHandlers(state) /**
// * @desc Bind any necessary function callbacks to DOM events (click,
// Bind any necessary function callbacks to DOM events (click, mousemove, etc.). * mousemove, etc.).
*
* @type {function}
* @access private
*
* @param {object} state The object containg the state of the video player.
* All other modules, their parameters, public variables, etc. are
* available via this object.
*
* @this {object} The global window object.
*
* @returns {undefined}
*/
function _bindHandlers(state) { function _bindHandlers(state) {
state.videoVolumeControl.buttonEl.on('click', state.videoVolumeControl.toggleMute); state.videoVolumeControl.buttonEl
.on('click', state.videoVolumeControl.toggleMute);
state.videoVolumeControl.el.on('mouseenter', function() { state.videoVolumeControl.el.on('mouseenter', function() {
$(this).addClass('open'); state.videoVolumeControl.el.addClass('open');
});
state.videoVolumeControl.buttonEl.on('focus', function() {
$(this).parent().addClass('open');
}); });
state.videoVolumeControl.el.on('mouseleave', function() { state.videoVolumeControl.el.on('mouseleave', function() {
$(this).removeClass('open'); state.videoVolumeControl.el.removeClass('open');
}); });
// Attach a focus event to the volume button.
state.videoVolumeControl.buttonEl.on('blur', function() { state.videoVolumeControl.buttonEl.on('blur', function() {
state.videoVolumeControl.volumeSliderEl.find('a').focus(); // If the focus is being trasnfered from the volume slider, then we
// don't do anything except for unsetting the special flag.
if (state.volumeBlur === true) {
state.volumeBlur = false;
}
//If the focus is comming from elsewhere, then we must show the
// volume slider and set focus to it.
else {
state.videoVolumeControl.el.addClass('open');
state.videoVolumeControl.volumeSliderEl.find('a').focus();
}
}); });
state.videoVolumeControl.volumeSliderEl.find('a').on('blur', function () { // Attach a blur event handler (loss of focus) to the volume slider
state.videoVolumeControl.el.removeClass('open'); // element. More specifically, we are attaching to the handle on
}); // the slider with which you can change the volume.
state.videoVolumeControl.volumeSliderEl.find('a')
.on('blur', function () {
// Hide the volume slider. This is done so that we can
// continue to the next (or previous) element by tabbing.
// Otherwise, after next tab we would come back to the volume
// slider because it is the next element visible element that
// we can tab to after the volume button.
state.videoVolumeControl.el.removeClass('open');
// Set focus to the volume button.
state.videoVolumeControl.buttonEl.focus();
// We store the fact that previous element that lost focus was
// the volume clontrol.
state.volumeBlur = true;
});
} }
// *************************************************************** // ***************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment