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

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

add logging messages
change storage location of passport picture
and more

  • Property svn:keywords set to Id
File size: 6.4 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 2119 2007-08-18 17:23:25Z 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
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
105if apply_pume:
106    if submitted:
107        mode = "view"
108        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
109        logger.info('%s tried to resubmit application record' % (reg_no))
110        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
111                                schema_id= 'application',
112                                layout_mode = mode,
113                                context=context,
114                                mapping={},
115                                ob=object,
116                                commit = False,
117                                )
118    elif not request.has_key('confirm'):
119        mode = "edit"
120        psm = "Please confirm Passport Photograph!"
121        logger.info('%s tried to submit without ticking confirmation check box' % (reg_no))
122    else:
123        mode = "view"
124        psm = "You successfully applied for PUME!"
125        data['application_date'] = current
126        data['status'] = "submitted"
127        context.applicants_catalog.modifyRecord(**data)
128        logger.info('%s modified and submitted application record' % (reg_no))
129        res,psm_dummy,ds = lt.renderLayout(layout_id= 'application',
130                                schema_id= 'application',
131                                layout_mode = mode,
132                                context=context,
133                                mapping=validate and REQUEST,
134                                ob=object,
135                                commit = False,
136                                )
137elif create:
138    if submitted:
139        mode = "view"
140        logger.info('%s views application record' % (reg_no))
141    else:
142        mode = "edit"
143        logger.info('%s edits application process' % (reg_no))
144    psm = ""
145    #set_trace()
146    object['pin'] = str(ds.get('pin'))
147    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
148                                schema_id= 'application',
149                                layout_mode = mode,
150                                context=context,
151                                mapping={},
152                                ob=object,
153                                commit = False,
154                                )
155elif edit:
156    #set_trace()
157    if submitted:
158        mode = "view"
159        psm = "The form has already been submitted and you are not allowed to modify the data!"
160        logger.info('%s tried to edit submitted application record' % (reg_no))
161        res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= 'application',
162                                schema_id= 'application',
163                                layout_mode = mode,
164                                context=context,
165                                mapping={},
166                                ob=object,
167                                commit = False,
168                                )
169    else:
170        mode = "edit"
171        psm = "Content changed"
172        data['status'] = "edited"
173        context.applicants_catalog.modifyRecord(**data)
174        logger.info('%s modified application record' % (reg_no))
175
176
177
178return context.apply_pume_form(rendered = res,
179                            psm = psm,
180                            #psm = "%s, %s" % (psm,ds),
181                            mode = mode,
182                            ds = ds,
183                            )
184
185
Note: See TracBrowser for help on using the repository browser.