Ignore:
Timestamp:
31 Jul 2009, 07:19:54 (15 years ago)
Author:
uli
Message:

Add add viewlets/forms for courses in departments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/department.py

    r4466 r4491  
    55from zope.component.interfaces import IFactory
    66from zope.interface import implementedBy
    7 from waeup.interfaces import IDepartment
     7from waeup.interfaces import IDepartment, ICourse
    88from waeup.utils.helpers import getName
    99from waeup.widgets.interfaces import ITableProvider
    10 from waeup.viewlets import MainArea, LeftSidebar, Index, FormWrapMixin, Manage
     10from waeup.viewlets import (MainArea, LeftSidebar, Index, FormWrapMixin,
     11                            Manage, AddCourse)
    1112
    1213class Department(grok.Container):
     
    129130    def render(self):
    130131        return u'<div class="portlet"><a href="manage">Settings</a></div>'
     132
     133class AddCourseForm(grok.AddForm):
     134    grok.context(IDepartment)
     135    form_fields = grok.AutoFields(ICourse)
     136    label = 'Add a course'
     137
     138    @grok.action('Add course')
     139    def addCourse(self, **data):
     140        course = createObject(u'waeup.Course')
     141        self.applyData(course, **data)
     142        try:
     143            self.context.courses.addCourse(course)
     144        except DuplicationError:
     145            self.status = Invalid('The name chosen already exists '
     146                                  'in the database')
     147            return
     148        self.redirect(self.url(self.context))
     149
     150class AddCourse(FormWrapMixin, grok.Viewlet):
     151    """A viewlet that wraps the `AddFacultyForm`.
     152    """
     153    grok.viewletmanager(MainArea)
     154    grok.context(IDepartment)
     155    grok.view(AddCourse)
     156    grok.require('waeup.manageUniversity')
     157
     158    formview_name = 'addcourseform' # The name of the formview we
     159                                    # want to be rendered in this
     160                                    # viewlet.
Note: See TracChangeset for help on using the changeset viewer.