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

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

beautify apply_pume layout

  • 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 2141 2007-08-21 16:50:33Z 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
[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))
[2141]65
[2098]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
[2103]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                                  )
[2105]82
[2098]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
[2102]98data = {}
[2114]99dm = ds.getDataModel()
100#set_trace()
[2102]101for field in context.applicants_catalog.schema():
[2114]102    if dm.has_key("%s" % field):
103        data[field] = dm.get(field)
[2102]104data['reg_no'] = reg_no
[2134]105#set_trace()
[2102]106if apply_pume:
[2111]107    if submitted:
108        mode = "view"
109        psm = "The form has already been submitted and you are not allowed to resubmit the data!"
[2119]110        logger.info('%s tried to resubmit application record' % (reg_no))
[2111]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                                )
[2136]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))
[2111]123    elif not request.has_key('confirm'):
[2102]124        mode = "edit"
[2111]125        psm = "Please confirm Passport Photograph!"
[2119]126        logger.info('%s tried to submit without ticking confirmation check box' % (reg_no))
[2102]127    else:
128        mode = "view"
[2111]129        psm = "You successfully applied for PUME!"
[2106]130        data['application_date'] = current
131        data['status'] = "submitted"
[2111]132        context.applicants_catalog.modifyRecord(**data)
[2119]133        logger.info('%s modified and submitted application record' % (reg_no))
[2108]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,
[2111]141                                )
[2102]142elif create:
143    if submitted:
144        mode = "view"
[2119]145        logger.info('%s views application record' % (reg_no))
[2102]146    else:
147        mode = "edit"
[2141]148        logger.info('%s edits application record' % (reg_no))
[2102]149    psm = ""
150    #set_trace()
151    object['pin'] = str(ds.get('pin'))
[2111]152    res,psm,ds_dummy = lt.renderLayout(layout_id= 'application',
[2102]153                                schema_id= 'application',
154                                layout_mode = mode,
155                                context=context,
156                                mapping={},
157                                ob=object,
158                                commit = False,
159                                )
160elif edit:
[2114]161    #set_trace()
[2111]162    if submitted:
163        mode = "view"
164        psm = "The form has already been submitted and you are not allowed to modify the data!"
[2119]165        logger.info('%s tried to edit submitted application record' % (reg_no))
[2111]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)
[2119]179        logger.info('%s modified application record' % (reg_no))
[2098]180
[2108]181
[2111]182
[2102]183return context.apply_pume_form(rendered = res,
184                            psm = psm,
185                            #psm = "%s, %s" % (psm,ds),
186                            mode = mode,
187                            ds = ds,
188                            )
[2098]189
[2102]190
Note: See TracBrowser for help on using the repository browser.