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

« back to all changes in this revision

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

Modified worksheets edit view, so now there are links to edit, add,
and re-arranging worksheets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
from ivle.webapp.base.views import BaseView
43
43
from ivle.webapp.base.xhtml import XHTMLView
44
44
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
45
 
from ivle.webapp.media import BaseMediaFileView
 
45
from ivle.webapp.media import BaseMediaFileView, media_url
46
46
from ivle.webapp.errors import NotFound, Forbidden
47
47
from ivle.webapp.tutorial.rst import rst as rstfunc
48
48
from ivle.webapp.tutorial.service import AttemptsRESTView, AttemptRESTView, \
457
457
        #XXX: Get the list of formats from somewhere else
458
458
        ctx['formats'] = ['xml', 'rst']
459
459
 
 
460
class WorksheetsEditView(XHTMLView):
 
461
    """View for arranging worksheets."""
 
462
    
 
463
    permission = 'edit'
 
464
    template = 'templates/worksheets_edit.html'
 
465
    
 
466
    def __init__(self, req, subject, year, semester):
 
467
        self.context = req.store.find(Offering,
 
468
            Offering.semester_id == Semester.id,
 
469
            Semester.year == year,
 
470
            Semester.semester == semester,
 
471
            Offering.subject_id == Subject.id,
 
472
            Subject.code == subject
 
473
        ).one()
 
474
        
 
475
        self.subject = subject
 
476
        self.year = year
 
477
        self.semester = semester
 
478
        
 
479
        if self.context is None:
 
480
            raise NotFound()
 
481
    
 
482
    def populate(self, req, ctx):
 
483
        self.plugin_styles[Plugin] = ['tutorial_admin.css']
 
484
        self.plugin_scripts[Plugin] = ['tutorial_admin.js']
 
485
        
 
486
        ctx['subject'] = self.subject
 
487
        ctx['year'] = self.year
 
488
        ctx['semester'] = self.semester
 
489
        
 
490
        ctx['worksheets'] = self.context.worksheets
 
491
        
 
492
        ctx['mediapath'] = media_url(req, Plugin, 'images/')
 
493
        
 
494
 
460
495
 
461
496
class Plugin(ViewPlugin, MediaPlugin):
462
497
    urls = [
463
498
        ('subjects/:subject/:year/:semester/+worksheets', OfferingView),
464
499
        ('subjects/:subject/:year/:semester/+worksheets/+add', WorksheetAddView),
465
500
        ('subjects/:subject/+worksheets/+media/*(path)', SubjectMediaView),
 
501
        ('subjects/:subject/:year/:semester/+worksheets/+edit', WorksheetsEditView),
466
502
        ('subjects/:subject/:year/:semester/+worksheets/:worksheet', WorksheetView),
467
503
        ('subjects/:subject/:year/:semester/+worksheets/:worksheet/+edit', WorksheetEditView),
468
504
        ('api/subjects/:subject/:year/:semester/+worksheets', WorksheetsRESTView),