360
360
return {"result": "ok"}
362
@named_operation('set_sequence')
363
def seq_sequence(self, req, worksheet_list):
364
"""Takes a list of worksheet-seq_no pairs and updates their
365
corresponding Worksheet objects to match."""
367
for worksheetid, seq_no in worksheet_list:
368
worksheet = req.store.find(Worksheet,
369
Worksheet.offering_id == self.context.id,
370
Worksheet.identifier == worksheetid).one()
371
if worksheet is None:
372
raise NotFound(worksheet)
373
worksheet.seq_no = seq_no
362
@named_operation('edit')
363
def move_up(self, req, worksheetid):
364
"""Takes a list of worksheet-seq_no pairs and updates their
365
corresponding Worksheet objects to match."""
367
worksheet_below = req.store.find(Worksheet,
368
Worksheet.offering_id == self.context.id,
369
Worksheet.identifier == unicode(worksheetid)).one()
370
if worksheet_below is None:
371
raise NotFound('worksheet_below')
372
worksheet_above = req.store.find(Worksheet,
373
Worksheet.offering_id == self.context.id,
374
Worksheet.seq_no == (worksheet_below.seq_no - 1)).one()
375
if worksheet_above is None:
376
raise NotFound('worksheet_above')
378
worksheet_below.seq_no = worksheet_below.seq_no - 1
379
worksheet_above.seq_no = worksheet_above.seq_no + 1
381
return {'result': 'ok'}
383
@named_operation('edit')
384
def move_down(self, req, worksheetid):
385
"""Takes a list of worksheet-seq_no pairs and updates their
386
corresponding Worksheet objects to match."""
388
worksheet_above = req.store.find(Worksheet,
389
Worksheet.offering_id == self.context.id,
390
Worksheet.identifier == unicode(worksheetid)).one()
391
if worksheet_above is None:
392
raise NotFound('worksheet_below')
393
worksheet_below = req.store.find(Worksheet,
394
Worksheet.offering_id == self.context.id,
395
Worksheet.seq_no == (worksheet_above.seq_no + 1)).one()
396
if worksheet_below is None:
397
raise NotFound('worksheet_above')
399
worksheet_below.seq_no = worksheet_below.seq_no - 1
400
worksheet_above.seq_no = worksheet_above.seq_no + 1
375
402
return {'result': 'ok'}