Add Code Requests for Single Component Courses
This tool can distrinbute add codes for courses that have only a single component (i.e. lecture or lab, but not both).
Installing and Configuring
To set it up on a new machine, make sure it is running the Apache web server with CGI enabled.
- Put the file "addcodes.py" into the CGI-Executable folder.
- Put the files index.html, spinner.gif, md5.js and detector.js into a foler that is web accessible
- Open the file index.html and search for "action=". Set the action to point at the web location of addcodes.py in the CGI-Executable directory
- Install the required python modules mechanize and beautiful soup.
- Edit the lines directly below "# define variables that will be initialized outside of the constructor":
Put in the SJSU IDs of anyone who should have administrator access allowing them to request multiple add codes without being subject to the normal waiting period.
contains the file path to where the list of add codes will be stored. If this is in the webserver path it should be in a password protected folder
contains the file system path to where teh web page index.html is located.
points to where the roster that is downloaded from peoplesoft is (it only needs to be present when itializing the system before the semester)
self.gracePeriod=datetime.timedelta(minutes=60) #Time before the enrollment was updated that add codes given out should be considered as students who are not counted yet in the published enrollment data
When checking if asection has availability any add codes given out for this length of time BEFORE the last published update on the section's enrollment are included in teh number of students who may be adding the section. If the total number of students in teh section and those who may be adding (i.e. who have been given an add code since the last update of the publsihed information) meets or exceeds the capacity a code will not be given out.
self.sessionLength=datetime.timedelta(minutes=10) # Time delay until the same computer can be used to get another add code
This determines how long to lock out a student frmo getting another add code using the same computer.
Setting it up before the semester
To configure the tool you will need terminal access to the web-server, and should wait until advanced registration has ended. For the Fall this is typically around August 15th, for the spring January 15th is typical. See the Registration Calendar for exact dates.
If all of this has worked no further configuration should be necessary.
- Open index.html and search for "coursesToAdminister" add a line of the form
for each course number that this tool should be giving out add codes for.
- Open addcodes.py in the CGI directory and search for the line with "closedSections=" replace it with the following "closedSections="
- Remove last semesters data (if there is any) by opening a terminal on the webserver and entering
substituting the file location of your data folder as necessary.
- Download the latest class roster from peoplesoft as "CLASS ROSTER.csv" and put it in the location specified by self.rosterFile (i.e. the Downloads folder)
- Generate the required data files and set their permissions to be read/writable by the webserver. From the terminal execute:
sudo /Library/Server/Web/Data/CGI-Executables/addcodes.py; sudo chmod 0666 /Library/Server/Web/Data/Sites/Spectrum/AddCodes/Data/addcodes*;open /Library/Server/Web/Data/Sites/Spectrum/AddCodes/Data/addcodes.txt
substituting the location of the cgi executable and the dataFolder as necessary. You will be prompted for your password.
You should get a response of the form "You didn't enter your name. Please try again." and a list of add codes should be open in a text editor.
- Test the system by requesting an add code from the web page index.html. Your entry should be recorded in a line of the file addcodes.txt in the data folder and should look something like
50W,7,171072,assigned to Peter Beyersdorf (001234567) at 21:27:23 on 12/30/2010,2af1b6bdcbee43debfe162142f1ec287
- Edit the file to remove the data that was written so that it has the form
50W,7,171072,, to reenable this particular add code. This isn't necessary but will help ensure there are enough add codes and that the test doesn't cause the section availabilty to appear less than it actually is.
What to do during the semester
No maintenance should be required during the semster, although it is a good idea to periodically check that you are able to get an add code if you request it, and that student information is getting recorded in the addcodes.txt file in the data folder.
How it works
This outline describes the steps taken by the cgi executable when called on to give an add code. Basically it checks the enrollment of the course form the last update published on the web, adds to that the number of add codes it has given out since it was published (including a 60 minute grace period for codes given out just before the last update was published). If the user hasn't requested an add code in the last 10 minutes, and if the section has availability it will give an add code to the user and record the user information in the file addcodes.txt int he Data folder.
The steps executed by the cgi executable are as follows:
- Define file locations:
- self.rosterFile="/Users/peteman/Downloads/CLASS ROSTER.csv"
- Check the course and section being requested, if the ID of the user is '0' regenerate the enrollment file addcodes-enrollment.txt in the data folder
- Read enrollment file addcodes-enrollment.txt in the data folder
use enrollment file to get parameters of the class being requested, using the URL of the web page with enrollment data stored in the enrollment file.
- Regenerate the enrollment file if necessary using links on "http://info.sjsu.edu/web-dbgen/soc-spring-courses/all-departments.html" or "http://info.sjsu.edu/web-dbgen/soc-fall-courses/all-departments.html" depending on the semester
- Check if space is available in desired section by reading the enrollment file addcodes-enrollment.txt in the data folder
- Use enrollment file to get parameters of the class being requested, using the URL of the web page with enrollment data stored in the enrollment file.
- Check that the name and ID of the user were submitted
- Check that the requesting computer has not been used to get an add code in the last 10 minutes unless the requesting user is an "administrator"
- Write the changes in the file addcodes.txt in the data folder
- Print out results to the user
- Update the initialization file used to create the web page, determining if pace is available based on the number of add codes that have been given since 1 hour BEFORE the last update of the web page listing the enrollment values. If space isn't availbale in a section the link for that section will not be clickable.