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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2010-02-24 02:36:13 UTC
  • mfrom: (1678.1.5 trunk)
  • Revision ID: matt.giuca@gmail.com-20100224023613-7sg1ivx3c324aagm
Added new view SubjectView, which shows all offerings for a subject (merged from several sub-commits). This fixes Launchpad bug #493931.

Show diffs side-by-side

added added

removed removed

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