public
Last active

Examples of of a controller and view for the web2py + GAE + AMT application I wrote.

  • Download Gist
grade6.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
# 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)
grade6_test2_problem35_partA_version1.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
{{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}}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.