305
305
return {"result": "ok"}
307
class OfferingRESTView(JSONRESTView):
308
"""View used to update Offering and create Worksheets."""
307
class WorksheetsRESTView(JSONRESTView):
308
"""View used to update and create Worksheets."""
310
310
def get_permissions(self, user):
311
311
# XXX: Do it properly.
338
338
@named_operation('add_worksheet')
339
def add_worksheet(self,req, identifier, name, assessable, data, format):
339
def add_worksheet(self, req, identifier, name, assessable, data, format):
340
340
"""Takes worksheet data and adds it."""
342
342
new_worksheet = Worksheet()
343
new_worksheet.seq_no = self.context.worksheets.count()
344
# Setting new_worksheet.offering implicitly adds new_worksheet,
345
# hence worksheets.count MUST be called above it
344
346
new_worksheet.offering = self.context
345
347
new_worksheet.identifier = unicode(identifier)
346
348
new_worksheet.name = unicode(name)
347
349
new_worksheet.assessable = self.convert_bool(assessable)
348
350
new_worksheet.data = unicode(data)
349
351
new_worksheet.format = unicode(format)
350
new_worksheet.seq_no = self.context.worksheets.count()
353
# This call is added for clarity, as the worksheet is implicitly added.
351
354
req.store.add(new_worksheet)
353
356
generate_exerciselist(new_worksheet, req, data)
355
358
return {"result": "ok"}
360
@named_operation('set_sequence')
361
def seq_sequence(self, req, worksheet_list):
362
"""Takes a list of worksheet-seq_no pairs and updates their
363
corresponding Worksheet objects to match."""
365
for worksheetid, seq_no in worksheet_list:
366
worksheet = req.store.find(Worksheet,
367
Worksheet.offering_id == self.context.id,
368
Worksheet.identifier == worksheetid).one()
369
if worksheet is None:
370
raise NotFound(worksheet)
371
worksheet.seq_no = seq_no
373
return {'result': 'ok'}