Changeset 3487 for WAeUP_SRP/base


Ignore:
Timestamp:
3 May 2008, 15:10:45 (17 years ago)
Author:
joachim
Message:

add WAeUP Boolean Widget;
use it in import_course_result

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/Widgets.py

    r3486 r3487  
    10301030
    10311031widgetRegistry.register(WAeUPSexWidget)
     1032
     1033###)
     1034
     1035class WAeUPBooleanWidget(CPSBooleanWidget): ###(
     1036    """WAeUP boolean widget."""
     1037    meta_type = 'WAeUP Boolean Widget'
     1038
     1039    def validate(self, datastructure, **kw):
     1040        """Validate datastructure and update datamodel."""
     1041        value = datastructure[self.getWidgetId()]
     1042
     1043        if self.render_format not in self.render_formats:
     1044            self.render_format = 'select'
     1045        true = value.upper() in ('T','1','TRUE',True)
     1046        false = value.upper() in ('F','0','FALSE',False)
     1047        if not true and not false:
     1048            datastructure.setError(self.getWidgetId(),
     1049                                   "invalid boolean %s" % value)
     1050            return 0
     1051        elif true:
     1052            v = True
     1053        else:
     1054            v = False
     1055        datamodel = datastructure.getDataModel()
     1056        datamodel[self.fields[0]] = v
     1057        return 1
     1058
     1059InitializeClass(WAeUPBooleanWidget)
     1060
     1061widgetRegistry.register(WAeUPBooleanWidget)
    10321062
    10331063###)
Note: See TracChangeset for help on using the changeset viewer.