107
107
problems_done = 0
108
108
problems_total = 0
109
109
for worksheet in ctx['worksheets']:
110
stored_worksheet = ivle.database.Worksheet.get_by_name(req.store,
111
self.context.subject.code, worksheet.id)
110
stored_worksheet = req.store.find(DBWorksheet,
111
DBWorksheet.offering_id == self.context.id,
112
DBWorksheet.name == worksheet.id).one()
112
113
# If worksheet is not in database yet, we'll simply not display
113
114
# data about it yet (it should be added as soon as anyone visits
114
115
# the worksheet itself).
206
207
ctx['year'] = self.year
207
208
ctx['worksheetstream'] = genshi.Stream(list(genshi.XML(worksheetfile)))
209
#TODO: Replace this with a nice way, possibly a match template
210
generate_worksheet_data(ctx, req)
210
generate_worksheet_data(ctx, req, self.context)
212
212
update_db_worksheet(req.store, self.context.offering.subject.code, self.worksheetname,
213
213
worksheetmtime, ctx['exerciselist'])
291
291
# This function runs through the worksheet, to get data on the exercises to
292
292
# build a Table of Contents, as well as fill in details in ctx
293
def generate_worksheet_data(ctx, req):
293
def generate_worksheet_data(ctx, req, worksheet):
294
294
"""Runs through the worksheetstream, generating the exericises"""
295
295
ctx['exercises'] = []
296
296
ctx['exerciselist'] = []
305
305
if attr[0] == 'optional':
306
306
optional = attr[1] == 'true'
307
307
# Each item in toc is of type (name, complete, stream)
308
ctx['exercises'].append(present_exercise(req, src))
308
ctx['exercises'].append(present_exercise(req, src, worksheet))
309
309
ctx['exerciselist'].append((src, optional))
310
310
elif data[0] == 'worksheet':
311
311
ctx['worksheetname'] = 'bob'
339
339
#TODO: This needs to be re-written, to stop using minidom, and get the data
340
340
# about the worksheet directly from the database
341
def present_exercise(req, exercisesrc):
341
def present_exercise(req, exercisesrc, worksheet):
342
342
"""Open a exercise file, and write out the exercise to the request in HTML.
343
343
exercisesrc: "src" of the exercise file. A path relative to the top-level
344
344
exercises base directory, as configured in conf.
362
362
#TODO: Replace calls to minidom with calls to the database directly
363
363
curctx['exercise'] = exercise
364
364
if exercise.description is not None:
365
curctx['description'] = genshi.XML('<div id="description">' + exercise.description + '</div>')
365
curctx['description'] = genshi.XML('<div id="description">' +
366
exercise.description + '</div>')
367
368
curctx['description'] = None
369
370
# If the user has already saved some text for this problem, or submitted
370
371
# an attempt, then use that text instead of the supplied "partial".
371
save = req.store.find(ExerciseSave, ExerciseSave.exercise_id == exercise.id).one()
372
save = req.store.find(ExerciseSave,
373
ExerciseSave.exercise_id == exercise.id,
374
ExerciseSave.worksheetid == worksheet.id,
375
ExerciseSave.user_id == req.user.id
372
377
# Also get the number of attempts taken and whether this is complete.
373
378
complete, curctx['attempts'] = \
374
ivle.worksheet.get_exercise_status(req.store, req.user, exercise)
379
ivle.worksheet.get_exercise_status(req.store, req.user,
375
381
if save is not None:
376
curctx['exercisepartial'] = save.text
382
curctx['exercisesave'] = save.text
384
curctx['exercisesave']= exercise.partial
377
385
curctx['complete'] = 'Complete' if complete else 'Incomplete'
378
386
curctx['complete_class'] = curctx['complete'].lower()
403
411
the existing data. If the worksheet does not yet exist, and assessable
404
412
is omitted, it defaults to False.
406
worksheet = ivle.database.Worksheet.get_by_name(store, subject,
414
""" worksheet = ivle.database.Worksheet.get_by_name(store, subject,
409
417
updated_database = False
437
445
worksheetexercise = ivle.database.WorksheetExercise(
438
446
worksheet=worksheet, exercise=exercise, optional=optional)
442
450
class Plugin(ViewPlugin, MediaPlugin):