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

« back to all changes in this revision

Viewing changes to ivle/worksheet.py

ivle.webapp.testing: Add, with fake request and user.
ivle.webapp.base.test: Add! Test the JSONRESTView, using the new mocks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
    return _get_exercise_attempts(store, user, exercise, as_of,
145
145
        allow_inactive).first()
146
146
 
 
147
def save_exercise(store, user, exercise, text, date):
 
148
    """Save an exercise for a user.
 
149
 
 
150
    Given a store, User, Exercise and text and date, save the text to the
 
151
    database. This will create the ExerciseSave if needed.
 
152
    """
 
153
    saved = store.find(ivle.database.ExerciseSave,
 
154
                ivle.database.ExerciseSave.user_id == user.id,
 
155
                ivle.database.ExerciseSave.exercise_id == exercise.id).one()
 
156
    if saved is None:
 
157
        saved = ivle.database.ExerciseSave(user=user, exercise=exercise)
 
158
        store.add(saved)
 
159
 
 
160
    saved.date = date
 
161
    saved.text = text
 
162
 
147
163
def calculate_score(store, user, worksheet):
148
164
    """
149
165
    Given a storm.store, User, Exercise and Worksheet, calculates a score for