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

« back to all changes in this revision

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

  • Committer: Nick Chadwick
  • Date: 2009-03-08 02:28:18 UTC
  • mto: (1099.1.227 exercise-ui)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090308022818-4iaouo258lq7nvq8
Added a listing of all exercises

Show diffs side-by-side

added added

removed removed

Lines of Context:
519
519
        
520
520
        ctx['test_types'] = ('norm', 'check')
521
521
 
 
522
class ExerciseDeleteView(XHTMLView):
 
523
    """View for confirming the deletion of an exercise."""
 
524
    
 
525
    permission = 'edit'
 
526
    template = 'template/exercise_delete.html'
 
527
    
 
528
    def __init__(self, req, exercise):
 
529
        self.context = req.store.find(Exercise,
 
530
            Exercise.id == exercise).one()
 
531
        
 
532
        if self.context is None:
 
533
            raise NotFound()
 
534
        
 
535
    def populate(self, req, ctx):
 
536
        ctx['exercise'] = self.context
 
537
        
 
538
        if self.context.worksheet_exercises.count() is not 0:
 
539
            ctx['hasworksheets'] = True
 
540
 
 
541
class ExercisesView(XHTMLView):
 
542
    """View for seeing the list of all exercises"""
 
543
    
 
544
    permission = 'edit'
 
545
    template = 'templates/exercises.html'
 
546
    
 
547
    def authorize(self, req):
 
548
        for offering in req.store.find(Offering):
 
549
            if 'edit' in offering.get_permissions(req.user):
 
550
                return True
 
551
        return False
 
552
    
 
553
    def populate(self, req, ctx):
 
554
        self.plugin_styles[Plugin] = ['exercise_admin.css']
 
555
        ctx['exercises'] = req.store.find(Exercise).order_by(Exercise.id)
 
556
        ctx['mediapath'] = media_url(req, Plugin, 'images/')
 
557
 
522
558
class Plugin(ViewPlugin, MediaPlugin):
523
559
    urls = [
524
560
        # Worksheet View Urls
539
575
        ('api/subjects/:subject/:year/:semester/+worksheets/:worksheet/*exercise', WorksheetExerciseRESTView),
540
576
        
541
577
        # Exercise View Urls
 
578
        ('+exercises', ExercisesView),
542
579
        ('+exercises/:exercise/+edit', ExerciseEditView),
 
580
        ('+exercises/:exercise/+edit', ExerciseDeleteView),
543
581
        
544
582
        # Exercise Api Urls
545
583
        ('api/+exercises', ExercisesRESTView),