311
311
req.throw_error(req.HTTP_NOT_FOUND,
312
312
"Worksheet file not found.")
313
worksheetmtime = datetime.datetime.fromtimestamp(worksheetmtime)
313
worksheetmtime = datetime.fromtimestamp(worksheetmtime)
315
315
worksheetdom = minidom.parse(worksheetfile)
316
316
worksheetfile.close()
638
638
worksheet = ivle.database.Worksheet.get_by_name(store, subject,
640
db_mtime = worksheet.mtime if worksheet is not None else None
641
if db_mtime is None or file_mtime > db_mtime:
644
db.create_worksheet(subject, worksheetname, exercise_list,
641
updated_database = False
642
if worksheet is None:
643
# If assessable is not supplied, default to False.
644
if assessable is None:
646
# Create a new Worksheet
647
worksheet = ivle.database.Worksheet(subject=subject,
648
name=worksheetname, assessable=assessable, mtime=datetime.now())
650
updated_database = True
652
if file_mtime > worksheet.mtime:
653
# File on disk is newer than database. Need to update.
654
worksheet.mtime = datetime.now()
655
if exercise_list is not None:
656
# exercise_list is supplied, so delete any existing problems
657
worksheet.remove_all_exercises(store)
658
if assessable is not None:
659
worksheet.assessable = assessable
660
updated_database = True
662
if updated_database and exercise_list is not None:
663
# Insert each exercise into the worksheet
664
for exercise_tuple in exercise_list:
665
if isinstance(exercise_tuple, tuple):
666
exercise_name = exercise_tuple[0]
668
optional = exercise_tuple[1]
672
exercise_name = exercise_tuple
674
# Get the Exercise from the DB
675
# XXX What if this fails?
676
exercise = ivle.database.Exercise.get_by_name(store,exercise_name)
677
# Create a new binding between the worksheet and the exercise
678
worksheetexercise = ivle.database.WorksheetExercise(
679
worksheet=worksheet, exercise=exercise, optional=optional)