Created
February 9, 2011 21:53
-
-
Save nathanvan/819384 to your computer and use it in GitHub Desktop.
Examples of of a controller and view for the web2py + GAE + AMT application I wrote.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Details here: http://nathanvan.wordpress.com/2011/02/09/general-purpose-amt-webapp-based-on-web2py/ | |
# I realize that this approach creates a lot of boilerplate code, but | |
# it gives me the flexibility I need to make a bunch of different versions | |
# without bloating a large assignment function. At this point, I just | |
# need the darn thing to work! | |
# -- nathanvan 1/20/2011 | |
import urllib | |
def grade6_test2_problem35_partA_version1(): | |
###################### | |
# build the form | |
###################### | |
# Only have one image for this rubric. | |
studentImage = "../static/locationOfImage/%s.png" % request.get_vars.studentIds | |
likertExplanation = ['Everything is correct.', | |
'Minor errors are present.', | |
'The explanation is wrong.', | |
'The explanation is either blank or can\'t be read.'] | |
likertRightAnswer = ['Yes', 'No', 'Impossible to tell'] | |
form = SQLFORM.factory( | |
Field('explanation', | |
widget=SQLFORM.widgets.radio.widget, | |
requires=IS_IN_SET(likertExplanation, | |
error_message=T('Please choose a rating for the explanation.')) | |
), | |
Field('rightAnswer', | |
widget=horizontal_radios, | |
requires=IS_IN_SET(likertRightAnswer, | |
error_message=T('Please choose a response.'))), | |
Field('comment', widget=SQLFORM.widgets.text.widget), | |
hidden={'timestart':request.get_vars.timestart, | |
'assignmentId':request.get_vars.assignmentId, | |
'experimentId':request.get_vars.experimentId, | |
'workerId':request.get_vars.workerId, | |
'studentIds':request.get_vars.studentIds, | |
'rubricCode':request.get_vars.rubricCode, | |
'studentIds':request.get_vars.studentIds, | |
'width':'tmp', | |
'height':'tmp', | |
'element':'tmp', | |
'value':'tmp'} | |
) | |
if form.accepts(request.vars): #, session): | |
###################### | |
# do the grading and send the results to the commit step | |
###################### | |
rightAnswer = request.post_vars.rightAnswer | |
explanation = request.post_vars.explanation | |
subscore1 = 0 | |
if rightAnswer == likertRightAnswer[0]: | |
#Yes | |
subscore1 = 1 | |
elif rightAnswer == likertRightAnswer[1]: | |
#No | |
subscore1 = 0 | |
elif rightAnswer == likertRightAnswer[2]: | |
#Impossible to tell | |
subscore1 = None | |
if explanation == likertExplanation[0]: | |
#'Everything is correct.', | |
subscore2 = 1 | |
elif explanation == likertExplanation[1]: | |
#'Minor errors are present.', | |
subscore2 = .5 | |
elif explanation == likertExplanation[2]: | |
#'The explanation is wrong.', | |
subscore2 = 0 | |
elif explanation == likertExplanation[3]: | |
#'The explanation is either blank or can\'t be read.'] | |
subscore2 = None | |
else: | |
return BEAUTIFY('The explanation "%s" did not match an entry on the likert scale.'%explanation) | |
if subscore1 != None and subscore2 != None: | |
subscore = subscore1 + subscore2 | |
else: | |
subscore = None | |
#Build the forwarding packet. See the bottom of landing(): for an explanation of this coding pattern. | |
# the following lists just have single entries since this rubric did not repeat students. | |
extraURLvariables = {'studentIds':request.post_vars.studentIds, | |
'rawAnswers':"%s:%s" % (rightAnswer, explanation), | |
'subscores':subscore, | |
} | |
extraURLvariables.update(request.post_vars) | |
form_data = urllib.urlencode(extraURLvariables) | |
redirect( '../default/commitRubric?%s' % form_data ) | |
elif form.errors: | |
#response.flash = 'form has errors <\br>%s' % BEAUTIFY(form.errors) | |
response.flash = 'Please correct the errors in the form.' | |
return dict(form=form,studentImage=studentImage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{extend 'rubricShell.html'}} | |
<h3>Please grade the following math question</h3> | |
<p><img alt="" border=2 src="{{=studentImage}}" /></p> | |
{{=form.custom.begin}} | |
{{ ## The following three calls set up the tracking of users clicking on form elements. }} | |
{{form.element(_name='rightAnswer')['_onClick']='tracktime("rightAnswer");'}} | |
{{form.element(_name='explanation')['_onClick']='tracktime("explanation");'}} | |
{{form.element(_name='comment')['_onClick']='tracktime("comment");'}} | |
{{# The <b>{{=prevMode}}</b> are for the informed consent during preview mode.}} | |
<b>{{=prevMode}}</b>Did the student give the correct answer (XX pieces of ribbon)? | |
<div>{{=form.custom.widget.rightAnswer}}</div> | |
<br /><b>{{=prevMode}}</b>Rate the quality of the student's explanation. | |
<div>{{=form.custom.widget.explanation}}</div> | |
<br /><b>{{=prevMode}}</b>Please provide any comments you may have below, we appreciate your input! | |
<div>{{=form.custom.widget.comment}}</div> | |
{{ if request.get_vars.assignmentId != 'ASSIGNMENT_ID_NOT_AVAILABLE':}} | |
{{=form.custom.submit}} | |
{{else:}} | |
<input type='submit' value='Submit' disabled> | |
{{pass}} | |
{{=form.custom.end}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment