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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/subject.py

  • Committer: William Grant
  • Date: 2010-02-24 01:32:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100224013250-3pfbslg7a5i2eb8g
Refactor UserAdminView to use BaseFormView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    '''The view of the list of subjects.'''
65
65
    template = 'templates/subjects.html'
66
66
    tab = 'subjects'
67
 
    breadcrumb_text = "Subjects"
68
67
 
69
68
    def authorize(self, req):
70
69
        return req.user is not None
97
96
    def populate(self, req, ctx):
98
97
        ctx['req'] = req
99
98
        ctx['mediapath'] = media_url(req, CorePlugin, 'images/')
100
 
        ctx['SubjectView'] = SubjectView
101
99
        ctx['SubjectEdit'] = SubjectEdit
102
100
        ctx['SemesterEdit'] = SemesterEdit
103
101
 
146
144
    def validator(self):
147
145
        return SubjectSchema()
148
146
 
 
147
    def get_return_url(self, obj):
 
148
        return '/subjects'
 
149
 
149
150
 
150
151
class SubjectNew(SubjectFormView):
151
152
    """A form to create a subject."""
265
266
 
266
267
        return self.context
267
268
 
268
 
class SubjectView(XHTMLView):
269
 
    '''The view of the list of offerings in a given subject.'''
270
 
    template = 'templates/subject.html'
271
 
    tab = 'subjects'
272
 
 
273
 
    def authorize(self, req):
274
 
        return req.user is not None
275
 
 
276
 
    def populate(self, req, ctx):
277
 
        ctx['context'] = self.context
278
 
        ctx['req'] = req
279
 
        ctx['user'] = req.user
280
 
        ctx['offerings'] = list(self.context.offerings)
281
 
        ctx['permissions'] = self.context.get_permissions(req.user,req.config)
282
 
        ctx['SubjectEdit'] = SubjectEdit
283
 
        ctx['SubjectOfferingNew'] = SubjectOfferingNew
284
 
 
285
269
 
286
270
class OfferingView(XHTMLView):
287
271
    """The home page of an offering."""
413
397
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
414
398
        ctx['semesters'] = req.store.find(Semester).order_by(
415
399
            Semester.year, Semester.semester)
416
 
        ctx['force_subject'] = None
417
400
 
418
401
    def populate_state(self, state):
419
402
        state.existing_offering = self.context
453
436
        ctx['subjects'] = req.store.find(Subject).order_by(Subject.name)
454
437
        ctx['semesters'] = req.store.find(Semester).order_by(
455
438
            Semester.year, Semester.semester)
456
 
        ctx['force_subject'] = None
457
439
 
458
440
    def populate_state(self, state):
459
441
        state.existing_offering = None
471
453
        req.store.add(new_offering)
472
454
        return new_offering
473
455
 
474
 
class SubjectOfferingNew(OfferingNew):
475
 
    """A form to create an offering for a given subject."""
476
 
    # Identical to OfferingNew, except it forces the subject to be the subject
477
 
    # in context
478
 
    def populate(self, req, ctx):
479
 
        super(SubjectOfferingNew, self).populate(req, ctx)
480
 
        ctx['force_subject'] = self.context
481
456
 
482
457
class OfferingCloneWorksheetsSchema(formencode.Schema):
483
458
    subject = formencode.All(
765
740
             (ApplicationRoot, ('subjects', '+new'), SubjectNew),
766
741
             (ApplicationRoot, ('subjects', '+new-offering'), OfferingNew),
767
742
             (ApplicationRoot, ('+semesters', '+new'), SemesterNew),
768
 
             (Subject, '+index', SubjectView),
769
743
             (Subject, '+edit', SubjectEdit),
770
 
             (Subject, '+new-offering', SubjectOfferingNew),
771
744
             (Semester, '+edit', SemesterEdit),
772
745
             (Offering, '+index', OfferingView),
773
746
             (Offering, '+edit', OfferingEdit),