source: waeup_product/trunk/Widgets.py @ 231

Last change on this file since 231 was 204, checked in by joachim, 19 years ago

=added doc

  • Property svn:keywords set to Id
File size: 2.8 KB
RevLine 
[47]1#-*- mode: python; mode: fold -*-
[22]2from Globals import InitializeClass
[199]3##from Products.CPSSchemas.Widget import CPSWidgetType
[22]4from Products.CPSSchemas.BasicWidgets import CPSStringWidget, CPSEmailWidget
5from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget
[199]6from Products.CPSSchemas.Widget import widgetRegistry
7##from Products.CPSSchemas.WidgetTypesTool import WidgetTypeRegistry
[22]8from DateTime.DateTime import DateTime
9from AccessControl import getSecurityManager
10
11from re import compile
12
13from zLOG import LOG, DEBUG
14
[47]15class StudentIdWidget(CPSStringWidget): ###(
[22]16    """ StudentId Widget"""
17    meta_type = "StudentId Widget"
[57]18    digits = 8
19    digits_str = "N"*digits
20    letters = 2
21    letters_str = "L"*letters
[22]22   
23    def validate(self, datastructure, **kw):
24        """Validate datastructure and update datamodel."""
25       
26        valid = CPSStringWidget.validate(self, datastructure, **kw)
27        if not valid:
28            return 0
29        else:
30            widget_id = self.getWidgetId()
31            value = datastructure[widget_id]
32            err = 0
[57]33            if not (len(value) == self.digits + self.letters and value[:self.digits].isdigit() and value[self.digits:].isalpha()):
34                err = 'invalid Student Id in the format: %s%s with N = Number, L = Letter' % (self.digits_str,self.letters_str)
[22]35            if err:
36                datastructure.setError(widget_id, err)
37            else:
38                datamodel = datastructure.getDataModel()
39                datamodel[self.fields[0]] = value
40           
41            return not err
42
43InitializeClass(StudentIdWidget)
44
[199]45widgetRegistry.register(StudentIdWidget)
[22]46
[199]47##Class StudentIdWidgetType(CPSWidgetType):
48##    """Student Id String widget type."""
49##    meta_type = "StudentId  Widget Type"
50##    cls = StudentIdWidget
51
[47]52###)
53
54class ScratchcardPinWidget(CPSStringWidget): ###(
[22]55    """ ScratchcardPin Widget"""
[199]56    meta_type = "Scratchcard Pin Widget"
[204]57    valid_pins = ['12345678',
58                  '23456789',
59                  '34567890',
60                  '45678901',
[22]61                  ]
62   
63    def validate(self, datastructure, **kw):
64        """Validate datastructure and update datamodel."""
65       
66        valid = CPSStringWidget.validate(self, datastructure, **kw)
67        if not valid:
68            return 0
69        else:
70            widget_id = self.getWidgetId()
71            value = datastructure[widget_id]
72            err = 0
[204]73            #import pdb; pdb.set_trace()
[57]74            if not value in self.valid_pins:
[22]75                err = 'invalid Pin'
76            if err:
77                datastructure.setError(widget_id, err)
78            else:
79                datamodel = datastructure.getDataModel()
80                datamodel[self.fields[0]] = value
81            return not err
82
83InitializeClass(ScratchcardPinWidget)
[199]84widgetRegistry.register(ScratchcardPinWidget)
[22]85
[47]86
87###)
88
[22]89###########
90
Note: See TracBrowser for help on using the repository browser.