source: WAeUP_SRP/branches/srpp_branch/WAeUPStudentWidgets.py @ 9144

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

initial import

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1from Globals import InitializeClass
2from Products.CPSSchemas.Widget import CPSWidgetType
3from Products.CPSSchemas.BasicWidgets import CPSStringWidget, CPSEmailWidget
4from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget
5from Products.CPSSchemas.WidgetTypesTool import WidgetTypeRegistry
6from AccessControl import getSecurityManager
7
8from re import compile
9
10from zLOG import LOG, DEBUG
11
12class MyProjectWeekDateTimeWidget(CPSDateTimeWidget):
13    """ """
14    meta_type = "MyProject Week Date Time Widget"
15   
16    def validate(self, datastructure, **kw):
17        """Validate datastructure and update datamodel."""
18       
19        valid = CPSDateTimeWidget.validate(self, datastructure, **kw)
20        if not valid:
21            return 0
22        else:
23            widget_id = self.getWidgetId()
24            value = datastructure[widget_id]
25            err = 0
26            if value.dow() in (6, 0):
27                err = 'Cette date ne correspond pas à un jour de semaine'
28
29            if err:
30                datastructure.setError(widget_id, err)
31
32            return not err
33
34InitializeClass(MyProjectWeekDateTimeWidget)
35
36class MyProjectWeekDateTimeWidgetType(CPSWidgetType):
37    """MyProject Week DateTime widget type."""
38    meta_type = "MyProject Week Date Time Widget Type"
39    cls = MyProjectWeekDateTimeWidget
40
41InitializeClass(MyProjectWeekDateTimeWidgetType)
42
43class MyProjectRestrictedStringWidget(CPSStringWidget):
44    """ """
45    meta_type = "MyProject Restricted String Widget"
46   
47    def validate(self, datastructure, **kw):
48        """Validate datastructure and update datamodel."""
49       
50        valid = CPSStringWidget.validate(self, datastructure, **kw)
51        if not valid:
52            return 0
53        else:
54            widget_id = self.getWidgetId()
55            value = datastructure[widget_id]
56            err = 0
57            if not (len(value) == 5 and value.isupper() and value.isalpha()):
58                err = 'Cette chaîne ne correspond pas au format imposé'
59
60            if err:
61                datastructure.setError(widget_id, err)
62            else:
63                datamodel = datastructure.getDataModel()
64                datamodel[self.fields[0]] = value
65           
66            return not err
67
68InitializeClass(MyProjectRestrictedStringWidget)
69
70class MyProjectRestrictedStringWidgetType(CPSWidgetType):
71    """MyProject Restricted String widget type."""
72    meta_type = "MyProject Restricted String Widget Type"
73    cls = MyProjectRestrictedStringWidget
74
75InitializeClass(MyProjectRestrictedStringWidgetType)
76
77
78class MyProjectRestrictedEmailWidget(CPSEmailWidget):
79    """ """
80    meta_type = "MyProject Restricted Email Widget"
81
82    email_myproject_pat = compile(r"^([-\w_+])+\.([-\w_+])+@myproject\.fr$")
83
84    def validate(self, datastructure, **kw):
85        """Validate datastructure and update datamodel."""
86       
87        valid = CPSEmailWidget.validate(self, datastructure, **kw)
88        if not valid:
89            return 0
90        else:
91            widget_id = self.getWidgetId()
92            err, v = self._extractValue(datastructure[widget_id])
93            LOG('MyProject: MyProjectWidgets.py', DEBUG, "Valeur de v : %s" % v)
94            if not err and kw.get('layout_mode') != 'search' and \
95              v and not self.email_myproject_pat.match(v):
96                err = 'cpsschemas_err_email'
97
98            if err:
99                datastructure.setError(widget_id, err)
100            else:
101                datamodel = datastructure.getDataModel()
102                datamodel[self.fields[0]] = v
103           
104            return not err
105
106    def render(self, mode, datastructure, **kw):
107        """Render in mode from datastructure."""
108        return CPSStringWidget.render(self, mode, datastructure, **kw)
109
110InitializeClass(MyProjectRestrictedEmailWidget)
111
112class MyProjectRestrictedEmailWidgetType(CPSWidgetType):
113    """MyProject Restricted String widget type."""
114    meta_type = "MyProject Restricted Email Widget Type"
115    cls = MyProjectRestrictedEmailWidget
116
117InitializeClass(MyProjectRestrictedEmailWidgetType)
118
119class MyProjectVisitTitleWidget(CPSStringWidget):
120    """ """
121    meta_type = "MyProject Visit Title Widget"
122   
123    def validate(self, datastructure, **kw):
124        """Validate datastructure and update datamodel."""
125       
126        widget_id = self.getWidgetId()
127        err = 0
128        curr_date = DateTime()
129        date = "%d.%d.%d" % (curr_date.day(), curr_date.month(), curr_date.year())
130        user = getSecurityManager().getUser()
131        value = 'Demande de visite du %s par %s' % (date,
132             self.portal_directories.members.getEntry(user.getId()).get('fullname'))
133        datamodel = datastructure.getDataModel()
134        datamodel[self.fields[0]] = value
135           
136        return not err
137
138    def render(self, mode, datastructure, **kw):
139        return ''
140
141InitializeClass(MyProjectVisitTitleWidget)
142
143class MyProjectVisitTitleWidgetType(CPSWidgetType):
144    """MyProject Visit Title widget type."""
145    meta_type = "MyProject Visit Title Widget Type"
146    cls = MyProjectVisitTitleWidget
147
148InitializeClass(MyProjectVisitTitleWidgetType)
149
150#####################################################################################
151
152WidgetTypeRegistry.register(MyProjectWeekDateTimeWidgetType)
153WidgetTypeRegistry.register(MyProjectRestrictedStringWidgetType)
154WidgetTypeRegistry.register(MyProjectRestrictedEmailWidgetType)
155WidgetTypeRegistry.register(MyProjectVisitTitleWidgetType)
156
Note: See TracBrowser for help on using the repository browser.