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

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

show submitbutton only if passport is uploaded (in custom)

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