This package provides the code necessary to deploy an online homework system on Stanford's AFS servers. Check out a demo here (SUNet ID required.)
The code is organized into three directories:
- cgi-bin/ contains a routing script that handles incoming client-side requests and calls the appropriate Python routines.
- ohms/ contains the Python package that does most of the server-side processing.
All data is written to and read from spreadsheets hosted on Google Drive. You will be storing the password to this account in a file on the server, so you are highly advised against using your personal Gmail account. Please either make a new Gmail account or consider using your Stanford Google Drive account (more details here. (To set the password on your Stanford Google Drive account, log into Google Drive and change the password.)
OHMS is written primarily in Python, and is suited to work with Python version 2.7. It also depends on the following Python packages:
- GData Python Client (install by typing "pip install gdata" on Unix machine)
- Flask Web Server (ONLY if you plan to develop on your local machine: install by typing "pip install Flask")
Please note that GData is already installed on the Stanford AFS servers.
- ohms/config.py MUST be edited with the details of your Google account (so that data can be read/written).
That's it. You should be able to start a web server running OHMS by typing "python server.py" from the command line. You can view OHMS by navigating your browser to http://127.0.0.1:5000/. (Remember that this only works if Flask has been installed.)
The cgi-bin/ohms/ and WWW/ directories come with .htaccess files which allow access to anyone in the Stanford community. To restrict access to your class roster, copy the .htaccess file in the WWW/restricted directory of your AFS course website.
Other than this, there are three configuration files
that may need to be edited:
ohms/config.py MUST be edited with the details of your Google account (so that data can be read/written).
PATH_TO_OHMS in cgi-bin/ohms/route.cgi only needs to be edited if you plan to install OHMS somewhere other than the default location (see instructions below
ROUTE_FILE in WWW/js/namespace.js only needs to be edited if you plan to install the WWW files to somewhere other than WWW/ohms/ and the cgi-bin files to somewhere other than cgi-bin/ohms/.
NOTE: The "user" which processes the CGI scripts takes the root directory of the web server as its home (i.e., ~/). For example, for the course Stats 60, ~/ would correspond to /afs/ir/class/stats60. Hereafter, we will refer to this directory as $HOME, although note that if you are logged into AFS as yourself, $HOME may already be set to your user home directory.
Follow these steps to install OHMS:
Install OHMS Python package. Simply copy the ohms/ directory to $HOME/. We also recommend that you copy ohms_admin.py to the same directory. This contains the utilities for generating databases, computing student's scores, etc.
Copy the contents of the cgi-bin/ directory to $HOME/cgi-bin/.
Copy the contents of the WWW/ directory to $HOME/WWW/ohms (recommended).
The CGI server needs permissions to execute all scripts inside $HOME. Give it the necessary permissions by going to $HOME and executing
fs sa -dir `find . -type d -print` -acl class-CLASSID-TERM.cgi rlidwk
replacing CLASSID by the appropriate ID (e.g., "stats60") and TERM by the appropriate 4-digit term number. If you are not sure of the term number, type "fs la" at the command line. This will show a list of users, one of which should be the CGI user.
- You may also want to prevent users from accessing the OHMS files. (Right now, they have read permissions.) Go to $HOME/ohms/ and execute
fs sa -dir `find . -type d -print` -acl system:anyuser none
exactly as written.
You should be all ready to go! The homework files are located in the homeworks/ directory of the OHMS Python package (i.e., $HOME/ohms/homeworks/). If you write a file, it should automatically show up when you point your web browser to OHMS. Right now, only the example homeworks should show up.
Unfortunately, you still won't be able to submit any answers to homeworks because the database is not set up yet. To do this, go to $HOME/local/lib/python and run
Choose Option 2 and type in Example_Homework. This will set up a database for Example_Homework in your Google Drive account (check for yourself!). Once the setup is complete, you should be able to submit responses for Example_Homework to the spreadsheet. Repeat for Example_Homework_2 and for any homeworks that you may write.