From 1736eb212532479f290223db4ab02b61fb5abd62 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Fri, 25 May 2012 16:15:12 -0400 Subject: [PATCH 01/15] first commit --- create-dev-env.sh | 221 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100755 create-dev-env.sh diff --git a/create-dev-env.sh b/create-dev-env.sh new file mode 100755 index 0000000000..35653c38ba --- /dev/null +++ b/create-dev-env.sh @@ -0,0 +1,221 @@ +#!/bin/bash +set -e + +error() { + printf '\E[36m'; echo "$@"; printf '\E[0m' +} +output() { + printf '\E[36m'; echo "$@"; printf '\E[0m' +} +usage() { + cat< $HOME/.rvmrc +fi +mkdir -p $BASE +rm -f $LOG +case `uname -s` in + [Ll]inux) + command -v lsb_release &>/dev/null || { + error "Please install lsb-release." + exit 1 + } + distro=`lsb_release -cs` + case $distro in + lisa|natty|oneiric|precise) + output "Installing ubuntu requirements" + sudo apt-get -y update + sudo apt-get -y install $APT_PKGS + ;; + *) + error "Unsupported distribution - $distro" + exit 1 + ;; + esac + ;; + Darwin) + command -v brew &>/dev/null || { + output "Installing brew" + /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" >>$LOG + } + output "Installing OSX requirements" + # brew errors if the package is already installed + for pkg in $BREW_PKGS; do + grep $pkg <(brew list) &>/dev/null || { + output "Installing $pkg" + brew install $pkg >>$LOG + } + done + command -v pip &>/dev/null || { + output "Installing pip" + sudo easy_install pip >>$LOG + } + command -v virtualenv &>/dev/null || { + output "Installing virtualenv" + sudo pip install virtualenv virtualenvwrapper >> $LOG + } + ;; + *) + error "Unsupported platform" + exit 1 + ;; +esac +output "Installing rvm and ruby" +curl -sL get.rvm.io | bash -s stable +source $RUBY_DIR/scripts/rvm +rvm install $RUBY_VER +virtualenv "$PYTHON_DIR" +source $PYTHON_DIR/bin/activate +output "Installing ruby packages - $GEM_PKGS" +gem install $GEM_PKGS +cd "$BASE" +output "Cloning mitx, askbot and data repos" +if [[ -d "$BASE/mitx" ]]; then + mv "$BASE/mitx" "${BASE}/mitx.bak.$$" +fi +git clone git@github.com:MITx/mitx.git >>$LOG +if [[ -d "$BASE/askbot-devel" ]]; then + mv "$BASE/askbot-devel" "${BASE}/askbot-devel.bak.$$" +fi +git clone git@github.com:MITx/askbot-devel >>$LOG +if [[ -d "$BASE/data" ]]; then + mv "$BASE/data" "${BASE}/data.bak.$$" +fi +hg clone ssh://hg-content@gp.mitx.mit.edu/data >>$LOG + +if [[ -n $compile ]]; then + output "Downloading numpy and scipy" + curl -sL -o numpy.tar.gz http://downloads.sourceforge.net/project/numpy/NumPy/${NUMPY_VER}/numpy-${NUMPY_VER}.tar.gz + curl -sL -o scipy.tar.gz http://downloads.sourceforge.net/project/scipy/scipy/${SCIPY_VER}/scipy-${SCIPY_VER}.tar.gz + tar xf numpy.tar.gz + tar xf scipy.tar.gz + rm -f numpy.tar.gz scipy.tar.gz + output "Compiling numpy" + cd "$BASE/numpy-${NUMPY_VER}" + python setup.py install >>$LOG 2>&1 + output "Compiling scipy" + cd "$BASE/scipy-${SCIPY_VER}" + python setup.py install >>$LOG 2>&1 + cd "$BASE" + rm -rf numpy-${NUMPY_VER} scipy-${SCIPY_VER} +fi + +output "Installing askbot requirements" +pip install -r askbot-devel/askbot_requirements.txt >>$LOG +pip install -r askbot-devel/askbot_requirements_dev.txt >>$LOG +output "Installing MITx requirements" +pip install -r mitx/pre-requirements.txt >> $LOG +pip install -r mitx/requirements.txt >>$LOG + +mkdir "$BASE/log" +mkdir "$BASE/db" + +cat< Date: Fri, 25 May 2012 16:22:09 -0400 Subject: [PATCH 02/15] mkdirs fail silently --- create-dev-env.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-dev-env.sh b/create-dev-env.sh index 35653c38ba..1f2ddd4376 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -195,8 +195,8 @@ output "Installing MITx requirements" pip install -r mitx/pre-requirements.txt >> $LOG pip install -r mitx/requirements.txt >>$LOG -mkdir "$BASE/log" -mkdir "$BASE/db" +mkdir "$BASE/log" || true +mkdir "$BASE/db" || true cat< Date: Fri, 25 May 2012 16:37:22 -0400 Subject: [PATCH 03/15] updating gem install list --- create-dev-env.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/create-dev-env.sh b/create-dev-env.sh index 1f2ddd4376..6c4d1cae8e 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -26,9 +26,7 @@ info() { MITx base dir : $BASE Python dir : $PYTHON_DIR Ruby dir : $RUBY_DIR - Ruby ver : $RUBY_VER - Ruby libraries : $GEM_PKGS EO @@ -45,7 +43,6 @@ SCIPY_VER="0.10.1" LOG="/var/tmp/install.log" BREW_PKGS="readline sqlite gdbm pkg-config gfortran mercurial python yuicompressor " APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor" -GEM_PKGS="sass bourbon" ARGS=$(getopt "cvh" "$*") if [[ $? != 0 ]]; then @@ -154,8 +151,10 @@ source $RUBY_DIR/scripts/rvm rvm install $RUBY_VER virtualenv "$PYTHON_DIR" source $PYTHON_DIR/bin/activate -output "Installing ruby packages - $GEM_PKGS" -gem install $GEM_PKGS +output "Installing ruby packages" +gem install --version '0.8.3' rake +gem install --version '3.1.15' sass +gem install --version '1.3.6' bourbon cd "$BASE" output "Cloning mitx, askbot and data repos" if [[ -d "$BASE/mitx" ]]; then From 3b3cf5b7a08e7caeca1f1269754016dfa62b53f2 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 29 May 2012 09:33:42 -0400 Subject: [PATCH 04/15] added node/coffeescript to dependency list --- create-dev-env.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-dev-env.sh b/create-dev-env.sh index 6c4d1cae8e..b207dbdeb3 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -41,8 +41,8 @@ RUBY_VER="1.9.3" NUMPY_VER="1.6.2" SCIPY_VER="0.10.1" LOG="/var/tmp/install.log" -BREW_PKGS="readline sqlite gdbm pkg-config gfortran mercurial python yuicompressor " -APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor" +BREW_PKGS="readline sqlite gdbm pkg-config gfortran mercurial python yuicompressor node" +APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript" ARGS=$(getopt "cvh" "$*") if [[ $? != 0 ]]; then From d011ab99ada2ddcba4f9189010c84a9c616ccc68 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Wed, 30 May 2012 11:43:33 -0400 Subject: [PATCH 05/15] added root user check --- create-dev-env.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/create-dev-env.sh b/create-dev-env.sh index b207dbdeb3..0a3d7258eb 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -2,7 +2,7 @@ set -e error() { - printf '\E[36m'; echo "$@"; printf '\E[0m' + printf '\E[31m'; echo "$@"; printf '\E[0m' } output() { printf '\E[36m'; echo "$@"; printf '\E[0m' @@ -29,10 +29,10 @@ info() { Ruby ver : $RUBY_VER EO - - - } + + + PROG=${0##*/} BASE="$HOME/mitx_all" PYTHON_DIR="$BASE/python" @@ -44,6 +44,12 @@ LOG="/var/tmp/install.log" BREW_PKGS="readline sqlite gdbm pkg-config gfortran mercurial python yuicompressor node" APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript" +if [[ $EUID -eq 0 ]]; then + error "This script should not be run using sudo or as the root user" + usage + exit 1 +fi + ARGS=$(getopt "cvh" "$*") if [[ $? != 0 ]]; then usage From 908e9c0427b0c14ca166ca81fe0acea3990d1f75 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Thu, 31 May 2012 10:41:45 -0400 Subject: [PATCH 06/15] no longer redirecting STDOUT when running the brew installer --- create-dev-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create-dev-env.sh b/create-dev-env.sh index 0a3d7258eb..1b3b932dd5 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -127,7 +127,7 @@ case `uname -s` in Darwin) command -v brew &>/dev/null || { output "Installing brew" - /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" >>$LOG + /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" } output "Installing OSX requirements" # brew errors if the package is already installed From 26ce972cea05bf75e21d1c7443b87754e7a174e2 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Thu, 31 May 2012 11:39:55 -0400 Subject: [PATCH 07/15] adding brew-formulas, updating dev env script --- brew-formulas.txt | 9 +++++++++ create-dev-env.sh | 34 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 brew-formulas.txt diff --git a/brew-formulas.txt b/brew-formulas.txt new file mode 100644 index 0000000000..5f76861eda --- /dev/null +++ b/brew-formulas.txt @@ -0,0 +1,9 @@ +readline +sqlite +gdbm +pkg-config +gfortran +mercurial +python +yuicompressor +node diff --git a/create-dev-env.sh b/create-dev-env.sh index 1b3b932dd5..1b3c272bb3 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -41,7 +41,7 @@ RUBY_VER="1.9.3" NUMPY_VER="1.6.2" SCIPY_VER="0.10.1" LOG="/var/tmp/install.log" -BREW_PKGS="readline sqlite gdbm pkg-config gfortran mercurial python yuicompressor node" +BREW_PKGS="$BASE/mit/brew-formulas.txt" APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript" if [[ $EUID -eq 0 ]]; then @@ -92,6 +92,10 @@ cat</dev/null || { output "Installing $pkg" brew install $pkg >>$LOG @@ -151,16 +155,7 @@ case `uname -s` in exit 1 ;; esac -output "Installing rvm and ruby" -curl -sL get.rvm.io | bash -s stable -source $RUBY_DIR/scripts/rvm -rvm install $RUBY_VER -virtualenv "$PYTHON_DIR" -source $PYTHON_DIR/bin/activate -output "Installing ruby packages" -gem install --version '0.8.3' rake -gem install --version '3.1.15' sass -gem install --version '1.3.6' bourbon + cd "$BASE" output "Cloning mitx, askbot and data repos" if [[ -d "$BASE/mitx" ]]; then @@ -176,6 +171,21 @@ if [[ -d "$BASE/data" ]]; then fi hg clone ssh://hg-content@gp.mitx.mit.edu/data >>$LOG + +output "Installing rvm and ruby" +curl -sL get.rvm.io | bash -s stable +source $RUBY_DIR/scripts/rvm +rvm install $RUBY_VER +virtualenv "$PYTHON_DIR" +source $PYTHON_DIR/bin/activate +output "Installing gem bundler" +gem install bundler +output "Installing ruby packages" +cd $BASE/mitx +bundle install + +cd $BASE + if [[ -n $compile ]]; then output "Downloading numpy and scipy" curl -sL -o numpy.tar.gz http://downloads.sourceforge.net/project/numpy/NumPy/${NUMPY_VER}/numpy-${NUMPY_VER}.tar.gz From a385dc4d2e5a53ecb79ad4b4bf612745a35d09d3 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Thu, 31 May 2012 14:34:50 -0400 Subject: [PATCH 08/15] added install.txt, updated env script for better error handling --- install.txt | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 install.txt diff --git a/install.txt b/install.txt new file mode 100644 index 0000000000..70c8655306 --- /dev/null +++ b/install.txt @@ -0,0 +1,74 @@ +This document describes how to set up the MITx development environment +for both Linux (Ubuntu) and MacOS (OSX Lion). + +There is also a script "create-dev-env.sh" that automates these steps. + +1) Make an mitx_all directory and clone the repos + (download and install git and mercurial if you don't have them already) + + mkdir ~/mitx_all + cd ~/mitx_all + 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 + +2) Install OSX dependencies (Mac users only) + + a) Install the brew utility if necessary + /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" + + b) Install the brew package list + cat ~/mitx_all/mitx/brew-formulas.txt | xargs brew install + + c) Install python pip if necessary + sudo easy_install pip + + d) Install python virtualenv if necessary + sudo pip install virtualenv virtualenvwrapper + +3) Install Ubuntu dependencies (Linux users only) + + sudo apt-get install curl python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript + + +4) Install rvm, ruby, and libraries + + echo "export rvm_path=$HOME/mitx_all/ruby" > $HOME/.rvmrc + curl -sL get.rvm.io | bash -s stable + source ~/mitx_all/ruby/scripts/rvm + rvm install 1.9.3 + gem install bundler + cd ~/mitx_all/mitx + bundle install + +5) Install python libraries + + source ~/mitx_all/python/bin/activate + 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/requirements.txt + +6) Create log and db dirs + + mkdir ~/mitx_all/log + mkdir ~/mitx_all/db + +7) Start the dev server + + To start using Django you will need + to activate the local Python and Ruby + environment: + + $ source ~/mitx_all/ruby/scripts/rvm + $ source ~/mitx_all/python/bin/activate + + To initialize and start a local instance of Django: + + $ cd ~/mitx_all/mitx + $ django-admin.py syncdb --settings=envs.dev --pythonpath=. + $ django-admin.py migrate --settings=envs.dev --pythonpath=. + $ django-admin.py runserver --settings=envs.dev --pythonpath=. + + From 178cdc877e3d83b107d11f72956761c42995096d Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Thu, 31 May 2012 14:36:23 -0400 Subject: [PATCH 09/15] removing mercurial from brew install list --- brew-formulas.txt | 1 - create-dev-env.sh | 76 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/brew-formulas.txt b/brew-formulas.txt index 5f76861eda..61e3d33e3a 100644 --- a/brew-formulas.txt +++ b/brew-formulas.txt @@ -3,7 +3,6 @@ sqlite gdbm pkg-config gfortran -mercurial python yuicompressor node diff --git a/create-dev-env.sh b/create-dev-env.sh index 1b3c272bb3..7190d81a73 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -1,6 +1,21 @@ #!/bin/bash set -e +trap "ouch" ERR +ouch() { + printf '\E[31m' + + cat<>$LOG + output "Cloning askbot-devel" + if [[ -d "$BASE/askbot-devel" ]]; then + mv "$BASE/askbot-devel" "${BASE}/askbot-devel.bak.$$" + fi + git clone git@github.com:MITx/askbot-devel >>$LOG + output "Cloning data" + if [[ -d "$BASE/data" ]]; then + mv "$BASE/data" "${BASE}/data.bak.$$" + fi + hg clone ssh://hg-content@gp.mitx.mit.edu/data >>$LOG +} PROG=${0##*/} BASE="$HOME/mitx_all" @@ -40,8 +72,8 @@ RUBY_DIR="$BASE/ruby" RUBY_VER="1.9.3" NUMPY_VER="1.6.2" SCIPY_VER="0.10.1" +BREW_FILE="$BASE/mitx/brew-formulas.txt" LOG="/var/tmp/install.log" -BREW_PKGS="$BASE/mit/brew-formulas.txt" APT_PKGS="curl git mercurial python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript" if [[ $EUID -eq 0 ]]; then @@ -49,7 +81,6 @@ if [[ $EUID -eq 0 ]]; then usage exit 1 fi - ARGS=$(getopt "cvh" "$*") if [[ $? != 0 ]]; then usage @@ -121,11 +152,12 @@ case `uname -s` in output "Installing ubuntu requirements" sudo apt-get -y update sudo apt-get -y install $APT_PKGS + clone_repos ;; *) error "Unsupported distribution - $distro" exit 1 - ;; + ;; esac ;; Darwin) @@ -133,9 +165,24 @@ case `uname -s` in output "Installing brew" /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)" } + command -v git &>/dev/null || { + output "Installing git" + brew install git >> $LOG + } + command -v hg &>/dev/null || { + output "Installaing mercurial" + brew install mercurial >> $LOG + } + + clone_repos + output "Installing OSX requirements" + if [[ ! -r $BREW_FILE ]]; then + error "$BREW_FILE does not exist, needed to install brew deps" + exit 1 + fi # brew errors if the package is already installed - for pkg in $(cat $BREW_PKGS); do + for pkg in $(cat $BREW_FILE); do grep $pkg <(brew list) &>/dev/null || { output "Installing $pkg" brew install $pkg >>$LOG @@ -156,22 +203,6 @@ case `uname -s` in ;; esac -cd "$BASE" -output "Cloning mitx, askbot and data repos" -if [[ -d "$BASE/mitx" ]]; then - mv "$BASE/mitx" "${BASE}/mitx.bak.$$" -fi -git clone git@github.com:MITx/mitx.git >>$LOG -if [[ -d "$BASE/askbot-devel" ]]; then - mv "$BASE/askbot-devel" "${BASE}/askbot-devel.bak.$$" -fi -git clone git@github.com:MITx/askbot-devel >>$LOG -if [[ -d "$BASE/data" ]]; then - mv "$BASE/data" "${BASE}/data.bak.$$" -fi -hg clone ssh://hg-content@gp.mitx.mit.edu/data >>$LOG - - output "Installing rvm and ruby" curl -sL get.rvm.io | bash -s stable source $RUBY_DIR/scripts/rvm @@ -181,7 +212,8 @@ source $PYTHON_DIR/bin/activate output "Installing gem bundler" gem install bundler output "Installing ruby packages" -cd $BASE/mitx +# hack :( +cd $BASE/mitx || true bundle install cd $BASE From 6c4a3cf618155ecc18673bb53ddccfb6a81c9297 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Thu, 31 May 2012 14:54:38 -0400 Subject: [PATCH 10/15] updating for coffeescript --- create-dev-env.sh | 5 +++++ install.txt | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/create-dev-env.sh b/create-dev-env.sh index 7190d81a73..a45fc0dba0 100755 --- a/create-dev-env.sh +++ b/create-dev-env.sh @@ -196,6 +196,11 @@ case `uname -s` in output "Installing virtualenv" sudo pip install virtualenv virtualenvwrapper >> $LOG } + command -v coffee &>/dev/null || { + output "Installing coffee script" + curl http://npmjs.org/install.sh | sh + npm install -g coffee-script + } ;; *) error "Unsupported platform" diff --git a/install.txt b/install.txt index 70c8655306..fa82b11a5c 100644 --- a/install.txt +++ b/install.txt @@ -26,6 +26,10 @@ There is also a script "create-dev-env.sh" that automates these steps. d) Install python virtualenv if necessary sudo pip install virtualenv virtualenvwrapper + e) Install coffee script + curl http://npmjs.org/install.sh | sh + npm install -g coffee-script + 3) Install Ubuntu dependencies (Linux users only) sudo apt-get install curl python-virtualenv build-essential python-dev gfortran liblapack-dev libfreetype6-dev libpng12-dev libxml2-dev libxslt-dev yui-compressor coffeescript From 71e25d9b4b677a53a7032ca81e0611a997399d63 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 12:02:40 -0400 Subject: [PATCH 11/15] According to the elementtree spec, elements with no children test as false. We only want to skip checking for module ids if the module is actually not found --- djangoapps/courseware/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index 014f759ed1..8c61e1c121 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -202,7 +202,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"): module = etree.XML(etree.tostring(module_wrapper[0])) # Copy the element out of the tree module_ids = [] - if module: + if module is not None: module_ids = module.xpath("//@id", course=course, chapter=chapter, section=section) From d20147932edff1b78e651e6b163645276ba4f48f Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 1 Jun 2012 12:06:31 -0400 Subject: [PATCH 12/15] Fix problem with sequence navigation on iOS * Add `touch-based-device` class to the when running on iOS. * Do not show the tooltip if we're on the iOS. --- static/coffee/src/main.coffee | 2 ++ static/sass/courseware/_sequence-nav.scss | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/static/coffee/src/main.coffee b/static/coffee/src/main.coffee index 733322b9bb..9f3c759a9a 100644 --- a/static/coffee/src/main.coffee +++ b/static/coffee/src/main.coffee @@ -12,6 +12,8 @@ $ -> window.onTouchBasedDevice = -> navigator.userAgent.match /iPhone|iPod|iPad/i + $('body').addClass 'touch-based-device' if onTouchBasedDevice() + $("a[rel*=leanModal]").leanModal() $('#csrfmiddlewaretoken').attr 'value', $.cookie('csrftoken') diff --git a/static/sass/courseware/_sequence-nav.scss b/static/sass/courseware/_sequence-nav.scss index 0e541e7f07..2be435c350 100644 --- a/static/sass/courseware/_sequence-nav.scss +++ b/static/sass/courseware/_sequence-nav.scss @@ -123,7 +123,7 @@ nav.sequence-nav { background-position: center; } - p { + p { background: #333; color: #fff; display: none; @@ -231,6 +231,10 @@ nav.sequence-nav { } } } + + body.touch-based-device & ol li a:hover p { + display: none; + } } @@ -304,3 +308,4 @@ section.course-content { } } } + From b574dcb8e8b339f9b19a31dfa9ab11dac6046c49 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 12:18:43 -0400 Subject: [PATCH 13/15] Check for None with is rather than == --- djangoapps/courseware/capa/capa_problem.py | 2 +- djangoapps/courseware/capa/inputtypes.py | 2 +- djangoapps/courseware/capa/responsetypes.py | 12 ++++++------ djangoapps/courseware/content_parser.py | 2 +- djangoapps/courseware/grades.py | 2 +- djangoapps/courseware/module_render.py | 2 +- djangoapps/courseware/modules/capa_module.py | 4 ++-- djangoapps/courseware/modules/seq_module.py | 4 ++-- djangoapps/courseware/modules/video_module.py | 2 +- djangoapps/courseware/views.py | 4 ++-- djangoapps/simplewiki/views.py | 2 +- templates/video.html | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/djangoapps/courseware/capa/capa_problem.py b/djangoapps/courseware/capa/capa_problem.py index 565e82a577..4c74d5315f 100644 --- a/djangoapps/courseware/capa/capa_problem.py +++ b/djangoapps/courseware/capa/capa_problem.py @@ -91,7 +91,7 @@ class LoncapaProblem(object): self.problem_id = id self.system = system - if seed != None: + if seed is not None: self.seed = seed if state: diff --git a/djangoapps/courseware/capa/inputtypes.py b/djangoapps/courseware/capa/inputtypes.py index d50e41a5a3..e535ec400e 100644 --- a/djangoapps/courseware/capa/inputtypes.py +++ b/djangoapps/courseware/capa/inputtypes.py @@ -133,7 +133,7 @@ class SimpleInput():# XModule def register_render_function(fn, names=None, cls=SimpleInput): - if names == None: + if names is None: SimpleInput.xml_tags[fn.__name__] = fn else: raise NotImplementedError diff --git a/djangoapps/courseware/capa/responsetypes.py b/djangoapps/courseware/capa/responsetypes.py index 3159b70d5c..d35d526b30 100644 --- a/djangoapps/courseware/capa/responsetypes.py +++ b/djangoapps/courseware/capa/responsetypes.py @@ -109,7 +109,7 @@ class MultipleChoiceResponse(GenericResponse): if rtype not in ["MultipleChoice"]: response.set("type", "MultipleChoice") # force choicegroup to be MultipleChoice if not valid for choice in list(response): - if choice.get("name") == None: + if choice.get("name") is None: choice.set("name", "choice_"+str(i)) i+=1 else: @@ -121,7 +121,7 @@ class TrueFalseResponse(MultipleChoiceResponse): for response in self.xml.xpath("choicegroup"): response.set("type", "TrueFalse") for choice in list(response): - if choice.get("name") == None: + if choice.get("name") is None: choice.set("name", "choice_"+str(i)) i+=1 else: @@ -292,7 +292,7 @@ def sympy_check2(): self.code = '' else: answer_src = answer.get('src') - if answer_src != None: + if answer_src is not None: self.code = open(settings.DATA_DIR+'src/'+answer_src).read() else: self.code = answer.text @@ -418,7 +418,7 @@ class ExternalResponse(GenericResponse): id=xml.get('id'))[0] answer_src = answer.get('src') - if answer_src != None: + if answer_src is not None: self.code = open(settings.DATA_DIR+'src/'+answer_src).read() else: self.code = answer.text @@ -489,7 +489,7 @@ class FormulaResponse(GenericResponse): self.context = context ts = xml.get('type') - if ts == None: + if ts is None: typeslist = [] else: typeslist = ts.split(',') @@ -558,7 +558,7 @@ class SchematicResponse(GenericResponse): answer = xml.xpath('//*[@id=$id]//answer', id=xml.get('id'))[0] answer_src = answer.get('src') - if answer_src != None: + if answer_src is not None: self.code = self.system.filestore.open('src/'+answer_src).read() # Untested; never used else: self.code = answer.text diff --git a/djangoapps/courseware/content_parser.py b/djangoapps/courseware/content_parser.py index 9d8811307f..06c07bff64 100644 --- a/djangoapps/courseware/content_parser.py +++ b/djangoapps/courseware/content_parser.py @@ -126,7 +126,7 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None): child (A) already has that attribute, A will keep the same attribute and all of A's children will inherit A's attribute. This is a recursive call.''' - if (parent_attribute == None): #This is the entry call. Select all elements with this attribute + if (parent_attribute is None): #This is the entry call. Select all elements with this attribute all_attributed_elements = element.xpath("//*[@" + attribute_name +"]") for attributed_element in all_attributed_elements: attribute_value = attributed_element.get(attribute_name) diff --git a/djangoapps/courseware/grades.py b/djangoapps/courseware/grades.py index 2013dc28b5..ca4d00a0db 100644 --- a/djangoapps/courseware/grades.py +++ b/djangoapps/courseware/grades.py @@ -190,7 +190,7 @@ def get_score(user, problem, cache, coursename=None): correct=float(response.grade) # Grab max grade from cache, or if it doesn't exist, compute and save to DB - if id in cache and response.max_grade != None: + if id in cache and response.max_grade is not None: total = response.max_grade else: ## HACK 1: We shouldn't specifically reference capa_module diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 510d26033c..ba550fe935 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -75,7 +75,7 @@ def grade_histogram(module_id): grades = list(cursor.fetchall()) grades.sort(key=lambda x:x[0]) # Probably not necessary - if (len(grades) == 1 and grades[0][0] == None): + if (len(grades) == 1 and grades[0][0] is None): return [] return grades diff --git a/djangoapps/courseware/modules/capa_module.py b/djangoapps/courseware/modules/capa_module.py index b54b028c11..25874c32b5 100644 --- a/djangoapps/courseware/modules/capa_module.py +++ b/djangoapps/courseware/modules/capa_module.py @@ -97,7 +97,7 @@ class Module(XModule): reset_button = False # We don't need a "save" button if infinite number of attempts and non-randomized - if self.max_attempts == None and self.rerandomize != "always": + if self.max_attempts is None and self.rerandomize != "always": save_button = False # Check if explanation is available, and if so, give a link @@ -222,7 +222,7 @@ class Module(XModule): ''' Is the student still allowed to submit answers? ''' if self.attempts == self.max_attempts: return True - if self.close_date != None and datetime.datetime.utcnow() > self.close_date: + if self.close_date is not None and datetime.datetime.utcnow() > self.close_date: return True return False diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index 063c37e5b3..deec191173 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -51,7 +51,7 @@ class Module(XModule): ## Returns a set of all types of all sub-children child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree] - titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") != None]) \ + titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") is not None]) \ for e in self.xmltree] self.contents = [j(self.render_function(e)) for e in self.xmltree] @@ -91,7 +91,7 @@ class Module(XModule): self.position = 1 - if state != None: + if state is not None: state = json.loads(state) if 'position' in state: self.position = int(state['position']) diff --git a/djangoapps/courseware/modules/video_module.py b/djangoapps/courseware/modules/video_module.py index 80a1ce2f80..41c76fc717 100644 --- a/djangoapps/courseware/modules/video_module.py +++ b/djangoapps/courseware/modules/video_module.py @@ -47,7 +47,7 @@ class Module(XModule): self.youtube = xmltree.get('youtube') self.name = xmltree.get('name') self.position = 0 - if state != None: + if state is not None: state = json.loads(state) if 'position' in state: self.position = int(float(state['position'])) diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index 8c61e1c121..0a4fc53fff 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -57,7 +57,7 @@ def profile(request, student_id = None): ''' User profile. Show username, location, etc, as well as grades . We need to allow the user to change some of these settings .''' - if student_id == None: + if student_id is None: student = request.user else: if 'course_admin' not in content_parser.user_groups(request.user): @@ -194,7 +194,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"): else: module_wrapper = dom_module[0] - if module_wrapper == None: + if module_wrapper is None: module = None elif module_wrapper.get("src"): module = content_parser.section_file(user=user, section=module_wrapper.get("src"), coursename=course) diff --git a/djangoapps/simplewiki/views.py b/djangoapps/simplewiki/views.py index 34a81e6b57..167ce27d95 100644 --- a/djangoapps/simplewiki/views.py +++ b/djangoapps/simplewiki/views.py @@ -482,7 +482,7 @@ def check_permissions(request, article, check_read=False, check_write=False, che locked_err = check_locked and article.locked - if revision == None: + if revision is None: revision = article.current_revision deleted_err = check_deleted and not (revision.deleted == 0) if (request.user.is_superuser): diff --git a/templates/video.html b/templates/video.html index 54d6f8fa37..f49b5b56c2 100644 --- a/templates/video.html +++ b/templates/video.html @@ -1,4 +1,4 @@ -% if name is not UNDEFINED and name != None: +% if name is not UNDEFINED and name is not None:

