Ignore:
Timestamp:
11 May 2007, 12:00:10 (18 years ago)
Author:
joachim
Message:

some fixes for addStudent and importStudent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Widgets.py

    r1748 r1772  
    66##from Products.CPSSchemas.Widget import CPSWidgetType
    77from Products.CMFCore.utils import getToolByName
    8 from Products.CPSSchemas.BasicWidgets import CPSWidget, CPSStringWidget, CPSEmailWidget,CPSImageWidget
     8from Products.CPSSchemas.BasicWidgets import CPSBooleanWidget, CPSWidget, CPSStringWidget, CPSEmailWidget,CPSImageWidget
    99from Products.CPSSchemas.BasicWidgets import renderHtmlTag,CPSSelectWidget, CPSStringWidget
    1010from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget
     
    389389widgetRegistry.register(SecretWidget)
    390390###)
     391
     392class WAeUPSexWidget(CPSBooleanWidget):
     393    """WAeUP sex widget."""
     394    meta_type = 'WAeUP Sex Widget'
     395
     396    def validate(self, datastructure, **kw):
     397        """Validate datastructure and update datamodel."""
     398        value = datastructure[self.getWidgetId()]
     399
     400        if self.render_format not in self.render_formats:
     401            self.render_format = 'select'
     402
     403        female = value in ('F','f','Female','female',"True",True)
     404        male = value in ('M','m','Male','male','False',False)
     405        if not female and not male:
     406            datastructure.setError(self.getWidgetId(),
     407                                   "invalid sex %s" % value)
     408            return 0
     409        elif female:
     410            v = True
     411        else:
     412            v = False
     413        datamodel = datastructure.getDataModel()
     414        datamodel[self.fields[0]] = v
     415        return 1
     416
     417InitializeClass(WAeUPSexWidget)
     418
     419widgetRegistry.register(WAeUPSexWidget)
    391420
    392421class MatricNoWidget(CPSStringWidget): ###(
Note: See TracChangeset for help on using the changeset viewer.