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

« back to all changes in this revision

Viewing changes to ivle/webapp/tutorial/__init__.py

Improve the worksheet/exercise authoring experience a little.

Show diffs side-by-side

added added

removed removed

Lines of Context:
460
460
        ctx['exercise_fragment'] = present_exercise(
461
461
            req, self.context.id)['stream']
462
462
        ctx['ExerciseEditView'] = ExerciseEditView
 
463
        ctx['ExerciseDeleteView'] = ExerciseDeleteView
463
464
 
464
465
 
465
466
class ExerciseEditView(XHTMLView):
480
481
        ctx['var_types'] = {
481
482
            'var': 'variable',
482
483
            'arg': 'function argument',
483
 
            'exception': 'exception',
 
484
            # XXX: wgrant 2010-01-29 bug=514160: Need to
 
485
            # restore support for this.
 
486
            #'exception': 'exception',
484
487
            }
485
488
        ctx['part_types'] = {
486
489
            'stdout': 'standard output',
503
506
        # If post, delete the exercise, or display a message explaining that
504
507
        # the exercise cannot be deleted
505
508
        if req.method == 'POST':
506
 
            ctx['method'] = 'POST'
507
509
            try:
508
510
                self.context.delete()
509
 
                ctx['deleted'] = True
510
 
            except:
511
 
                ctx['deleted'] = False
 
511
                self.template = 'templates/exercise_deleted.html'
 
512
            except Exception:
 
513
                self.template = 'templates/exercise_undeletable.html'
512
514
 
513
515
        # If get, display a delete confirmation page
514
516
        else:
515
 
            ctx['method'] = 'GET'
516
517
            if self.context.worksheet_exercises.count() is not 0:
517
 
                ctx['has_worksheets'] = True
518
 
            else:
519
 
                ctx['has_worksheets'] = False
 
518
                self.template = 'templates/exercise_undeletable.html'
 
519
 
520
520
        # Variables for the template
521
521
        ctx['exercise'] = self.context
522
 
        ctx['path'] = "/+exercises/" + self.context.id + "/+delete"
523
522
 
524
523
class ExerciseAddView(XHTMLView):
525
524
    """View for creating a new exercise."""
551
550
    
552
551
    def populate(self, req, ctx):
553
552
        self.plugin_styles[Plugin] = ['exercise_admin.css']
 
553
        ctx['req'] = req
554
554
        ctx['exercises'] = req.store.find(Exercise).order_by(Exercise.id)
555
 
        ctx['mediapath'] = media_url(req, Plugin, 'images/')
556
555
 
557
556
 
558
557
class Plugin(ViewPlugin, MediaPlugin):