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

« back to all changes in this revision

Viewing changes to ivle/worksheet.py

  • Committer: William Grant
  • Date: 2009-01-20 05:03:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090120050355-1tm3j13zazd9ik32
ivle.worksheet: Add a save_exercise function.
www/apps/tutorialservice: Import db.TIMESTAMP_FORMAT locally.
    Remove last reference to ivle.db, replacing it with save_exercise.

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