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

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

print slip added

  • Property svn:keywords set to Id
File size: 4.1 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 2103 2007-08-16 12:16:32Z 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
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"
59res,psm,ds = lt.renderLayout(layout_id= 'application',
60                             schema_id= 'application',
61                             layout_mode = mode,
62                             context=context,
63                             mapping=validate and REQUEST,
64                             ob=object,
65                             commit = False,
66                            )
67
68if slip:
69    return context.apply_pume_slip(rendered = res,
70                                   psm = "",
71                                   #psm = "%s, %s" % (psm,ds),
72                                   mode = mode,
73                                   ds = ds,
74                                  )
75   
76if psm == 'invalid':
77    return context.apply_pume_form(rendered = res,
78                                   psm = "Please correct your input!",
79                                   #psm = "%s, %s" % (psm,ds),
80                                   mode = mode,
81                                   ds = ds,
82                                  )
83elif psm == '':
84    return context.apply_pume_form(rendered = res,
85                                   psm = None,
86                                   ds = ds,
87                                   mode = mode,
88                                  )
89elif psm == 'valid':
90    pass
91data = {}
92for field in context.applicants_catalog.schema():
93    if ds.has_key(field) and request.has_key("widget__%s" % field):
94        data[field] = ds.get(field)
95data['reg_no'] = reg_no
96if apply_pume:
97    data['registration_date'] = current
98    data['status'] = "submitted"
99context.applicants_catalog.modifyRecord(**data)
100if apply_pume:
101    if not request.has_key('confirm'):
102        mode = "edit"
103        psm = "Please confirm Passport Photograph"
104    else:
105        mode = "view"
106        psm = "You successfully applied for PUME"
107elif create:
108    if submitted:
109        mode = "view"
110    else:
111        mode = "edit"
112    psm = ""
113    #set_trace()
114    object['pin'] = str(ds.get('pin'))
115    res,psm,dummy = lt.renderLayout(layout_id= 'application',
116                                schema_id= 'application',
117                                layout_mode = mode,
118                                context=context,
119                                mapping={},
120                                ob=object,
121                                commit = False,
122                                )
123elif edit:
124    mode = "edit"
125    psm = "Content changed"
126
127return context.apply_pume_form(rendered = res,
128                            psm = psm,
129                            #psm = "%s, %s" % (psm,ds),
130                            mode = mode,
131                            ds = ds,
132                            )
133
134
Note: See TracBrowser for help on using the repository browser.