1 | #-*- mode: python; mode: fold -*- |
---|
2 | from Globals import InitializeClass |
---|
3 | ##from Products.CPSSchemas.Widget import CPSWidgetType |
---|
4 | from Products.CPSSchemas.BasicWidgets import CPSStringWidget, CPSEmailWidget |
---|
5 | from Products.CPSSchemas.ExtendedWidgets import CPSDateTimeWidget |
---|
6 | from Products.CPSSchemas.Widget import widgetRegistry |
---|
7 | ##from Products.CPSSchemas.WidgetTypesTool import WidgetTypeRegistry |
---|
8 | from DateTime.DateTime import DateTime |
---|
9 | from AccessControl import getSecurityManager |
---|
10 | |
---|
11 | from re import compile |
---|
12 | |
---|
13 | from zLOG import LOG, DEBUG |
---|
14 | |
---|
15 | class StudentIdWidget(CPSStringWidget): ###( |
---|
16 | """ StudentId Widget""" |
---|
17 | meta_type = "StudentId Widget" |
---|
18 | digits = 8 |
---|
19 | digits_str = "N"*digits |
---|
20 | letters = 2 |
---|
21 | letters_str = "L"*letters |
---|
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 |
---|
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) |
---|
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 | |
---|
43 | InitializeClass(StudentIdWidget) |
---|
44 | |
---|
45 | widgetRegistry.register(StudentIdWidget) |
---|
46 | |
---|
47 | ##Class StudentIdWidgetType(CPSWidgetType): |
---|
48 | ## """Student Id String widget type.""" |
---|
49 | ## meta_type = "StudentId Widget Type" |
---|
50 | ## cls = StudentIdWidget |
---|
51 | |
---|
52 | ###) |
---|
53 | |
---|
54 | class ScratchcardPinWidget(CPSStringWidget): ###( |
---|
55 | """ ScratchcardPin Widget""" |
---|
56 | meta_type = "Scratchcard Pin Widget" |
---|
57 | valid_pins = ['12345678', |
---|
58 | '23456789', |
---|
59 | '34567890', |
---|
60 | '45678901', |
---|
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 |
---|
73 | #import pdb; pdb.set_trace() |
---|
74 | if not value in self.valid_pins: |
---|
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 | |
---|
83 | InitializeClass(ScratchcardPinWidget) |
---|
84 | widgetRegistry.register(ScratchcardPinWidget) |
---|
85 | |
---|
86 | |
---|
87 | ###) |
---|
88 | |
---|
89 | ########### |
---|
90 | |
---|