Ignore:
Timestamp:
7 Jan 2010, 23:12:02 (15 years ago)
Author:
uli
Message:
  • Add missing docstrings.
  • Remove viewing stuff (moved to browser subpackage).
  • Remove unneeded imports.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/university/faculty.py

    r4465 r4714  
     1"""Faculty components.
     2"""
     3
    14import grok
    2 from zope.component.interfaces import Invalid, IFactory
    3 from zope.component import createObject
    4 from zope.exceptions import DuplicationError
     5from zope.component.interfaces import IFactory
    56from zope.interface import implementedBy
    67from waeup.interfaces import IFaculty, IDepartment
    7 from waeup.viewlets import (MainArea, LeftSidebar, Index, FormWrapMixin,
    8                             Manage, Add)
    9 from waeup.widgets.interfaces import ITableProvider
    108
    119class Faculty(grok.Container):
     10    """A university faculty.
     11    """
    1212    grok.implements(IFaculty)
    1313
     
    2222
    2323    def addDepartment(self, department):
     24        """Add a department to the faculty.
     25        """
    2426        if not IDepartment.providedBy(department):
    2527            raise TypeError('Faculties contain only IDepartment instances')
     
    2729
    2830    def clear(self):
     31        """Remove all departments from faculty.
     32        """
    2933        keys = self.keys()
    3034        for key in keys:
     
    3236
    3337    def getName(self, key):
     38        """Get complete faculty name.
     39        """
    3440        if key in self.keys():
    3541            dept = self[key]
     
    5258    def getInterfaces(self):
    5359        return implementedBy(Faculty)
    54 
    55 class DisplayForm(grok.DisplayForm):
    56     grok.context(IFaculty)
    57     form_fields = grok.AutoFields(IFaculty)
    58  
    59 class Content(FormWrapMixin, grok.Viewlet):
    60     """A viewlet that wraps the `AddFacultyForm`.
    61     """
    62     grok.viewletmanager(MainArea)
    63     grok.context(IFaculty)
    64     grok.view(Index)
    65     grok.order(2)
    66     formview_name = 'displayform' # The name of the formview we want
    67                                   # to be rendered in this viewlet.
    68    
    69 class DepartmentList(grok.Viewlet):
    70     grok.viewletmanager(MainArea)
    71     grok.context(IFaculty)
    72     grok.view(Index)
    73     grok.order(3)
    74 
    75     def update(self):
    76         self.table = ITableProvider(self.context).getTables(view=self.view)[0]
    77         self.table.need()
    78 
    79 class ManageForm(grok.EditForm):
    80     """Manage the basic properties of a `Faculty` instance.
    81     """
    82 
    83     form_fields = grok.AutoFields(IFaculty)
    84 
    85     @property
    86     def label(self):
    87         # Set faculty name as form label
    88         return self.form_fields['title'].field.get(self.context)
    89    
    90     @grok.action('Save')
    91     def save(self, **data):
    92         self.applyData(self.context, **data)
    93         return
    94    
    95     @grok.action('Save and return')
    96     def saveAndReturn(self, **data):
    97         self.applyData(self.context, **data)
    98         self.redirect(self.url(self.context))
    99         return
    100 
    101     @grok.action('Cancel')
    102     def cancel(self, **data):
    103         self.redirect(self.url(self.context))
    104         return
    105 
    106 class ManageFaculty(FormWrapMixin, grok.Viewlet):
    107     """A viewlet that renders the `ManageForm`.
    108     """
    109     grok.viewletmanager(MainArea)
    110     grok.context(IFaculty)
    111     grok.view(Manage)
    112     grok.require('waeup.manageUniversity')
    113    
    114     formview_name = 'manageform' # The name of the formview we want to
    115                                  # be rendered in this viewlet.
    116 
    117 class ManageLink(grok.Viewlet):
    118     grok.viewletmanager(LeftSidebar)
    119     grok.context(IFaculty)
    120     grok.view(Index)
    121     grok.order(5)
    122     # This link is only displayed, if the user is allowed to use it!
    123     grok.require('waeup.manageUniversity')
    124    
    125     def render(self):
    126         return u'<div class="portlet"><a href="manage">Settings</a></div>'
    127 
    128 class AddDepartmentForm(grok.AddForm):
    129     grok.context(IFaculty)
    130     form_fields = grok.AutoFields(IDepartment)
    131     label = 'Add a department'
    132 
    133     @grok.action('Add department')
    134     def addDepartment(self, **data):
    135         department = createObject(u'waeup.Department')
    136         self.applyData(department, **data)
    137         try:
    138             self.context.addDepartment(department)
    139         except DuplicationError:
    140             self.status = Invalid('The name chosen already exists '
    141                                   'in the database')
    142             return
    143         self.redirect(self.url(self.context))
    144 
    145        
    146 class AddDepartment(FormWrapMixin, grok.Viewlet):
    147     """A viewlet that wraps the `AddDepartmentForm`.
    148     """
    149     grok.viewletmanager(MainArea)
    150     grok.context(IFaculty)
    151     grok.view(Add)
    152     grok.require('waeup.manageUniversity')
    153 
    154     formview_name = 'adddepartmentform' # The name of the formview we
    155                                      # want to be rendered in this
    156                                      # viewlet.
    157 
    158 class AddDepartmentLink(grok.Viewlet):
    159     """A link in the left sidebar displaying 'Add department'
    160     """
    161     grok.viewletmanager(LeftSidebar)
    162     grok.context(IFaculty)
    163     grok.view(Index)
    164     grok.order(5)
    165     # This is so cool! This link is only displayed, when the user is
    166     # allowed to use it!
    167     grok.require('waeup.manageUniversity')
    168    
    169     def render(self):
    170         return u'<div class="portlet"><a href="add">Add department</a></div>'
Note: See TracChangeset for help on using the changeset viewer.