Changeset 4720


Ignore:
Timestamp:
8 Jan 2010, 01:05:01 (15 years ago)
Author:
uli
Message:

Add add-forms to add a course or certificate to departments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/pages.py

    r4717 r4720  
    22""" Viewing components for WAeUP objects.
    33"""
     4import copy
    45import grok
    56import os
     
    1314from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
    1415                              IUserAccount, IFacultyContainer, IDataCenter,
    15                               IFaculty, IDepartment)
     16                              IFaculty, IDepartment, ICourse, ICertificate)
    1617from waeup.widgets.interfaces import ITableProvider
    1718from waeup.utils.helpers import getName
     
    491492#
    492493class DepartmentPage(WAeUPPage):
     494    """Department index page.
     495    """
    493496    grok.context(IDepartment)
    494497    grok.require('waeup.View')
     
    513516        self.certificatetable = self.tables[1]
    514517        self.coursetable.need()
     518
     519class DepartmentManageFormPage(WAeUPEditFormPage):
     520    """Manage the basic properties of a `Department` instance.
     521    """
     522    grok.context(IDepartment)
     523    grok.name('manage')
     524    grok.require('waeup.manageUniversity')
     525    title = u'Edit department settings'
     526    pnav = 1
     527
     528    form_fields = grok.AutoFields(IDepartment)
     529
     530    @grok.action('Save')
     531    def save(self, **data):
     532        self.applyData(self.context, **data)
     533        return
     534   
     535    @grok.action('Save and return')
     536    def saveAndReturn(self, **data):
     537        self.applyData(self.context, **data)
     538        self.redirect(self.url(self.context))
     539        return
     540
     541    @grok.action('Cancel')
     542    def cancel(self, **data):
     543        self.redirect(self.url(self.context))
     544        return
     545
     546class DepartmentAddCourseFormPage(WAeUPAddFormPage):
     547    """Add-form to add course to a department.
     548    """
     549    grok.context(IDepartment)
     550    grok.name('addcourse')
     551    grok.require('waeup.manageUniversity')
     552    title = u'Add course'
     553    pnav = 1
     554   
     555    # We need a deepcopy here, because otherwise also all other
     556    # ICourse forms would be affected.
     557    form_fields = copy.deepcopy(grok.AutoFields(ICourse))
     558    form_fields.get('code').field.readonly = False
     559
     560    @grok.action('Add course')
     561    def addCourse(self, **data):
     562        course = createObject(u'waeup.Course')
     563        self.applyData(course, **data)
     564        try:
     565            self.context.courses.addCourse(course)
     566        except DuplicationError:
     567            self.status = Invalid('The code chosen already exists '
     568                                  'in the database')
     569            return
     570        self.redirect(self.url(self.context))
     571
     572    @grok.action('Cancel')
     573    def cancel(self, **data):
     574        self.redirect(self.url(self.context))
     575        return
     576
     577class DepartmentAddCertificateFormPage(WAeUPAddFormPage):
     578    """Add-form to add certificate to a department.
     579    """
     580    grok.context(IDepartment)
     581    grok.name('addcertificate')
     582    grok.require('waeup.manageUniversity')
     583    title = u'Add certificate'
     584    pnav = 1
     585   
     586    # We need a deepcopy here, because otherwise also all other
     587    # ICertificate forms would be affected.
     588    form_fields = copy.deepcopy(grok.AutoFields(ICertificate))
     589    form_fields.get('code').field.readonly = False
     590
     591    @grok.action('Add certificate')
     592    def addCertificate(self, **data):
     593        certificate = createObject(u'waeup.Certificate')
     594        self.applyData(certificate, **data)
     595        try:
     596            self.context.certificates.addCertificate(certificate)
     597        except DuplicationError:
     598            self.status = Invalid('The name chosen already exists '
     599                                  'in the database')
     600            return
     601        self.redirect(self.url(self.context))
     602
     603    @grok.action('Cancel')
     604    def cancel(self, **data):
     605        self.redirect(self.url(self.context))
     606        return
Note: See TracChangeset for help on using the changeset viewer.