~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/service.py

  • Committer: David Coles
  • Date: 2010-07-27 04:52:14 UTC
  • Revision ID: coles.david@gmail.com-20100727045214-p32h1kc0gcv48dpr
Worksheets: Strip off whitespace from the end of exercise attempts.

This solves an issue where accidental whitespace in an attempt will cause 
"IndentationError" syntax error (which don't occur when run in console).

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    @require_permission('edit')
57
57
    def PUT(self, req, data):
58
58
        """ Tests the given submission """
 
59
        # Trim off any trailing whitespace (can cause syntax errors in python)
 
60
        # While technically this is a user error, it causes a lot of confusion 
 
61
        # for student since it's "invisible".
 
62
        code = data['code'].rstrip()
 
63
 
59
64
        test_results = ivle.worksheet.utils.test_exercise_submission(
60
65
            req.config, req.user, self.context.worksheet_exercise.exercise,
61
 
            data['code'])
 
66
            code)
62
67
 
63
68
        attempt = ivle.database.ExerciseAttempt(user=req.user,
64
69
            worksheet_exercise = self.context.worksheet_exercise,
65
70
            date = datetime.datetime.now(),
66
71
            complete = test_results['passed'],
67
 
            text = unicode(data['code'])
 
72
            text = unicode(code)
68
73
        )
69
74
 
70
75
        req.store.add(attempt)