source: WAeUP_SRP/trunk/skins/waeup_student/apply_pume.py @ 2111

Last change on this file since 2111 was 2111, checked in by Henrik Bettermann, 17 years ago

apply_pume.py fixed
2 fields added to applicants_catalog

  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1## Script (Python) "apply_pume"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST
8##title=
9##
10# $Id: apply_pume.py 2111 2007-08-17 05:34:36Z henrik $
11"""
12process the Pume Application Form
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19
20import DateTime
21current = DateTime.DateTime()
22pr = context.portal_registration
23request = REQUEST
24
25#type_name = 'StudentApplication'
26#ti = context.portal_types[type_name]
27#REQUEST.set('type_name',type_name)
28create = "create" in request.keys()
29apply_pume = "apply" in request.keys()
30edit = "edit" in request.keys()
31slip = "slip" in request.keys()
32submitted = False
33mode = request.get('mode','')
34if not mode:
35    if apply_pume or edit:
36        mode = "edit"
37    else:
38        mode = "create"
39validate = create or edit or apply_pume
40
41lt = context.portal_layouts
42reg_no = request.get('widget__reg_no','').upper()
43if not reg_no:
44    reg_no = request.form.get('reg_no','').upper()
45pin = request.form.get('pin','')
46object = {}
47if reg_no:
48    brains = context.applicants_catalog(reg_no = reg_no)
49    if len(brains) == 1:
50        for field in context.applicants_catalog.schema():
51            object[field] = getattr(brains[0],field,None)
52        if object['status'] == "submitted":
53            submitted = True
54        #set_trace()
55        if not create and pin != object['pin']:
56            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
57if slip:
58    mode = "view_slip"
59
60res,psm,ds = lt.renderLayout(layout_id= 'application',
61                             schema_id= 'application',
62                             layout_mode = mode,
63                             context=context,
64                             mapping=validate and REQUEST,
65                             ob=object,
66                             commit = False,
67                            )
68
69if slip:
70    return context.apply_pume_slip(rendered = res,
71                                   psm = "",
72                                   #psm = "%s, %s" % (psm,ds),
73                                   mode = mode,
74                                   ds = ds,
75                                  )
76
77if psm == 'invalid':
78    return context.apply_pume_form(rendered = res,
79                                   psm = "Please correct your input!",
80                                   #psm = "%s, %s" % (psm,ds),
81                                   mode = mode,
82                                   ds = ds,
83                                  )
84elif psm == '':
85    return context.apply_pume_form(rendered = res,
86                                   psm = None,
87                                   ds = ds,
88                                   mode = mode,
89                                  )
90elif psm == 'valid':
91    pass
92data = {}
93for field in context.applicants_catalog.schema():
94    if ds.has_key(field) and request.has_key("widget__%s" % field):
95        data[field] = ds.get(field)
96data['reg_no'] = reg_no
97
98if apply_pume:
99
100    if submitted:
101        mode = "view"
102        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
103        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
104                                schema_id= 'application',
105                                layout_mode = mode,
106                                context=context,
107                                mapping={},
108                                ob=object,
109                                commit = False,
110                                )
111    elif not request.has_key('confirm'):
112        mode = "edit"
113        psm = "Please confirm Passport Photograph!"
114    else:
115        mode = "view"
116        psm = "You successfully applied for PUME!"
117        data['application_date'] = current
118        data['status'] = "submitted"
119        context.applicants_catalog.modifyRecord(**data)
120        res,psm_dummy,ds = lt.renderLayout(layout_id= 'application',
121                                schema_id= 'application',
122                                layout_mode = mode,
123                                context=context,
124                                mapping=validate and REQUEST,
125                                ob=object,
126                                commit = False,
127                                )
128elif create:
129    if submitted:
130        mode = "view"
131    else:
132        mode = "edit"
133    psm = ""
134    #set_trace()
135    object['pin'] = str(ds.get('pin'))
136    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
137                                schema_id= 'application',
138                                layout_mode = mode,
139                                context=context,
140                                mapping={},
141                                ob=object,
142                                commit = False,
143                                )
144elif edit:
145    if submitted:
146        mode = "view"
147        psm = "The form has already been submitted and you are not allowed to modify the data!"
148        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
149                                schema_id= 'application',
150                                layout_mode = mode,
151                                context=context,
152                                mapping={},
153                                ob=object,
154                                commit = False,
155                                )
156    else:
157        mode = "edit"
158        psm = "Content changed"
159        data['status'] = "edited"
160        context.applicants_catalog.modifyRecord(**data)
161
162
163
164return context.apply_pume_form(rendered = res,
165                            psm = psm,
166                            #psm = "%s, %s" % (psm,ds),
167                            mode = mode,
168                            ds = ds,
169                            )
170
171
Note: See TracBrowser for help on using the repository browser.