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

Last change on this file since 2134 was 2134, checked in by joachim, 17 years ago

add check for passport foto

  • Property svn:keywords set to Id
File size: 6.6 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 2134 2007-08-21 06:21:08Z joachim $
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
21import logging
22logger = logging.getLogger('Skins.apply_pume')
23
24current = DateTime.DateTime()
25pr = context.portal_registration
26request = REQUEST
27
28#type_name = 'StudentApplication'
29#ti = context.portal_types[type_name]
30#REQUEST.set('type_name',type_name)
31create = "create" in request.keys()
32apply_pume = "apply" in request.keys()
33edit = "edit" in request.keys()
34slip = "slip" in request.keys()
35submitted = False
36mode = request.get('mode','')
37if not mode:
38    if apply_pume or edit:
39        mode = "edit"
40    else:
41        mode = "create"
42validate = create or edit or apply_pume
43
44lt = context.portal_layouts
45reg_no = request.get('widget__reg_no','').upper()
46if not reg_no:
47    reg_no = request.form.get('reg_no','').upper()
48pin = request.form.get('pin','')
49object = {}
50if reg_no:
51    brains = context.applicants_catalog(reg_no = reg_no)
52    if len(brains) == 1:
53        for field in context.applicants_catalog.schema():
54            object[field] = getattr(brains[0],field,None)
55        if not object['passport']:
56            object['passport'] = ''
57        if object['status'] == "submitted":
58            submitted = True
59        if not create and pin != object['pin']:
60            logger.info('%s entered wrong pin %s' % (reg_no,pin))
61            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
62if slip:
63    mode = "view_slip"
64    logger.info('%s views application slip' % (reg_no))
65   
66res,psm,ds = lt.renderLayout(layout_id= 'application',
67                             schema_id= 'application',
68                             layout_mode = mode,
69                             context=context,
70                             mapping=validate and REQUEST,
71                             ob=object,
72                             commit = False,
73                            )
74
75if slip:
76    return context.apply_pume_slip(rendered = res,
77                                   psm = "",
78                                   #psm = "%s, %s" % (psm,ds),
79                                   mode = mode,
80                                   ds = ds,
81                                  )
82
83if psm == 'invalid':
84    return context.apply_pume_form(rendered = res,
85                                   psm = "Please correct your input!",
86                                   #psm = "%s, %s" % (psm,ds),
87                                   mode = mode,
88                                   ds = ds,
89                                  )
90elif psm == '':
91    return context.apply_pume_form(rendered = res,
92                                   psm = None,
93                                   ds = ds,
94                                   mode = mode,
95                                  )
96elif psm == 'valid':
97    pass
98data = {}
99dm = ds.getDataModel()
100#set_trace()
101for field in context.applicants_catalog.schema():
102    if dm.has_key("%s" % field):
103        data[field] = dm.get(field)
104data['reg_no'] = reg_no
105#set_trace()
106if apply_pume:
107    if submitted:
108        mode = "view"
109        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
110        logger.info('%s tried to resubmit application record' % (reg_no))
111        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
112                                schema_id= 'application',
113                                layout_mode = mode,
114                                context=context,
115                                mapping={},
116                                ob=object,
117                                commit = False,
118                                )
119    elif not dm.get('passport'):
120        mode = "edit"
121        psm = "Please upload Passport Photograph!"
122        logger.info('%s tried to submit without uploading a passport foto' % (reg_no))
123    elif not request.has_key('confirm'):
124        mode = "edit"
125        psm = "Please confirm Passport Photograph!"
126        logger.info('%s tried to submit without ticking confirmation check box' % (reg_no))
127    else:
128        mode = "view"
129        psm = "You successfully applied for PUME!"
130        data['application_date'] = current
131        data['status'] = "submitted"
132        context.applicants_catalog.modifyRecord(**data)
133        logger.info('%s modified and submitted application record' % (reg_no))
134        res,psm_dummy,ds = lt.renderLayout(layout_id= 'application',
135                                schema_id= 'application',
136                                layout_mode = mode,
137                                context=context,
138                                mapping=validate and REQUEST,
139                                ob=object,
140                                commit = False,
141                                )
142elif create:
143    if submitted:
144        mode = "view"
145        logger.info('%s views application record' % (reg_no))
146    else:
147        mode = "edit"
148        logger.info('%s edits application process' % (reg_no))
149    psm = ""
150    #set_trace()
151    object['pin'] = str(ds.get('pin'))
152    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
153                                schema_id= 'application',
154                                layout_mode = mode,
155                                context=context,
156                                mapping={},
157                                ob=object,
158                                commit = False,
159                                )
160elif edit:
161    #set_trace()
162    if submitted:
163        mode = "view"
164        psm = "The form has already been submitted and you are not allowed to modify the data!"
165        logger.info('%s tried to edit submitted application record' % (reg_no))
166        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
167                                schema_id= 'application',
168                                layout_mode = mode,
169                                context=context,
170                                mapping={},
171                                ob=object,
172                                commit = False,
173                                )
174    else:
175        mode = "edit"
176        psm = "Content changed"
177        data['status'] = "edited"
178        context.applicants_catalog.modifyRecord(**data)
179        logger.info('%s modified application record' % (reg_no))
180
181
182
183return context.apply_pume_form(rendered = res,
184                            psm = psm,
185                            #psm = "%s, %s" % (psm,ds),
186                            mode = mode,
187                            ds = ds,
188                            )
189
190
Note: See TracBrowser for help on using the repository browser.