~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:
28
28
from ivle.database import Exercise, ExerciseAttempt, ExerciseSave, Worksheet, \
29
29
                          Offering, Subject, Semester, User, WorksheetExercise
30
30
import ivle.worksheet.utils
31
 
from ivle.webapp.base.rest import (JSONRESTView, named_operation,
 
31
from ivle.webapp.base.rest import (JSONRESTView, write_operation,
32
32
                                   require_permission)
33
33
from ivle.webapp.errors import NotFound
34
34
 
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)
91
96
class WorksheetExerciseRESTView(JSONRESTView):
92
97
    '''REST view of a worksheet exercise.'''
93
98
 
94
 
    @named_operation('view')
 
99
    @write_operation('view')
95
100
    def save(self, req, text):
96
101
        # Find the appropriate WorksheetExercise to save to. If its not found,
97
102
        # the user is submitting against a non-existant worksheet/exercise
118
123
class WorksheetsRESTView(JSONRESTView):
119
124
    """View used to update and create Worksheets."""
120
125
 
121
 
    @named_operation('edit_worksheets')
 
126
    @write_operation('edit_worksheets')
122
127
    def move_up(self, req, worksheetid):
123
128
        """Takes a list of worksheet-seq_no pairs and updates their 
124
129
        corresponding Worksheet objects to match."""
139
144
        
140
145
        return {'result': 'ok'}
141
146
 
142
 
    @named_operation('edit_worksheets')
 
147
    @write_operation('edit_worksheets')
143
148
    def move_down(self, req, worksheetid):
144
149
        """Takes a list of worksheet-seq_no pairs and updates their 
145
150
        corresponding Worksheet objects to match."""