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

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

first version of apply_pume, without passport and ugly layout.

  • Property svn:keywords set to Id
File size: 3.3 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 2098 2007-08-15 16:22:25Z 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()
31mode = request.get('mode','')
32if not mode:
33    if apply_pume or edit:
34        mode = "edit"
35    else:
36        mode = "create"
37validate = create or edit or apply_pume
38
39lt = context.portal_layouts
40reg_no = request.get('widget__reg_no','').upper()
41if not reg_no:
42    reg_no = request.get('reg_no','').upper()
43   
44object = {}
45#set_trace()
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
52res,psm,ds = lt.renderLayout(layout_id= 'application',
53                             schema_id= 'application',
54                             layout_mode = mode,
55                             context=context,
56                             mapping=validate and REQUEST,
57                             ob=object,
58                             commit = False,
59                            )
60
61if psm == 'invalid':
62    return context.apply_pume_form(rendered = res,
63                                   psm = "Please correct your input!",
64                                   #psm = "%s, %s" % (psm,ds),
65                                   mode = mode,
66                                   ds = ds,
67                                  )
68elif psm == '':
69    return context.apply_pume_form(rendered = res,
70                                   psm = None,
71                                   ds = ds,
72                                   mode = mode,
73                                  )
74elif psm == 'valid':
75    pass
76if create or edit or apply_pume:
77    data = {}
78    for field in context.applicants_catalog.schema():
79        if ds.has_key(field) and request.has_key("widget__%s" % field):
80            data[field] = ds.get(field)
81    data['reg_no'] = reg_no
82    if apply_pume:
83        data['registration_date'] = current
84        data['status'] = "submitted"
85    context.applicants_catalog.modifyRecord(**data)
86    if apply_pume:
87        if not request.has_key('confirm'):
88            return context.apply_pume_form(rendered = res,
89                                        psm = "Please confirm Passport Photograph",
90                                        #psm = "%s, %s" % (psm,ds),
91                                        mode = mode,
92                                        ds = ds,
93                                        )
94                   
95        return request.RESPONSE.redirect("%s/apply_pume?mode=view&reg_no=%s" %
96                                     (context.absolute_url(),ds.get('reg_no')))
97    elif edit or create:
98        return request.RESPONSE.redirect("%s/apply_pume?mode=edit&reg_no=%s" %
99                                     (context.absolute_url(),ds.get('reg_no')))
100
101
Note: See TracBrowser for help on using the repository browser.