Ignore:
Timestamp:
31 Jul 2009, 10:02:49 (15 years ago)
Author:
uli
Message:

Add forms/viewlets for adding certificates in departments.

File:
1 edited

Legend:

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

    r4497 r4499  
    66from zope.component.interfaces import IFactory
    77from zope.interface import implementedBy
    8 from waeup.interfaces import IDepartment, ICourse
     8from waeup.interfaces import IDepartment, ICourse, ICertificate
    99from waeup.utils.helpers import getName
    1010from waeup.widgets.interfaces import ITableProvider
    1111from waeup.viewlets import (MainArea, LeftSidebar, Index, FormWrapMixin,
    12                             Manage, AddCourse)
     12                            Manage, AddCourse, AddCertificate)
    1313
    1414class Department(grok.Container):
     
    175175                                    # want to be rendered in this
    176176                                    # viewlet.
     177
     178class AddCertificateForm(grok.AddForm):
     179    grok.context(IDepartment)
     180    # We need a deepcopy here, because otherwise also all other
     181    # ICertificate forms would be affected.
     182    form_fields = copy.deepcopy(grok.AutoFields(ICertificate))
     183    form_fields.get('code').field.readonly = False
     184    label = 'Add a certificate'
     185
     186    @grok.action('Add certificate')
     187    def addCertificate(self, **data):
     188        certificate = createObject(u'waeup.Certificate')
     189        self.applyData(certificate, **data)
     190        try:
     191            self.context.certificates.addCertificate(certificate)
     192        except DuplicationError:
     193            self.status = Invalid('The name chosen already exists '
     194                                  'in the database')
     195            return
     196        self.redirect(self.url(self.context))
     197
     198    @grok.action('Cancel')
     199    def cancel(self, **data):
     200        self.redirect(self.url(self.context))
     201        return
     202
     203       
     204class AddCertificate(FormWrapMixin, grok.Viewlet):
     205    """A viewlet that wraps the `AddFacultyForm`.
     206    """
     207    grok.viewletmanager(MainArea)
     208    grok.context(IDepartment)
     209    grok.view(AddCertificate)
     210    grok.require('waeup.manageUniversity')
     211
     212    formview_name = 'addcertificateform' # The name of the formview we
     213                                         # want to be rendered in this
     214                                         # viewlet.
Note: See TracChangeset for help on using the changeset viewer.