~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-09 00:15:21 UTC
  • mfrom: (1099.6.4 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090309001521-dffcygyuyvs2cap0
finished the exercise-ui. It is now ready to be merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
509
509
    def populate(self, req, ctx):
510
510
        self.plugin_styles[Plugin] = ['exercise_admin.css']
511
511
        self.plugin_scripts[Plugin] = ['exercise_admin.js']
 
512
            
 
513
        ctx['mediapath'] = media_url(req, Plugin, 'images/')
512
514
        
513
515
        ctx['exercise'] = self.context
514
516
        #XXX: These should come from somewhere else
519
521
        
520
522
        ctx['test_types'] = ('norm', 'check')
521
523
 
 
524
class ExerciseDeleteView(XHTMLView):
 
525
    """View for confirming the deletion of an exercise."""
 
526
    
 
527
    permission = 'edit'
 
528
    template = 'templates/exercise_delete.html'
 
529
    
 
530
    def __init__(self, req, exercise):
 
531
        self.context = req.store.find(Exercise,
 
532
            Exercise.id == exercise).one()
 
533
        
 
534
        if self.context is None:
 
535
            raise NotFound()
 
536
        
 
537
    def populate(self, req, ctx):
 
538
        ctx['exercise'] = self.context
 
539
        ctx['deleted'] = False
 
540
        ctx['path'] = "/+exercises/" + self.context.id + "/+delete"
 
541
        if req.method == 'POST':
 
542
            if self.context.worksheet_exercises.count() is not 0:
 
543
                ctx['hasworksheets'] = True
 
544
            else:
 
545
                #TODO: DELETE the exercise and all its test cases
 
546
                ctx['deleted'] = True
 
547
        else:
 
548
            if self.context.worksheet_exercises.count() is not 0:
 
549
                ctx['hasworksheets'] = True
 
550
            else:
 
551
                ctx['hasworksheets'] = False
 
552
 
 
553
class ExercisesView(XHTMLView):
 
554
    """View for seeing the list of all exercises"""
 
555
    
 
556
    permission = 'edit'
 
557
    template = 'templates/exercises.html'
 
558
    
 
559
    def authorize(self, req):
 
560
        for offering in req.store.find(Offering):
 
561
            if 'edit' in offering.get_permissions(req.user):
 
562
                return True
 
563
        return False
 
564
    
 
565
    def populate(self, req, ctx):
 
566
        self.plugin_styles[Plugin] = ['exercise_admin.css']
 
567
        ctx['exercises'] = req.store.find(Exercise).order_by(Exercise.id)
 
568
        ctx['mediapath'] = media_url(req, Plugin, 'images/')
 
569
 
522
570
class Plugin(ViewPlugin, MediaPlugin):
523
571
    urls = [
524
572
        # Worksheet View Urls
539
587
        ('api/subjects/:subject/:year/:semester/+worksheets/:worksheet/*exercise', WorksheetExerciseRESTView),
540
588
        
541
589
        # Exercise View Urls
 
590
        ('+exercises', ExercisesView),
542
591
        ('+exercises/:exercise/+edit', ExerciseEditView),
 
592
        ('+exercises/:exercise/+delete', ExerciseDeleteView),
543
593
        
544
594
        # Exercise Api Urls
545
595
        ('api/+exercises', ExercisesRESTView),