Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit e13503c

Browse files
committed
Let students score their own assignments
1 parent 4b76b25 commit e13503c

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

controllers/assignments.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,15 @@ def student_autograde():
348348
This is a safe endpoint that students can call from the assignment page
349349
to get a preliminary grade on their assignment.
350350
"""
351-
pass
351+
assignment_id = request.vars.assignment_id
352+
timezoneoffset = session.timezoneoffset if 'timezoneoffset' in session else None
353+
assignment = db(db.assignments.id == assignment_id).select().first()
354+
if assignment:
355+
count = do_autograde(assignment, auth.user.course_id, auth.user.course_name,
356+
auth.user.username, None, 'false', timezoneoffset, db, settings)
357+
return json.dumps({'message': "autograded {} items".format(count)})
358+
else:
359+
return json.dumps({'success': False, 'message': "Could not find this assignment -- This should not happen"})
352360

353361

354362
@auth.requires(lambda: verifyInstructorStatus(auth.user.course_name, auth.user), requires_login=True)
@@ -553,15 +561,13 @@ def doAssignment():
553561
get_course_url('_images/'))
554562
else:
555563
htmlsrc = None
556-
if assignment['released']:
557-
# get score and comment
558-
grade = db((db.question_grades.sid == auth.user.username) &
559-
(db.question_grades.course_name == auth.user.course_name) &
560-
(db.question_grades.div_id == q.questions.name)).select().first()
561-
if grade:
562-
score, comment = grade.score, grade.comment
563-
else:
564-
score, comment = 0, 'ungraded'
564+
565+
# get score and comment
566+
grade = db((db.question_grades.sid == auth.user.username) &
567+
(db.question_grades.course_name == auth.user.course_name) &
568+
(db.question_grades.div_id == q.questions.name)).select().first()
569+
if grade:
570+
score, comment = grade.score, grade.comment
565571
else:
566572
score, comment = 0, 'ungraded'
567573

@@ -633,7 +639,9 @@ def doAssignment():
633639
course_id=auth.user.course_name,
634640
readings=readings,
635641
questions_score=questions_score,
636-
readings_score=readings_score)
642+
readings_score=readings_score,
643+
student_id=auth.user.username,
644+
released=assignment['released'])
637645

638646

639647
def chooseAssignment():

static/js/selfgrade.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function selfGrade(assignment_id, student_id) {
2-
var enforceDeadline = false // for now, don't enforce assignment deadlines for self-grading in Coursera MOOC; should be taken from config
2+
var enforceDeadline = false; // for now, don't enforce assignment deadlines for self-grading in Coursera MOOC; should be taken from config
33
jQuery.ajax({
4-
url: eBookConfig.autogradingURL,
4+
url: eBookConfig.app + '/assignments/student_autograde',
55
type: "POST",
66
dataType: "JSON",
77
data: {

views/assignments/doAssignment.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ <h5 style='text-align:center;'>Not yet graded</h5>
7272
</div>
7373
{{pass}}
7474
</div>
75-
{{ if settings.coursera_mode: }}
75+
76+
{{ if not released: }}
7677
<div style="text-align:center">
77-
<button class="btn btn-lg buttonAskCompletion" id="gradeMeButton"> Grade Me</button>
78+
<button class="btn btn-lg buttonAskCompletion" id="gradeMeButton">Score Me</button>
79+
<p><strong>Warning:</strong> Scores for problems that you self grade are unofficial.
80+
Some problems will need to be manually graded, and your instructor may have requirements that cannot be autograded.
81+
No deadlines are enforced when self grading, but your instructor may penalize you
82+
for late work.</p>
7883
</div>
7984
{{ pass }}
8085
</div>
@@ -108,15 +113,16 @@ <h5 style='text-align:center;'>Not yet graded</h5>
108113
let change = $.parseHTML(unescapedhtml, keepScripts=true);
109114
$div.append(change);
110115
}
111-
{{ if settings.coursera_mode: }}
116+
112117

113118
$("#gradeMeButton").on("click", function(){
114119
$('#gradeMeButton').css('visibility', 'hidden');
115-
selfGrade({{=assignment['id']}}, {{=student_id}})});
116-
{{ pass }}
120+
selfGrade({{=assignment['id']}}, '{{=student_id}}')});
121+
117122

118123

119124

120125
</script>
126+
<script src="/runestone/static/js/selfgrade.js" type="text/javascript"></script>
121127
{{end}}
122128

0 commit comments

Comments
 (0)