source: waeup_product/trunk/Widgets.py @ 48

Last change on this file since 48 was 47, checked in by joachim, 19 years ago

=weitere

  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1#-*- mode: python; mode: fold -*-
2from Globals import InitializeClass
3from Products.CPSSchemas.Widget import CPSWidgetType
4from Products.CPSSchemas.BasicWidgets import CPSStringWidget, CPSEmailWidget
5from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget
6from Products.CPSSchemas.WidgetTypesTool import WidgetTypeRegistry
7from DateTime.DateTime import DateTime
8from AccessControl import getSecurityManager
9
10from re import compile
11
12from zLOG import LOG, DEBUG
13
14class StudentIdWidget(CPSStringWidget): ###(
15    """ StudentId Widget"""
16    meta_type = "StudentId Widget"
17   
18    def validate(self, datastructure, **kw):
19        """Validate datastructure and update datamodel."""
20       
21        valid = CPSStringWidget.validate(self, datastructure, **kw)
22        print "studentw",valid
23        if not valid:
24            return 0
25        else:
26            widget_id = self.getWidgetId()
27            value = datastructure[widget_id]
28            err = 0
29            if not (len(value) == 8 and value[:6].isdigit() and value[6:].isalpha()):
30                err = 'invalid Student Id'
31
32            if err:
33                datastructure.setError(widget_id, err)
34            else:
35                datamodel = datastructure.getDataModel()
36                datamodel[self.fields[0]] = value
37           
38            return not err
39
40InitializeClass(StudentIdWidget)
41
42class StudentIdWidgetType(CPSWidgetType):
43    """Student Id String widget type."""
44    meta_type = "StudentId  Widget Type"
45    cls = StudentIdWidget
46
47###)
48
49class ScratchcardPinWidget(CPSStringWidget): ###(
50    """ ScratchcardPin Widget"""
51    meta_type = "ScratchcardPin Widget"
52    valid_pins = ['123456',
53                  '234567',
54                  '345678',
55                  '456789',
56                  ]
57   
58    def validate(self, datastructure, **kw):
59        """Validate datastructure and update datamodel."""
60       
61        valid = CPSStringWidget.validate(self, datastructure, **kw)
62        print "sc_pinw",valid
63        if not valid:
64            return 0
65        else:
66            widget_id = self.getWidgetId()
67            value = datastructure[widget_id]
68            err = 0
69            print value
70            if not value in valid_pins:
71                err = 'invalid Pin'
72            if err:
73                datastructure.setError(widget_id, err)
74            else:
75                datamodel = datastructure.getDataModel()
76                datamodel[self.fields[0]] = value
77            return not err
78
79InitializeClass(ScratchcardPinWidget)
80
81class ScratchcardPinWidgetType(CPSWidgetType):
82    """Scratchcard Pin widget type."""
83    meta_type = "Scratchcard Pin  Widget Type"
84    cls = ScratchcardPinWidget
85
86###)
87
88###########
89
90WidgetTypeRegistry.register(StudentIdWidgetType)
91WidgetTypeRegistry.register(ScratchcardPinWidgetType)
92
93##class MyProjectWeekDateTimeWidget(CPSDateTimeWidget): ###(
94##    """ """
95##    meta_type = "MyProject Week Date Time Widget"
96##   
97##    def validate(self, datastructure, **kw):
98##        """Validate datastructure and update datamodel."""
99##       
100##        valid = CPSDateTimeWidget.validate(self, datastructure, **kw)
101##        if not valid:
102##            return 0
103##        else:
104##            widget_id = self.getWidgetId()
105##            value = datastructure[widget_id]
106##            err = 0
107##            if value.dow() in (6, 0):
108##                err = 'Cette date ne correspond pas à un jour de semaine'
109##
110##            if err:
111##                datastructure.setError(widget_id, err)
112##
113##            return not err
114##
115##InitializeClass(MyProjectWeekDateTimeWidget)
116
117##class MyProjectWeekDateTimeWidgetType(CPSWidgetType):
118##    """MyProject Week DateTime widget type."""
119##    meta_type = "MyProject Week Date Time Widget Type"
120##    cls = MyProjectWeekDateTimeWidget
121##
122##InitializeClass(MyProjectWeekDateTimeWidgetType)
123##class MyProjectRestrictedStringWidget(CPSStringWidget):
124##    """ """
125##    meta_type = "MyProject Restricted String Widget"
126##   
127##    def validate(self, datastructure, **kw):
128##        """Validate datastructure and update datamodel."""
129##       
130##        valid = CPSStringWidget.validate(self, datastructure, **kw)
131##        if not valid:
132##            return 0
133##        else:
134##            widget_id = self.getWidgetId()
135##            value = datastructure[widget_id]
136##            err = 0
137##            if not (len(value) == 5 and value.isupper() and value.isalpha()):
138##                err = 'Cette chaîne ne correspond pas au format imposé'
139##
140##            if err:
141##                datastructure.setError(widget_id, err)
142##            else:
143##                datamodel = datastructure.getDataModel()
144##                datamodel[self.fields[0]] = value
145##           
146##            return not err
147##
148##InitializeClass(MyProjectRestrictedStringWidget)
149##
150##class MyProjectRestrictedStringWidgetType(CPSWidgetType):
151##    """MyProject Restricted String widget type."""
152##    meta_type = "MyProject Restricted String Widget Type"
153##    cls = MyProjectRestrictedStringWidget
154##
155##InitializeClass(MyProjectRestrictedStringWidgetType)
156##
157##
158##class MyProjectRestrictedEmailWidget(CPSEmailWidget):
159##    """ """
160##    meta_type = "MyProject Restricted Email Widget"
161##
162##    email_myproject_pat = compile(r"^([-\w_+])+\.([-\w_+])+@myproject\.fr$")
163##
164##    def validate(self, datastructure, **kw):
165##        """Validate datastructure and update datamodel."""
166##       
167##        valid = CPSEmailWidget.validate(self, datastructure, **kw)
168##        if not valid:
169##            return 0
170##        else:
171##            widget_id = self.getWidgetId()
172##            err, v = self._extractValue(datastructure[widget_id])
173##            LOG('MyProject: MyProjectWidgets.py', DEBUG, "Valeur de v : %s" % v)
174##            if not err and kw.get('layout_mode') != 'search' and \
175##              v and not self.email_myproject_pat.match(v):
176##                err = 'cpsschemas_err_email'
177##
178##            if err:
179##                datastructure.setError(widget_id, err)
180##            else:
181##                datamodel = datastructure.getDataModel()
182##                datamodel[self.fields[0]] = v
183##           
184##            return not err
185##
186##    def render(self, mode, datastructure, **kw):
187##        """Render in mode from datastructure."""
188##        return CPSStringWidget.render(self, mode, datastructure, **kw)
189##
190##InitializeClass(MyProjectRestrictedEmailWidget)
191##
192##class MyProjectRestrictedEmailWidgetType(CPSWidgetType):
193##    """MyProject Restricted String widget type."""
194##    meta_type = "MyProject Restricted Email Widget Type"
195##    cls = MyProjectRestrictedEmailWidget
196##
197##InitializeClass(MyProjectRestrictedEmailWidgetType)
198##
199##class MyProjectVisitTitleWidget(CPSStringWidget):
200##    """ """
201##    meta_type = "MyProject Visit Title Widget"
202##   
203##    def validate(self, datastructure, **kw):
204##        """Validate datastructure and update datamodel."""
205##       
206##        widget_id = self.getWidgetId()
207##        err = 0
208##        curr_date = DateTime()
209##        date = "%d.%d.%d" % (curr_date.day(), curr_date.month(), curr_date.year())
210##        user = getSecurityManager().getUser()
211##        value = 'Demande de visite du %s par %s' % (date,
212##             self.portal_directories.members.getEntry(user.getId()).get('fullname'))
213##        datamodel = datastructure.getDataModel()
214##        datamodel[self.fields[0]] = value
215##           
216##        return not err
217##
218##    def render(self, mode, datastructure, **kw):
219##        return ''
220##
221##InitializeClass(MyProjectVisitTitleWidget)
222##
223##class MyProjectVisitTitleWidgetType(CPSWidgetType):
224##    """MyProject Visit Title widget type."""
225##    meta_type = "MyProject Visit Title Widget Type"
226##    cls = MyProjectVisitTitleWidget
227##
228##InitializeClass(MyProjectVisitTitleWidgetType)
229
230#####################################################################################
231
232##WidgetTypeRegistry.register(MyProjectWeekDateTimeWidgetType)
233##WidgetTypeRegistry.register(MyProjectRestrictedStringWidgetType)
234##WidgetTypeRegistry.register(MyProjectRestrictedEmailWidgetType)
235##WidgetTypeRegistry.register(MyProjectVisitTitleWidgetType)
236##
237
238###)
Note: See TracBrowser for help on using the repository browser.