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

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

better version

  • Property svn:keywords set to Id
File size: 3.7 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 2102 2007-08-16 11:45:27Z 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()
31submitted = False
32mode = request.get('mode','')
33if not mode:
34    if apply_pume or edit:
35        mode = "edit"
36    else:
37        mode = "create"
38validate = create or edit or apply_pume
39
40lt = context.portal_layouts
41reg_no = request.get('widget__reg_no','').upper()
42if not reg_no:
43    reg_no = request.form.get('reg_no','').upper()
44pin = request.form.get('pin','')
45object = {}
46if reg_no:
47    brains = context.applicants_catalog(reg_no = reg_no)
48    if len(brains) == 1:
49        for field in context.applicants_catalog.schema():
50            object[field] = getattr(brains[0],field,None)
51        if object['status'] == "submitted":
52            submitted = True
53        #set_trace()
54        if not create and pin != object['pin']:
55            return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
56
57res,psm,ds = lt.renderLayout(layout_id= 'application',
58                             schema_id= 'application',
59                             layout_mode = mode,
60                             context=context,
61                             mapping=validate and REQUEST,
62                             ob=object,
63                             commit = False,
64                            )
65
66set_trace()
67if psm == 'invalid':
68    return context.apply_pume_form(rendered = res,
69                                   psm = "Please correct your input!",
70                                   #psm = "%s, %s" % (psm,ds),
71                                   mode = mode,
72                                   ds = ds,
73                                  )
74elif psm == '':
75    return context.apply_pume_form(rendered = res,
76                                   psm = None,
77                                   ds = ds,
78                                   mode = mode,
79                                  )
80elif psm == 'valid':
81    pass
82data = {}
83for field in context.applicants_catalog.schema():
84    if ds.has_key(field) and request.has_key("widget__%s" % field):
85        data[field] = ds.get(field)
86data['reg_no'] = reg_no
87if apply_pume:
88    data['registration_date'] = current
89    data['status'] = "submitted"
90context.applicants_catalog.modifyRecord(**data)
91if apply_pume:
92    if not request.has_key('confirm'):
93        mode = "edit"
94        psm = "Please confirm Passport Photograph"
95    else:
96        mode = "view"
97        psm = "You successfully applied for PUME"
98elif create:
99    if submitted:
100        mode = "view"
101    else:
102        mode = "edit"
103    psm = ""
104    #set_trace()
105    object['pin'] = str(ds.get('pin'))
106    res,psm,dummy = lt.renderLayout(layout_id= 'application',
107                                schema_id= 'application',
108                                layout_mode = mode,
109                                context=context,
110                                mapping={},
111                                ob=object,
112                                commit = False,
113                                )
114elif edit:
115    mode = "edit"
116    psm = "Content changed"
117
118return context.apply_pume_form(rendered = res,
119                            psm = psm,
120                            #psm = "%s, %s" % (psm,ds),
121                            mode = mode,
122                            ds = ds,
123                            )
124
125
Note: See TracBrowser for help on using the repository browser.