Commit 278ed85c by JM Van Thong

Merge branch 'master' into jmpm-analytics

parents 660481be c341975b
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
.AppleDouble .AppleDouble
database.sqlite database.sqlite
courseware/static/js/mathjax/* courseware/static/js/mathjax/*
db.newaskbot
db.oldaskbot
flushdb.sh flushdb.sh
build build
.coverage .coverage
......
[submodule "askbot"]
path = askbot
url = git@github.com:MITx/askbot-devel.git
syntax: glob
*.pyc
*~
*.scssc
*.swp
*.orig
*.DS_Store
database.sqlite
courseware/static/js/mathjax/*
db.newaskbot
db.oldaskbot
flushdb.sh
Subproject commit e56ae380846f7c6cdaeacfc58880fab103540491
...@@ -3,6 +3,8 @@ Models for Student Information ...@@ -3,6 +3,8 @@ Models for Student Information
Replication Notes Replication Notes
TODO: Update this to be consistent with reality (no portal servers, no more askbot)
In our live deployment, we intend to run in a scenario where there is a pool of In our live deployment, we intend to run in a scenario where there is a pool of
Portal servers that hold the canoncial user information and that user Portal servers that hold the canoncial user information and that user
information is replicated to slave Course server pools. Each Course has a set of information is replicated to slave Course server pools. Each Course has a set of
...@@ -34,10 +36,12 @@ file and check it in at the same time as your model changes. To do that, ...@@ -34,10 +36,12 @@ file and check it in at the same time as your model changes. To do that,
3. Add the migration file created in mitx/common/djangoapps/student/migrations/ 3. Add the migration file created in mitx/common/djangoapps/student/migrations/
""" """
from datetime import datetime from datetime import datetime
from hashlib import sha1
import json import json
import logging import logging
import uuid import uuid
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
...@@ -123,9 +127,9 @@ class UserProfile(models.Model): ...@@ -123,9 +127,9 @@ class UserProfile(models.Model):
self.meta = json.dumps(js) self.meta = json.dumps(js)
class TestCenterUser(models.Model): class TestCenterUser(models.Model):
"""This is our representation of the User for in-person testing, and """This is our representation of the User for in-person testing, and
specifically for Pearson at this point. A few things to note: specifically for Pearson at this point. A few things to note:
* Pearson only supports Latin-1, so we have to make sure that the data we * Pearson only supports Latin-1, so we have to make sure that the data we
capture here will work with that encoding. capture here will work with that encoding.
* While we have a lot of this demographic data in UserProfile, it's much * While we have a lot of this demographic data in UserProfile, it's much
...@@ -133,9 +137,9 @@ class TestCenterUser(models.Model): ...@@ -133,9 +137,9 @@ class TestCenterUser(models.Model):
UserProfile, but we'll need to have a step where people who are signing UserProfile, but we'll need to have a step where people who are signing
up re-enter their demographic data into the fields we specify. up re-enter their demographic data into the fields we specify.
* Users are only created here if they register to take an exam in person. * Users are only created here if they register to take an exam in person.
The field names and lengths are modeled on the conventions and constraints The field names and lengths are modeled on the conventions and constraints
of Pearson's data import system, including oddities such as suffix having of Pearson's data import system, including oddities such as suffix having
a limit of 255 while last_name only gets 50. a limit of 255 while last_name only gets 50.
""" """
# Our own record keeping... # Our own record keeping...
...@@ -146,21 +150,21 @@ class TestCenterUser(models.Model): ...@@ -146,21 +150,21 @@ class TestCenterUser(models.Model):
# and is something Pearson needs to know to manage updates. Unlike # and is something Pearson needs to know to manage updates. Unlike
# updated_at, this will not get incremented when we do a batch data import. # updated_at, this will not get incremented when we do a batch data import.
user_updated_at = models.DateTimeField(db_index=True) user_updated_at = models.DateTimeField(db_index=True)
# Unique ID given to us for this User by the Testing Center. It's null when # Unique ID given to us for this User by the Testing Center. It's null when
# we first create the User entry, and is assigned by Pearson later. # we first create the User entry, and is assigned by Pearson later.
candidate_id = models.IntegerField(null=True, db_index=True) candidate_id = models.IntegerField(null=True, db_index=True)
# Unique ID we assign our user for a the Test Center. # Unique ID we assign our user for a the Test Center.
client_candidate_id = models.CharField(max_length=50, db_index=True) client_candidate_id = models.CharField(max_length=50, db_index=True)
# Name # Name
first_name = models.CharField(max_length=30, db_index=True) first_name = models.CharField(max_length=30, db_index=True)
last_name = models.CharField(max_length=50, db_index=True) last_name = models.CharField(max_length=50, db_index=True)
middle_name = models.CharField(max_length=30, blank=True) middle_name = models.CharField(max_length=30, blank=True)
suffix = models.CharField(max_length=255, blank=True) suffix = models.CharField(max_length=255, blank=True)
salutation = models.CharField(max_length=50, blank=True) salutation = models.CharField(max_length=50, blank=True)
# Address # Address
address_1 = models.CharField(max_length=40) address_1 = models.CharField(max_length=40)
address_2 = models.CharField(max_length=40, blank=True) address_2 = models.CharField(max_length=40, blank=True)
...@@ -173,7 +177,7 @@ class TestCenterUser(models.Model): ...@@ -173,7 +177,7 @@ class TestCenterUser(models.Model):
postal_code = models.CharField(max_length=16, blank=True, db_index=True) postal_code = models.CharField(max_length=16, blank=True, db_index=True)
# country is a ISO 3166-1 alpha-3 country code (e.g. "USA", "CAN", "MNG") # country is a ISO 3166-1 alpha-3 country code (e.g. "USA", "CAN", "MNG")
country = models.CharField(max_length=3, db_index=True) country = models.CharField(max_length=3, db_index=True)
# Phone # Phone
phone = models.CharField(max_length=35) phone = models.CharField(max_length=35)
extension = models.CharField(max_length=8, blank=True, db_index=True) extension = models.CharField(max_length=8, blank=True, db_index=True)
...@@ -181,14 +185,28 @@ class TestCenterUser(models.Model): ...@@ -181,14 +185,28 @@ class TestCenterUser(models.Model):
fax = models.CharField(max_length=35, blank=True) fax = models.CharField(max_length=35, blank=True)
# fax_country_code required *if* fax is present. # fax_country_code required *if* fax is present.
fax_country_code = models.CharField(max_length=3, blank=True) fax_country_code = models.CharField(max_length=3, blank=True)
# Company # Company
company_name = models.CharField(max_length=50, blank=True) company_name = models.CharField(max_length=50, blank=True)
@property @property
def email(self): def email(self):
return self.user.email return self.user.email
def unique_id_for_user(user):
"""
Return a unique id for a user, suitable for inserting into
e.g. personalized survey links.
Currently happens to be implemented as a sha1 hash of the username
(and thus assumes that usernames don't change).
"""
# Using the user id as the salt because it's sort of random, and is already
# in the db.
salt = str(user.id)
return sha1(salt + user.username).hexdigest()
## TODO: Should be renamed to generic UserGroup, and possibly ## TODO: Should be renamed to generic UserGroup, and possibly
# Given an optional field for type of group # Given an optional field for type of group
class UserTestGroup(models.Model): class UserTestGroup(models.Model):
...@@ -361,10 +379,10 @@ def replicate_user_save(sender, **kwargs): ...@@ -361,10 +379,10 @@ def replicate_user_save(sender, **kwargs):
# @receiver(post_save, sender=CourseEnrollment) # @receiver(post_save, sender=CourseEnrollment)
def replicate_enrollment_save(sender, **kwargs): def replicate_enrollment_save(sender, **kwargs):
"""This is called when a Student enrolls in a course. It has to do the """This is called when a Student enrolls in a course. It has to do the
following: following:
1. Make sure the User is copied into the Course DB. It may already exist 1. Make sure the User is copied into the Course DB. It may already exist
(someone deleting and re-adding a course). This has to happen first or (someone deleting and re-adding a course). This has to happen first or
the foreign key constraint breaks. the foreign key constraint breaks.
2. Replicate the CourseEnrollment. 2. Replicate the CourseEnrollment.
...@@ -408,9 +426,9 @@ USER_FIELDS_TO_COPY = ["id", "username", "first_name", "last_name", "email", ...@@ -408,9 +426,9 @@ USER_FIELDS_TO_COPY = ["id", "username", "first_name", "last_name", "email",
def replicate_user(portal_user, course_db_name): def replicate_user(portal_user, course_db_name):
"""Replicate a User to the correct Course DB. This is more complicated than """Replicate a User to the correct Course DB. This is more complicated than
it should be because Askbot extends the auth_user table and adds its own it should be because Askbot extends the auth_user table and adds its own
fields. So we need to only push changes to the standard fields and leave fields. So we need to only push changes to the standard fields and leave
the rest alone so that Askbot changes at the Course DB level don't get the rest alone so that Askbot changes at the Course DB level don't get
overridden. overridden.
""" """
try: try:
...@@ -455,7 +473,7 @@ def is_valid_course_id(course_id): ...@@ -455,7 +473,7 @@ def is_valid_course_id(course_id):
"""Right now, the only database that's not a course database is 'default'. """Right now, the only database that's not a course database is 'default'.
I had nicer checking in here originally -- it would scan the courses that I had nicer checking in here originally -- it would scan the courses that
were in the system and only let you choose that. But it was annoying to run were in the system and only let you choose that. But it was annoying to run
tests with, since we don't have course data for some for our course test tests with, since we don't have course data for some for our course test
databases. Hence the lazy version. databases. Hence the lazy version.
""" """
return course_id != 'default' return course_id != 'default'
......
...@@ -6,11 +6,16 @@ Replace this with more appropriate tests for your application. ...@@ -6,11 +6,16 @@ Replace this with more appropriate tests for your application.
""" """
import logging import logging
from datetime import datetime from datetime import datetime
from hashlib import sha1
from django.test import TestCase from django.test import TestCase
from mock import patch, Mock
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from .models import User, UserProfile, CourseEnrollment, replicate_user, USER_FIELDS_TO_COPY from .models import (User, UserProfile, CourseEnrollment,
replicate_user, USER_FIELDS_TO_COPY,
unique_id_for_user)
from .views import process_survey_link, _cert_info
COURSE_1 = 'edX/toy/2012_Fall' COURSE_1 = 'edX/toy/2012_Fall'
COURSE_2 = 'edx/full/6.002_Spring_2012' COURSE_2 = 'edx/full/6.002_Spring_2012'
...@@ -55,7 +60,7 @@ class ReplicationTest(TestCase): ...@@ -55,7 +60,7 @@ class ReplicationTest(TestCase):
# This hasattr lameness is here because we don't want this test to be # This hasattr lameness is here because we don't want this test to be
# triggered when we're being run by CMS tests (Askbot doesn't exist # triggered when we're being run by CMS tests (Askbot doesn't exist
# there, so the test will fail). # there, so the test will fail).
# #
# seen_response_count isn't a field we care about, so it shouldn't have # seen_response_count isn't a field we care about, so it shouldn't have
# been copied over. # been copied over.
if hasattr(portal_user, 'seen_response_count'): if hasattr(portal_user, 'seen_response_count'):
...@@ -74,7 +79,7 @@ class ReplicationTest(TestCase): ...@@ -74,7 +79,7 @@ class ReplicationTest(TestCase):
# During this entire time, the user data should never have made it over # During this entire time, the user data should never have made it over
# to COURSE_2 # to COURSE_2
self.assertRaises(User.DoesNotExist, self.assertRaises(User.DoesNotExist,
User.objects.using(COURSE_2).get, User.objects.using(COURSE_2).get,
id=portal_user.id) id=portal_user.id)
...@@ -108,19 +113,19 @@ class ReplicationTest(TestCase): ...@@ -108,19 +113,19 @@ class ReplicationTest(TestCase):
# Grab all the copies we expect # Grab all the copies we expect
course_user = User.objects.using(COURSE_1).get(id=portal_user.id) course_user = User.objects.using(COURSE_1).get(id=portal_user.id)
self.assertEquals(portal_user, course_user) self.assertEquals(portal_user, course_user)
self.assertRaises(User.DoesNotExist, self.assertRaises(User.DoesNotExist,
User.objects.using(COURSE_2).get, User.objects.using(COURSE_2).get,
id=portal_user.id) id=portal_user.id)
course_enrollment = CourseEnrollment.objects.using(COURSE_1).get(id=portal_enrollment.id) course_enrollment = CourseEnrollment.objects.using(COURSE_1).get(id=portal_enrollment.id)
self.assertEquals(portal_enrollment, course_enrollment) self.assertEquals(portal_enrollment, course_enrollment)
self.assertRaises(CourseEnrollment.DoesNotExist, self.assertRaises(CourseEnrollment.DoesNotExist,
CourseEnrollment.objects.using(COURSE_2).get, CourseEnrollment.objects.using(COURSE_2).get,
id=portal_enrollment.id) id=portal_enrollment.id)
course_user_profile = UserProfile.objects.using(COURSE_1).get(id=portal_user_profile.id) course_user_profile = UserProfile.objects.using(COURSE_1).get(id=portal_user_profile.id)
self.assertEquals(portal_user_profile, course_user_profile) self.assertEquals(portal_user_profile, course_user_profile)
self.assertRaises(UserProfile.DoesNotExist, self.assertRaises(UserProfile.DoesNotExist,
UserProfile.objects.using(COURSE_2).get, UserProfile.objects.using(COURSE_2).get,
id=portal_user_profile.id) id=portal_user_profile.id)
...@@ -174,30 +179,112 @@ class ReplicationTest(TestCase): ...@@ -174,30 +179,112 @@ class ReplicationTest(TestCase):
portal_user.save() portal_user.save()
portal_user_profile.gender = 'm' portal_user_profile.gender = 'm'
portal_user_profile.save() portal_user_profile.save()
# Grab all the copies we expect, and make sure it doesn't end up in # Grab all the copies we expect, and make sure it doesn't end up in
# places we don't expect. # places we don't expect.
course_user = User.objects.using(COURSE_1).get(id=portal_user.id) course_user = User.objects.using(COURSE_1).get(id=portal_user.id)
self.assertEquals(portal_user, course_user) self.assertEquals(portal_user, course_user)
self.assertRaises(User.DoesNotExist, self.assertRaises(User.DoesNotExist,
User.objects.using(COURSE_2).get, User.objects.using(COURSE_2).get,
id=portal_user.id) id=portal_user.id)
course_enrollment = CourseEnrollment.objects.using(COURSE_1).get(id=portal_enrollment.id) course_enrollment = CourseEnrollment.objects.using(COURSE_1).get(id=portal_enrollment.id)
self.assertEquals(portal_enrollment, course_enrollment) self.assertEquals(portal_enrollment, course_enrollment)
self.assertRaises(CourseEnrollment.DoesNotExist, self.assertRaises(CourseEnrollment.DoesNotExist,
CourseEnrollment.objects.using(COURSE_2).get, CourseEnrollment.objects.using(COURSE_2).get,
id=portal_enrollment.id) id=portal_enrollment.id)
course_user_profile = UserProfile.objects.using(COURSE_1).get(id=portal_user_profile.id) course_user_profile = UserProfile.objects.using(COURSE_1).get(id=portal_user_profile.id)
self.assertEquals(portal_user_profile, course_user_profile) self.assertEquals(portal_user_profile, course_user_profile)
self.assertRaises(UserProfile.DoesNotExist, self.assertRaises(UserProfile.DoesNotExist,
UserProfile.objects.using(COURSE_2).get, UserProfile.objects.using(COURSE_2).get,
id=portal_user_profile.id) id=portal_user_profile.id)
class CourseEndingTest(TestCase):
"""Test things related to course endings: certificates, surveys, etc"""
def test_process_survey_link(self):
username = "fred"
user = Mock(username=username)
id = unique_id_for_user(user)
link1 = "http://www.mysurvey.com"
self.assertEqual(process_survey_link(link1, user), link1)
link2 = "http://www.mysurvey.com?unique={UNIQUE_ID}"
link2_expected = "http://www.mysurvey.com?unique={UNIQUE_ID}".format(UNIQUE_ID=id)
self.assertEqual(process_survey_link(link2, user), link2_expected)
def test_cert_info(self):
user = Mock(username="fred")
survey_url = "http://a_survey.com"
course = Mock(end_of_course_survey_url=survey_url)
self.assertEqual(_cert_info(user, course, None),
{'status': 'processing',
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': False,})
cert_status = {'status': 'unavailable'}
self.assertEqual(_cert_info(user, course, cert_status),
{'status': 'processing',
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': False})
cert_status = {'status': 'generating', 'grade': '67'}
self.assertEqual(_cert_info(user, course, cert_status),
{'status': 'generating',
'show_disabled_download_button': True,
'show_download_url': False,
'show_survey_button': True,
'survey_url': survey_url,
'grade': '67'
})
cert_status = {'status': 'regenerating', 'grade': '67'}
self.assertEqual(_cert_info(user, course, cert_status),
{'status': 'generating',
'show_disabled_download_button': True,
'show_download_url': False,
'show_survey_button': True,
'survey_url': survey_url,
'grade': '67'
})
download_url = 'http://s3.edx/cert'
cert_status = {'status': 'downloadable', 'grade': '67',
'download_url': download_url}
self.assertEqual(_cert_info(user, course, cert_status),
{'status': 'ready',
'show_disabled_download_button': False,
'show_download_url': True,
'download_url': download_url,
'show_survey_button': True,
'survey_url': survey_url,
'grade': '67'
})
cert_status = {'status': 'notpassing', 'grade': '67',
'download_url': download_url}
self.assertEqual(_cert_info(user, course, cert_status),
{'status': 'notpassing',
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': True,
'survey_url': survey_url,
'grade': '67'
})
# Test a course that doesn't have a survey specified
course2 = Mock(end_of_course_survey_url=None)
cert_status = {'status': 'notpassing', 'grade': '67',
'download_url': download_url}
self.assertEqual(_cert_info(user, course2, cert_status),
{'status': 'notpassing',
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': False,
'grade': '67'
})
...@@ -28,7 +28,7 @@ from django.core.cache import cache ...@@ -28,7 +28,7 @@ from django.core.cache import cache
from django_future.csrf import ensure_csrf_cookie, csrf_exempt from django_future.csrf import ensure_csrf_cookie, csrf_exempt
from student.models import (Registration, UserProfile, from student.models import (Registration, UserProfile,
PendingNameChange, PendingEmailChange, PendingNameChange, PendingEmailChange,
CourseEnrollment) CourseEnrollment, unique_id_for_user)
from certificates.models import CertificateStatuses, certificate_status_for_student from certificates.models import CertificateStatuses, certificate_status_for_student
...@@ -39,6 +39,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError ...@@ -39,6 +39,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError
from datetime import date from datetime import date
from collections import namedtuple from collections import namedtuple
from courseware.courses import get_courses_by_university from courseware.courses import get_courses_by_university
from courseware.access import has_access from courseware.access import has_access
...@@ -68,20 +69,6 @@ def index(request, extra_context={}, user=None): ...@@ -68,20 +69,6 @@ def index(request, extra_context={}, user=None):
extra_context is used to allow immediate display of certain modal windows, eg signup, extra_context is used to allow immediate display of certain modal windows, eg signup,
as used by external_auth. as used by external_auth.
''' '''
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
feed_data = render_to_string("feed.rss", None)
cache.set("students_index_rss_feed_data", feed_data, settings.RSS_TIMEOUT)
feed = feedparser.parse(feed_data)
entries = feed['entries'][0:3]
for entry in entries:
soup = BeautifulSoup(entry.description)
entry.image = soup.img['src'] if soup.img else None
entry.summary = soup.getText()
# The course selection work is done in courseware.courses. # The course selection work is done in courseware.courses.
domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN') # normally False domain = settings.MITX_FEATURES.get('FORCE_UNIVERSITY_DOMAIN') # normally False
...@@ -89,7 +76,11 @@ def index(request, extra_context={}, user=None): ...@@ -89,7 +76,11 @@ def index(request, extra_context={}, user=None):
domain = request.META.get('HTTP_HOST') domain = request.META.get('HTTP_HOST')
universities = get_courses_by_university(None, universities = get_courses_by_university(None,
domain=domain) domain=domain)
context = {'universities': universities, 'entries': entries}
# Get the 3 most recent news
top_news = _get_news(top=3)
context = {'universities': universities, 'news': top_news}
context.update(extra_context) context.update(extra_context)
return render_to_response('index.html', context) return render_to_response('index.html', context)
...@@ -98,6 +89,19 @@ def course_from_id(course_id): ...@@ -98,6 +89,19 @@ def course_from_id(course_id):
course_loc = CourseDescriptor.id_to_location(course_id) course_loc = CourseDescriptor.id_to_location(course_id)
return modulestore().get_instance(course_id, course_loc) return modulestore().get_instance(course_id, course_loc)
import re
day_pattern = re.compile('\s\d+,\s')
multimonth_pattern = re.compile('\s?\-\s?\S+\s')
def get_date_for_press(publish_date):
import datetime
# strip off extra months, and just use the first:
date = re.sub(multimonth_pattern, ", ", publish_date)
if re.search(day_pattern, date):
date = datetime.datetime.strptime(date, "%B %d, %Y")
else:
date = datetime.datetime.strptime(date, "%B, %Y")
return date
def press(request): def press(request):
json_articles = cache.get("student_press_json_articles") json_articles = cache.get("student_press_json_articles")
...@@ -110,9 +114,91 @@ def press(request): ...@@ -110,9 +114,91 @@ def press(request):
json_articles = json.loads(content) json_articles = json.loads(content)
cache.set("student_press_json_articles", json_articles) cache.set("student_press_json_articles", json_articles)
articles = [Article(**article) for article in json_articles] articles = [Article(**article) for article in json_articles]
articles.sort(key=lambda item: get_date_for_press(item.publish_date), reverse=True)
return render_to_response('static_templates/press.html', {'articles': articles}) return render_to_response('static_templates/press.html', {'articles': articles})
def process_survey_link(survey_link, user):
"""
If {UNIQUE_ID} appears in the link, replace it with a unique id for the user.
Currently, this is sha1(user.username). Otherwise, return survey_link.
"""
return survey_link.format(UNIQUE_ID=unique_id_for_user(user))
def cert_info(user, course):
"""
Get the certificate info needed to render the dashboard section for the given
student and course. Returns a dictionary with keys:
'status': one of 'generating', 'ready', 'notpassing', 'processing'
'show_download_url': bool
'download_url': url, only present if show_download_url is True
'show_disabled_download_button': bool -- true if state is 'generating'
'show_survey_button': bool
'survey_url': url, only if show_survey_button is True
'grade': if status is not 'processing'
"""
if not course.has_ended():
return {}
return _cert_info(user, course, certificate_status_for_student(user, course.id))
def _cert_info(user, course, cert_status):
"""
Implements the logic for cert_info -- split out for testing.
"""
default_status = 'processing'
default_info = {'status': default_status,
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': False}
if cert_status is None:
return default_info
# simplify the status for the template using this lookup table
template_state = {
CertificateStatuses.generating: 'generating',
CertificateStatuses.regenerating: 'generating',
CertificateStatuses.downloadable: 'ready',
CertificateStatuses.notpassing: 'notpassing',
}
status = template_state.get(cert_status['status'], default_status)
d = {'status': status,
'show_download_url': status == 'ready',
'show_disabled_download_button': status == 'generating',}
if (status in ('generating', 'ready', 'notpassing') and
course.end_of_course_survey_url is not None):
d.update({
'show_survey_button': True,
'survey_url': process_survey_link(course.end_of_course_survey_url, user)})
else:
d['show_survey_button'] = False
if status == 'ready':
if 'download_url' not in cert_status:
log.warning("User %s has a downloadable cert for %s, but no download url",
user.username, course.id)
return default_info
else:
d['download_url'] = cert_status['download_url']
if status in ('generating', 'ready', 'notpassing'):
if 'grade' not in cert_status:
# Note: as of 11/20/2012, we know there are students in this state-- cs169.1x,
# who need to be regraded (we weren't tracking 'notpassing' at first).
# We can add a log.warning here once we think it shouldn't happen.
return default_info
else:
d['grade'] = cert_status['grade']
return d
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def dashboard(request): def dashboard(request):
...@@ -146,12 +232,10 @@ def dashboard(request): ...@@ -146,12 +232,10 @@ def dashboard(request):
show_courseware_links_for = frozenset(course.id for course in courses show_courseware_links_for = frozenset(course.id for course in courses
if has_access(request.user, course, 'load')) if has_access(request.user, course, 'load'))
# TODO: workaround to not have to zip courses and certificates in the template cert_statuses = { course.id: cert_info(request.user, course) for course in courses}
# since before there is a migration to certificates
if settings.MITX_FEATURES.get('CERTIFICATES_ENABLED'): # Get the 3 most recent news
cert_statuses = { course.id: certificate_status_for_student(request.user, course.id) for course in courses} top_news = _get_news(top=3)
else:
cert_statuses = {}
context = {'courses': courses, context = {'courses': courses,
'message': message, 'message': message,
...@@ -159,6 +243,7 @@ def dashboard(request): ...@@ -159,6 +243,7 @@ def dashboard(request):
'errored_courses': errored_courses, 'errored_courses': errored_courses,
'show_courseware_links_for' : show_courseware_links_for, 'show_courseware_links_for' : show_courseware_links_for,
'cert_statuses': cert_statuses, 'cert_statuses': cert_statuses,
'news': top_news,
} }
return render_to_response('dashboard.html', context) return render_to_response('dashboard.html', context)
...@@ -806,3 +891,24 @@ def test_center_login(request): ...@@ -806,3 +891,24 @@ def test_center_login(request):
return redirect('/courses/MITx/6.002x/2012_Fall/courseware/Final_Exam/Final_Exam_Fall_2012/') return redirect('/courses/MITx/6.002x/2012_Fall/courseware/Final_Exam/Final_Exam_Fall_2012/')
else: else:
return HttpResponseForbidden() return HttpResponseForbidden()
def _get_news(top=None):
"Return the n top news items on settings.RSS_URL"
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
feed_data = render_to_string("feed.rss", None)
cache.set("students_index_rss_feed_data", feed_data, settings.RSS_TIMEOUT)
feed = feedparser.parse(feed_data)
entries = feed['entries'][0:top] # all entries if top is None
for entry in entries:
soup = BeautifulSoup(entry.description)
entry.image = soup.img['src'] if soup.img else None
entry.summary = soup.getText()
return entries
...@@ -388,7 +388,7 @@ class XModuleDescriptor(Plugin, HTMLSnippet, ResourceTemplates): ...@@ -388,7 +388,7 @@ class XModuleDescriptor(Plugin, HTMLSnippet, ResourceTemplates):
entry_point = "xmodule.v1" entry_point = "xmodule.v1"
module_class = XModule module_class = XModule
# Attributes for inpsection of the descriptor # Attributes for inspection of the descriptor
stores_state = False # Indicates whether the xmodule state should be stores_state = False # Indicates whether the xmodule state should be
# stored in a database (independent of shared state) # stored in a database (independent of shared state)
has_score = False # This indicates whether the xmodule is a problem-type. has_score = False # This indicates whether the xmodule is a problem-type.
......
<problem display_name="S3E2: Lorentz Force">
<startouttext/>
<p>Consider a hypothetical magnetic field pointing out of your computer screen. Now imagine an electron traveling from right to leftin the plane of your screen. A diagram of this situation is show below.</p>
<center><img width="400" src="/static/images/LSQimages/LSQ_W01_8.png"/></center>
<p>a. The magnitude of the force experienced by the electron is proportional the product of which of the following? (Select all that apply.)</p>
<endouttext/>
<choiceresponse>
<checkboxgroup>
<choice correct="true"><text>Magnetic field strength</text></choice>
<choice correct="false"><text>Electric field strength</text></choice>
<choice correct="true"><text>Electric charge of the electron</text></choice>
<choice correct="false"><text>Radius of the electron</text></choice>
<choice correct="false"><text>Mass of the electron</text></choice>
<choice correct="true"><text>Velocity of the electron</text></choice>
</checkboxgroup>
</choiceresponse>
<startouttext/>
<p>b. The direction of the force experienced by the electron is _______.</p>
<endouttext/>
<choiceresponse>
<checkboxgroup>
<choice correct="false"><text>up, in the plane of the screen.</text></choice>
<choice correct="true"><text>down, in the plane of the screen.</text></choice>
<choice correct="false"><text>into the plane of the screen.</text></choice>
<choice correct="false"><text>out of the plane of the screen.</text></choice>
<choice correct="false"><text>towards the right, in the plane of the screen.</text></choice>
<choice correct="false"><text>towards the left, in the plane of the screen.</text></choice>
</checkboxgroup>
</choiceresponse>
</problem>
<?xml version="1.0"?>
<problem display_name="L4 Problem 1">
<text>
<p>
<b class="bfseries">Part 1: Function Types</b>
</p>
<p>
For each of the following functions, specify the type of its <b class="bfseries">output</b>. You can assume each function is called with an appropriate argument, as specified by its docstring. </p>
<p>
If the output can be either an int or a float, select num, which isn't a real Python type, but which we'll use to indicate that either basic numeric type is legal. </p>
<p>
In fact, in Python, booleans True and False can be operated on as if they were the integers 1 and 0; but it is ugly and confusing to take advantage of this fact, and we will resolutely pretend that it isn't true. </p> <!-- so why even mention it? -->
<p>
<section class="hints">
<div class="collapsible">
<header>
<a href="#" id="id41">What are those lines under the function definitions?</a>
</header>
<section id="id41">
<p>
In this and future problems, you'll see function definitions that look like this: </p>
<pre>
def a(x):
'''
x: int or float.
'''
return x + 1
</pre>
<p>
What are those three lines between <code>def a(x):</code> and <code>return x + 1</code>? These lines are called the <i class="it">docstring</i> of the function. A docstring is a special type of comment that is used to document what your function is doing. Typically, docstrings will explain what the function expects the type(s) of the argument(s) to be, and what the function is returning. </p>
<p>
In Python, docstrings appear immediately after the <code>def</code> line of a function, before the body. Docstrings start and end with triple quotes - this can be triple single quotes or triple double quotes, it doesn't matter as long as they match. To sum up this general form: </p>
<pre>
def myFunction(argument):
"""
Docstring goes here. Explain what type argument(s) should have, and what your function
is going to return.
"""
&lt; Code for your function (the body of the function) goes here &gt;
</pre>
<p>
As you begin coding your own functions, we strongly encourage you to document all your functions by using properly-formatted docstrings! </p>
</section>
</div>
</section>
</p>
<ol class="enumerate">
<li>
<pre>
def a(x):
'''
x: int or float.
'''
return x + 1
</pre>
<p>
Indicate the type of the output that the function <code>a</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="num"/></optionresponse> </p>
</li>
<li>
<pre>
def b(x):
'''
x: int or float.
'''
return x + 1.0
</pre>
<p>
Indicate the type of the output that the function <code>b</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="float"/></optionresponse> </p>
</li>
<li>
<pre>
def c(x, y):
'''
x: int or float.
y: int or float.
'''
return x + y
</pre>
<p>
Indicate the type of the output that the function <code>c</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="num"/></optionresponse> </p>
</li>
<li>
<pre>
def d(x, y):
'''
x: Can be of any type.
y: Can be of any type.
'''
return x &gt; y
</pre>
<p>
Indicate the type of the output that the function <code>d</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="boolean"/></optionresponse> </p>
</li>
<li>
<pre>
def e(x, y, z):
'''
x: Can be of any type.
y: Can be of any type.
z: Can be of any type.
'''
return x &gt;= y and x &lt;= z
</pre>
<p>
Indicate the type of the output that the function <code>e</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="boolean"/></optionresponse> </p>
</li>
<li>
<pre>
def f(x, y):
'''
x: int or float.
y: int or float
'''
x + y - 2
</pre>
<p>
Indicate the type of the output that the function <code>f</code> will yield. <optionresponse><optioninput options="('NoneType','num','int','float','boolean')" correct="NoneType"/></optionresponse> </p>
</li>
</ol>
<p>
<b class="bfseries">Part 2: Transcript</b>
</p>
<p>
Below is a transcript of a session with the Python shell. Assume the functions from Part 1 (above) have been defined. Provide the type and value of the expressions being evaluated. If evaluating an expression would cause an error, select NoneType and write 'error' in the box. If the value of an expression is a function, select function as the type and write 'function' in the box. </p>
<ol class="enumerate">
<li>
<p>
<code>a(6)</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="int"/>
</optionresponse>
<stringresponse answer="7">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>a(-5.3)</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="float"/>
</optionresponse>
<stringresponse answer="-4.3">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>a(a(a(6)))</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="int"/>
</optionresponse>
<stringresponse answer="9">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>c(a(1), b(1))</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="float"/>
</optionresponse>
<stringresponse answer="4.0">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>d('apple', 11.1)</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="boolean"/>
</optionresponse>
<stringresponse answer="True">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>e(a(3), b(4), c(3, 4))</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="boolean"/>
</optionresponse>
<stringresponse answer="False">
<textline size="50"/>
</stringresponse>
</p>
</li>
<li>
<p>
<code>f</code>
<optionresponse>
<optioninput options="('NoneType','num','int','float','boolean','function')" correct="function"/>
</optionresponse>
<stringresponse answer="function">
<textline size="50"/>
</stringresponse>
</p>
</li>
</ol>
</text>
</problem>
<problem display_name="S3E3: Deflection of a Proton">
<startouttext/>
<p>Suppose you were to pass a hydroge ion (H+) through an electric field and measure the deflection of the ion. How would its deflection compare to the deflection of an electron passed through the same electric field? </p>
<endouttext/>
<multiplechoiceresponse direction="vertical" randomize="yes">
<choicegroup type="MultipleChoice">
<choice location="random" correct="false" name="1"><text>The ion would deflect identically as both species have the same charge.</text></choice>
<choice location="random" correct="false" name="2"><text>The ion would deflect by an amount identical in magnitude but opposite in direction because the charges are of opposite sign but equal in magnitude.</text></choice>
<choice location="random" correct="false" name="3"><text>The deflection will be in the same direction but smaller in magnitude due to the larger mass of the ion.</text></choice>
<choice location="random" correct="true" name="4"><text>The deflection will be smaller in magnitude due to the increased mass of the ion, as well as in the opposite direction due to the opposite sign of the charge.</text></choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
\ No newline at end of file
<problem display_name="S2E2: Hydrogen Combustion">
<text>
<p>Gaseous hydrogen can be reacted with gaseous oxygen in the presence of a flame to produce water vapor according to the following reaction:</p>
[mathjax] \text{ a } \text{H}_{2 } + \text{ b }\text{O}_{2 } = \text{ c }\text{H}_{2 }\text{O }[/mathjax]
<p>Balance the equation i.e., specify the values of <i> a, b, </i> and <i>c</i>. Use the lowest whole number coefficients.</p>
<p>a =</p>
<numericalresponse answer="2">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline correct_answer="2" math="1" />
</numericalresponse>
<p>b =
<numericalresponse answer="1">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline math="1" />
</numericalresponse> </p>
<p>c =
<numericalresponse answer="2">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline math="1" />
</numericalresponse> </p>
</text>
</problem>
<problem>
<text>
<p>Metallothermic production of zirconium (Zr) would involve the reaction of sodium (Na) with zirconium tetrachloride (ZrCl<sub>4</sub>).</p>
<p><b>(a)</b> Write a balanced chemical equation.</p>
<!-- chemformularesponse
[mathjax] \text{a ZrCl}_{4 } + \text{ b }\text{Na} -> \text{ c }\text{NaCl } + \text{ d } \text{Zr} [/mathjax]
ratio of (a, b, c, d) = (1, 4, 4, 1)
-->
<customresponse>
<chemicalequationinput size="50"/>
<answer type="loncapa/python">
if chemcalc.chemical_equations_equal(submission[0], 'ZrCl4 + 4 Na -&gt; 4 NaCl + Zr'):
correct = ['correct']
else:
correct = ['incorrect']
</answer>
</customresponse>
<p><b>(b)</b> Write the balanced chemical equation using lowest whole numbers.</p>
<!-- chemformularesponse
as above, with (a, b, c, d) = (1, 4, 4, 1)
-->
<customresponse>
<chemicalequationinput size="50"/>
<answer type="loncapa/python">
if chemcalc.chemical_equations_equal(submission[0], 'ZrCl4 + 4 Na -&gt; 4 NaCl + Zr', exact=True):
correct = ['correct']
else:
correct = ['incorrect']
</answer>
</customresponse>
<p><b>(c)</b> Calculate the amount of zirconium produced (in kg) if a reactor were charged with 111 kg [mathjaxinline]\text{ZrCl}_4[/mathjaxinline] and 11.1 kg [mathjaxinline]\text{Na}[/mathjaxinline].
<numericalresponse answer="11.0">
<responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />
<textline math="1" />
</numericalresponse> </p>
<br/>
<solution>
<p><b>SOLUTION:</b></p>
<p><b>(b)</b>[mathjax] \text{ZrCl}_{4 } + \mathbf{4 }\text{Na} = \mathbf{4 }\text{NaCl } + \mathbf{1 } \text{Zr} [/mathjax] </p>
<p><b>(c)</b></p>
<p>[mathjaxinline]111\text{kg ZrCl}_4 = 111000/[91.22 + (4 \times 35.45)] = 476 \text{ moles ZrCl}_4[/mathjaxinline] </p>
<p>[mathjaxinline]11.1\text{ kg Na} = 11100/22.99 = 483\text{ moles C}[/mathjaxinline]</p>
<p>stoichiometry of reaction further dictates that on a molar basis there needs to be 4 x amount of [mathjaxinline]\text{Na}[/mathjaxinline] as there is [mathjaxinline]\text{ZrCl}_4[/mathjaxinline], but calculations show there to be a shortfall of [mathjaxinline]\text{Na}[/mathjaxinline] </p>
<p>[mathjaxinline]\therefore[/mathjaxinline] reaction yield is contrained by [mathjaxinline]\text{Na}[/mathjaxinline] present </p>
<p>stoichiometry of reaction further dictates that if [mathjaxinline]\text{Na}[/mathjaxinline] controls the yield, then the amount of [mathjaxinline]\text{Zr}[/mathjaxinline] produced = 1/4 x molar quantity of [mathjaxinline]\text{Na}[/mathjaxinline] = 1/4 x 483 moles = 121 </p>
[mathjaxinline]121 \text{ moles Zr} \times 91.22\text{ g / mol } \mathbf{= 11.0 \text{ kg Zr} }[/mathjaxinline]<br/>
</solution>
</text>
</problem>
<problem>
<choiceresponse>
<checkboxgroup>
<choice correct="false">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</checkboxgroup>
</choiceresponse>
<choiceresponse>
<checkboxgroup>
<choice correct="false">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</checkboxgroup>
</choiceresponse>
<choiceresponse>
<checkboxgroup>
<choice correct="false">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</checkboxgroup>
</choiceresponse>
</problem>
<problem>
<choiceresponse>
<radiogroup>
<choice correct="false">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</radiogroup>
</choiceresponse>
<choiceresponse>
<radiogroup>
<choice correct="false">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="true">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</radiogroup>
</choiceresponse>
</problem>
<problem>
<text>
<h2>Code response</h2>
<p>
</p>
<text>
Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<codeparam>
<initial_display>def square(x):</initial_display>
<answer_display>answer</answer_display>
<grader_payload>grader stuff</grader_payload>
</codeparam>
</coderesponse>
</text>
<text>
Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<codeparam>
<initial_display>def square(x):</initial_display>
<answer_display>answer</answer_display>
<grader_payload>grader stuff</grader_payload>
</codeparam>
</coderesponse>
</text>
</text>
</problem>
<problem>
<text>
<h2>Code response</h2>
<p>
</p>
<text>
Write a program to compute the square of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[
initial_display = """
def square(n):
"""
answer = """
def square(n):
return n**2
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testSquare(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: square(%d)'%n
return str(square(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testSquare(0))
elif test == 2: f.write(testSquare(1))
else: f.write(testSquare())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse>
</text>
<text>
Write a program to compute the cube of a number
<coderesponse tests="repeat:2,generate">
<textbox rows="10" cols="70" mode="python"/>
<answer><![CDATA[
initial_display = """
def cube(n):
"""
answer = """
def cube(n):
return n**3
"""
preamble = """
import sys, time
"""
test_program = """
import random
import operator
def testCube(n = None):
if n is None:
n = random.randint(2, 20)
print 'Test is: cube(%d)'%n
return str(cube(n))
def main():
f = os.fdopen(3,'w')
test = int(sys.argv[1])
rndlist = map(int,os.getenv('rndlist').split(','))
random.seed(rndlist[0])
if test == 1: f.write(testCube(0))
elif test == 2: f.write(testCube(1))
else: f.write(testCube())
f.close()
main()
sys.exit(0)
"""
]]>
</answer>
</coderesponse>
</text>
</text>
</problem>
<problem>
<script type="loncapa/python">
# from loncapa import *
x1 = 4 # lc_random(2,4,1)
y1 = 5 # lc_random(3,7,1)
x2 = 10 # lc_random(x1+1,9,1)
y2 = 20 # lc_random(y1+1,15,1)
m = (y2-y1)/(x2-x1)
b = y1 - m*x1
answer = "%s*x+%s" % (m,b)
answer = answer.replace('+-','-')
inverted_m = (x2-x1)/(y2-y1)
inverted_b = b
wrongans = "%s*x+%s" % (inverted_m,inverted_b)
wrongans = wrongans.replace('+-','-')
</script>
<text>
<p>Hints can be provided to students, based on the last response given, as well as the history of responses given. Here is an example of a hint produced by a Formula Response problem.</p>
<p>
What is the equation of the line which passess through ($x1,$y1) and
($x2,$y2)?</p>
<p>The correct answer is <tt>$answer</tt>. A common error is to invert the equation for the slope. Enter <tt>
$wrongans</tt> to see a hint.</p>
</text>
<formularesponse samples="x@-5:5#11" id="11" answer="$answer">
<responseparam description="Numerical Tolerance" type="tolerance" default="0.001" name="tol" />
<text>y = <textline size="25" /></text>
<hintgroup>
<formulahint samples="x@-5:5#11" answer="$wrongans" name="inversegrad">
</formulahint>
<hintpart on="inversegrad">
<text>You have inverted the slope in the question.</text>
</hintpart>
</hintgroup>
</formularesponse>
</problem>
<problem>
<text><p>
Two skiers are on frictionless black diamond ski slopes.
Hello</p></text>
<imageresponse max="1" loncapaid="11">
<imageinput src="/static/Physics801/Figures/Skier-conservation of energy.jpg" width="560" height="388" rectangle="(490,11)-(556,98)"/>
<text>Click on the image where the top skier will stop momentarily if the top skier starts from rest.</text>
<imageinput src="/static/Physics801/Figures/Skier-conservation of energy.jpg" width="560" height="388" rectangle="(242,202)-(296,276)"/>
<text>Click on the image where the lower skier will stop momentarily if the lower skier starts from rest.</text>
<imageinput src="/static/Physics801/Figures/Skier-conservation of energy.jpg" width="560" height="388" rectangle="(490,11)-(556,98);(242,202)-(296,276)"/>
<text>Click on either of the two positions as discussed previously.</text>
<imageinput src="/static/Physics801/Figures/Skier-conservation of energy.jpg" width="560" height="388" rectangle="(490,11)-(556,98);(242,202)-(296,276)"/>
<text>Click on either of the two positions as discussed previously.</text>
<imageinput src="/static/Physics801/Figures/Skier-conservation of energy.jpg" width="560" height="388" rectangle="(490,11)-(556,98);(242,202)-(296,276)"/>
<text>Click on either of the two positions as discussed previously.</text>
<hintgroup showoncorrect="no">
<text><p>Use conservation of energy.</p></text>
</hintgroup>
</imageresponse>
</problem>
<problem>
<javascriptresponse>
<generator src="test_problem_generator.js"/>
<grader src="test_problem_grader.js"/>
<display class="TestProblemDisplay" src="test_problem_display.js"/>
<responseparam name="value" value="4"/>
<javascriptinput>
</javascriptinput>
</javascriptresponse>
</problem>
<problem>
<multiplechoiceresponse>
<choicegroup>
<choice correct="false" >
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false" >
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true" >
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
<problem>
<multiplechoiceresponse>
<choicegroup>
<choice correct="false" name="foil1">
<startouttext />This is foil One.<endouttext />
</choice>
<choice correct="false" name="foil2">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice correct="true" name="foil3">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice correct="false" name="foil4">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice correct="false" name="foil5">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
<problem display_name="S3E3: Deflection of a Proton">
<startouttext/>
<p>Suppose you were to pass a hydroge ion (H+) through an electric field and measure the deflection of the ion. How would its deflection compare to the deflection of an electron passed through the same electric field? </p>
<endouttext/>
<multiplechoiceresponse direction="vertical" randomize="yes">
<choicegroup type="MultipleChoice">
<choice location="random" correct="false" name="1"><text>The ion would deflect identically as both species have the same charge.</text></choice>
<choice location="random" correct="false" name="2"><text>The ion would deflect by an amount identical in magnitude but opposite in direction because the charges are of opposite sign but equal in magnitude.</text></choice>
<choice location="random" correct="false" name="3"><text>The deflection will be in the same direction but smaller in magnitude due to the larger mass of the ion.</text></choice>
<choice location="random" correct="true" name="4"><text>The deflection will be smaller in magnitude due to the increased mass of the ion, as well as in the opposite direction due to the opposite sign of the charge.</text></choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
\ No newline at end of file
<problem display_name="S2E2: Hydrogen Combustion">
<text>
<p>Gaseous hydrogen can be reacted with gaseous oxygen in the presence of a flame to produce water vapor according to the following reaction:</p>
[mathjax] \text{ a } \text{H}_{2 } + \text{ b }\text{O}_{2 } = \text{ c }\text{H}_{2 }\text{O }[/mathjax]
<p>Balance the equation i.e., specify the values of <i> a, b, </i> and <i>c</i>. Use the lowest whole number coefficients.</p>
<p>a =</p>
<numericalresponse answer="2">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline correct_answer="2" math="1" />
</numericalresponse>
<p>b =
<numericalresponse answer="1">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline math="1" />
</numericalresponse> </p>
<p>c =
<numericalresponse answer="2">
<responseparam type="tolerance" default="1%" name="tol" description="Numerical Tolerance" />
<textline math="1" />
</numericalresponse> </p>
</text>
</problem>
<problem>
<text>
<p>
Why do bicycles benefit from having larger wheels when going up a bump as shown in the picture? <br/>
Assume that for both bicycles:<br/>
1.) The tires have equal air pressure.<br/>
2.) The bicycles never leave the contact with the bump.<br/>
3.) The bicycles have the same mass. The bicycle tires (regardless of size) have the same mass.<br/>
</p>
</text>
<optionresponse texlayout="horizontal" max="10" randomize="yes">
<ul>
<li>
<text>
<p>The bicycles with larger wheels have more time to go over the bump. This decreases the magnitude of the force needed to lift the bicycle.</p>
</text>
<optioninput name="Foil1" location="random" options="('True','False')" correct="True">
</optioninput>
</li>
<li>
<text>
<p>The bicycles with larger wheels always have a smaller vertical displacement regardless of speed.</p>
</text>
<optioninput name="Foil2" location="random" options="('True','False')" correct="False">
</optioninput>
</li>
<li>
<text>
<p>The bicycles with larger wheels experience a force backward with less magnitude for the same amount of time.</p>
</text>
<optioninput name="Foil3" location="random" options="('True','False')" correct="False">
</optioninput>
</li>
<li>
<text>
<p>The bicycles with larger wheels experience a force backward with less magnitude for a greater amount of time.</p>
</text>
<optioninput name="Foil4" location="random" options="('True','False')" correct="True">
</optioninput>
</li>
<li>
<text>
<p>The bicycles with larger wheels have more kinetic energy turned into gravitational potential energy.</p>
</text>
<optioninput name="Foil5" location="random" options="('True','False')" correct="False">
</optioninput>
</li>
<li>
<text>
<p>The bicycles with larger wheels have more rotational kinetic energy, so the horizontal velocity of the biker changes less.</p>
</text>
<optioninput name="Foil6" location="random" options="('True','False')" correct="False">
</optioninput>
</li>
</ul>
<hintgroup showoncorrect="no">
<text>
<br/>
<br/>
</text>
</hintgroup>
</optionresponse>
</problem>
<problem >
<text><h2>Example: String Response Problem</h2>
<br/>
</text>
<text>Which US state has Lansing as its capital?</text>
<stringresponse answer="Michigan" type="ci">
<textline size="20" />
<hintgroup>
<stringhint answer="wisconsin" type="cs" name="wisc">
</stringhint>
<stringhint answer="minnesota" type="cs" name="minn">
</stringhint>
<hintpart on="wisc">
<text>The state capital of Wisconsin is Madison.</text>
</hintpart>
<hintpart on="minn">
<text>The state capital of Minnesota is St. Paul.</text>
</hintpart>
<hintpart on="default">
<text>The state you are looking for is also known as the 'Great Lakes State'</text>
</hintpart>
</hintgroup>
</stringresponse>
</problem>
<problem>
<text>
<h2>Example: Symbolic Math Response Problem</h2>
<p>
A symbolic math response problem presents one or more symbolic math
input fields for input. Correctness of input is evaluated based on
the symbolic properties of the expression entered. The student enters
text, but sees a proper symbolic rendition of the entered formula, in
real time, next to the input box.
</p>
<p>This is a correct answer which may be entered below: </p>
<p><tt>cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]</tt></p>
<script>
from symmath import *
</script>
<text>Compute [mathjax] U = \exp\left( i \theta \left[ \begin{matrix} 0 &amp; 1 \\ 1 &amp; 0 \end{matrix} \right] \right) [/mathjax]
and give the resulting \(2 \times 2\) matrix. <br/>
Your input should be typed in as a list of lists, eg <tt>[[1,2],[3,4]]</tt>. <br/>
[mathjax]U=[/mathjax] <symbolicresponse cfn="symmath_check" answer="[[cos(theta),I*sin(theta)],[I*sin(theta),cos(theta)]]" options="matrix,imaginaryi" id="filenamedogi0VpEBOWedxsymmathresponse_1" state="unsubmitted">
<textline size="80" math="1" response_id="2" answer_id="1" id="filenamedogi0VpEBOWedxsymmathresponse_2_1"/>
</symbolicresponse>
<br/>
</text>
</text>
</problem>
<problem>
<truefalseresponse max="10" randomize="yes">
<choicegroup>
<choice location="random" correct="true" name="foil1">
<startouttext />This is foil One.<endouttext />
</choice>
<choice location="random" correct="true" name="foil2">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice location="random" correct="false" name="foil3">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice location="random" correct="false" name="foil4">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice location="random" correct="false" name="foil5">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
</truefalseresponse>
</problem>
<vertical display_name="Test problems">
<problem url_name="test_files:numericalresponse_demo"/>
<problem url_name="test_files:choiceresponse_checkbox"/>
<problem url_name="test_files:choiceresponse_radio"/>
<problem url_name="test_files:coderesponse"/>
<problem url_name="test_files:coderesponse_externalresponseformat"/>
<problem url_name="test_files:formularesponse_with_hint"/>
<problem url_name="test_files:imageresponse"/>
<problem url_name="test_files:javascriptresponse"/>
<problem url_name="test_files:multi_bare"/>
<problem url_name="test_files:multichoice"/>
<problem url_name="test_files:multiplechoicelresponse_demo"/>
<problem url_name="test_files:numericalresponse_demo"/>
<problem url_name="test_files:optionresponse"/>
<problem url_name="test_files:stringresponse_with_hint"/>
<problem url_name="test_files:symbolicresponse"/>
<problem url_name="test_files:truefalse"/>
<problem url_name="test_files:chemicalequationresponse"/>
<problem url_name="test_files:filesubmission"/>
</vertical>
\ No newline at end of file
...@@ -72,12 +72,6 @@ clone_repos() { ...@@ -72,12 +72,6 @@ clone_repos() {
git clone git@github.com:MITx/mitx.git git clone git@github.com:MITx/mitx.git
fi fi
if [[ ! -d "$BASE/mitx/askbot/.git" ]]; then
output "Cloning askbot as a submodule of mitx"
cd "$BASE/mitx"
git submodule update --init
fi
# By default, dev environments start with a copy of 6.002x # By default, dev environments start with a copy of 6.002x
cd "$BASE" cd "$BASE"
mkdir -p "$BASE/data" mkdir -p "$BASE/data"
...@@ -334,9 +328,6 @@ pip install -r mitx/pre-requirements.txt ...@@ -334,9 +328,6 @@ pip install -r mitx/pre-requirements.txt
output "Installing MITx requirements" output "Installing MITx requirements"
cd mitx cd mitx
pip install -r requirements.txt pip install -r requirements.txt
output "Installing askbot requirements"
pip install -r askbot/askbot_requirements.txt
pip install -r askbot/askbot_requirements_dev.txt
mkdir "$BASE/log" || true mkdir "$BASE/log" || true
mkdir "$BASE/db" || true mkdir "$BASE/db" || true
......
...@@ -27,7 +27,7 @@ You should be familiar with the following. If you're not, go read some docs... ...@@ -27,7 +27,7 @@ You should be familiar with the following. If you're not, go read some docs...
- CMS -- Course Management System. The instructor-facing parts of the system. Allows instructors to see and modify their course, add lectures, problems, reorder things, etc. - CMS -- Course Management System. The instructor-facing parts of the system. Allows instructors to see and modify their course, add lectures, problems, reorder things, etc.
- Askbot -- the discussion forums. We have a custom fork of this project. We're also hoping to replace it with something better later. (e.g. need support for multiple classes, etc) - Forums -- this is a ruby on rails service that runs on Heroku. Contributed by berkeley folks. The LMS has a wrapper lib that talks to it.
- Data. In the data/ dir. There is currently a single `course.xml` file that describes an entire course. Speaking of which... - Data. In the data/ dir. There is currently a single `course.xml` file that describes an entire course. Speaking of which...
......
...@@ -9,7 +9,6 @@ There is also a script "create-dev-env.sh" that automates these steps. ...@@ -9,7 +9,6 @@ There is also a script "create-dev-env.sh" that automates these steps.
mkdir ~/mitx_all mkdir ~/mitx_all
cd ~/mitx_all cd ~/mitx_all
git clone git@github.com:MITx/mitx.git git clone git@github.com:MITx/mitx.git
git clone git@github.com:MITx/askbot-devel
hg clone ssh://hg-content@gp.mitx.mit.edu/data hg clone ssh://hg-content@gp.mitx.mit.edu/data
2) Install OSX dependencies (Mac users only) 2) Install OSX dependencies (Mac users only)
...@@ -49,8 +48,6 @@ There is also a script "create-dev-env.sh" that automates these steps. ...@@ -49,8 +48,6 @@ There is also a script "create-dev-env.sh" that automates these steps.
source ~/mitx_all/python/bin/activate source ~/mitx_all/python/bin/activate
cd ~/mitx_all cd ~/mitx_all
pip install -r askbot-devel/askbot_requirements.txt
pip install -r askbot-devel/askbot_requirements_dev.txt
pip install -r mitx/pre-requirements.txt pip install -r mitx/pre-requirements.txt
pip install -r mitx/requirements.txt pip install -r mitx/requirements.txt
......
=============================
Customization of Askbot skins
=============================
The default skin at the moment is in the development, however
it is already possible to start customizing your site without
incurring much maintenance overhead.
Current status of templates
===========================
The two busiest templates are - the "main" page and the "question" page,
the main page is more or less complete. "Question" page will be significantly
refactored in the near future.
How skins work in Askbot
========================
The skins reside in up to two directories:
* `askbot/skins` in the source code (contains any stock skins)
* directory pointed to by a ASKBOT_EXTRA_SKINS_DIR in your settings.py
with any other skins
Currently, the skin is selected by the site administrator in the live settings.
Also, at the moment skin default is special - it serves any resources
absent in other skins. In a way - all other skins inherit from the "default".
Templates and media are resolved in the following way:
* check in skin named as in settings.ASKBOT_DEFAULT_SKIN
* then skin named 'default'
How to customize a skin
=======================
There are three options:
* edit custom css via the settings interface - good for small tweaks
(no need to directly log in to the server)
* create a new skin in separate files (need direct access to the server
files, more maintenance overhead)
* directly modify the "default" skin (as in the previous option - need
direct access to the server, less maintenance overhead, some
knowledge of git system is required)
The first option only allows to modify css and add custom javascript.
The latter two options allow changing the templates as well.
If you wish to follow the second option, create a directory named the same
way as the skin you are building and start adding files with the same names
and relative locations as those in the "default" skin.
NO NEED TO CREATE ALL TEMPLATES/MEDIA FILES AT ONCE as your skin will inherit
pieces from the "default".
The disadvantage of thil second approach is that you will be on your own maintaining
the synchrony of your template, stylesheet and the core code.
Third approach is the best, but it requires (the most basic) use of
git source code management software. With git you will easily merge the updates
from the development repository.
Structure of the skin directories
=================================
Todo.
To simplify maintenance of the css as the skin is being developed,
populate css file `media/style/extra.css` with any rules that will
override those in the `media/style/style.css` file. If you do that
media does not have to be composed of files named the same way as in default skin
whatever media you link to from your templates - will be in operation
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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