${name}

% endif From bb18c854f79c135b72f3327ca6a3e7280139b193 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 31 May 2012 17:14:34 -0400 Subject: [PATCH 14/15] Trigger a pause event when user click Youtube logo This will make sure that the play button is in the paused state. Fixes https://www.pivotaltracker.com/story/show/26236143 --- static/coffee/spec/modules/video/video_player_spec.coffee | 8 ++++++++ static/coffee/src/modules/video/video_player.coffee | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/static/coffee/spec/modules/video/video_player_spec.coffee b/static/coffee/spec/modules/video/video_player_spec.coffee index 309afcd002..26f5e3b5ed 100644 --- a/static/coffee/spec/modules/video/video_player_spec.coffee +++ b/static/coffee/spec/modules/video/video_player_spec.coffee @@ -126,6 +126,14 @@ describe 'VideoPlayer', -> it 'trigger pause event', -> expect('pause').toHaveBeenTriggeredOn @player + describe 'when the video is unstarted', -> + beforeEach -> + spyOnEvent @player, 'pause' + @player.onStateChange data: YT.PlayerState.UNSTARTED + + it 'trigger pause event', -> + expect('pause').toHaveBeenTriggeredOn @player + describe 'when the video is ended', -> beforeEach -> spyOnEvent @player, 'ended' diff --git a/static/coffee/src/modules/video/video_player.coffee b/static/coffee/src/modules/video/video_player.coffee index 57d7f913b8..28f87b2d53 100644 --- a/static/coffee/src/modules/video/video_player.coffee +++ b/static/coffee/src/modules/video/video_player.coffee @@ -1,5 +1,8 @@ class @VideoPlayer constructor: (@video) -> + # Define a missing constant of Youtube API + YT.PlayerState.UNSTARTED = -1 + @currentTime = 0 @element = $("#video_#{@video.id}") @render() @@ -57,7 +60,7 @@ class @VideoPlayer switch event.data when YT.PlayerState.PLAYING $(@).trigger('play') - when YT.PlayerState.PAUSED + when YT.PlayerState.PAUSED, YT.PlayerState.UNSTARTED $(@).trigger('pause') when YT.PlayerState.ENDED $(@).trigger('ended') From d7043ea27f16be73da1ca579195b7386452ac3bf Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Thu, 31 May 2012 16:33:28 -0400 Subject: [PATCH 15/15] Fix page jumping bug when click on the speeds list --- static/coffee/src/modules/video/video_speed_control.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/coffee/src/modules/video/video_speed_control.coffee b/static/coffee/src/modules/video/video_speed_control.coffee index 203e3677a4..6f7631a0ad 100644 --- a/static/coffee/src/modules/video/video_speed_control.coffee +++ b/static/coffee/src/modules/video/video_speed_control.coffee @@ -10,7 +10,9 @@ class @VideoSpeedControl $(@player).bind('speedChange', @onSpeedChange) @$('.video_speeds a').click @changeVideoSpeed if onTouchBasedDevice() - @$('.speeds').click -> $(this).toggleClass('open') + @$('.speeds').click (event) -> + event.preventDefault() + $(this).toggleClass('open') else @$('.speeds').mouseenter -> $(this).addClass('open')