source: WAeUP_SRP/base/skins/waeup_student/apply_admission_manage.py @ 3671

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

use only one application schema (import and editing)

File size: 3.9 KB
Line 
1## Script (Python) "apply_admission_manage"
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_admission_manage.py 2225 2007-09-12 21:04:51Z henrik $
11"""
12search for  Pume Applications
13"""
14
15try:
16    from Products.zdb import set_trace
17except:
18    def set_trace():
19        pass
20
21import DateTime
22import logging
23logger = logging.getLogger('Skins.apply_admission_manage')
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
27current = DateTime.DateTime()
28pr = context.portal_registration
29request = REQUEST
30
31
32if not context.isSectionOfficer():
33    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.absolute_url())
34
35#type_name = 'StudentApplication'
36#ti = context.portal_types[type_name]
37#REQUEST.set('type_name',type_name)
38
39search = "search" in request.keys()
40reset = "reset" in request.keys()
41edit = "edit" in request.keys()
42lt = context.portal_layouts
43
44reg_no = request.get('reg_no','').upper()
45new_reg_no = request.get('new_reg_no','').upper()
46
47if reset or edit:
48    reg_no = reg_no
49elif new_reg_no:
50    reg_no = new_reg_no
51
52res = ''
53psm = ''
54object = {}
55ds = []
56found = False
57
58validate = not search
59
60if reg_no:
61    brains = context.applicants_catalog(reg_no = reg_no)
62
63    if len(brains) == 1:
64        found = True
65        for field in context.applicants_catalog.schema():
66            object[field] = getattr(brains[0],field,None)
67        res,psm,ds = lt.renderLayout(layout_id= 'application_manage',
68                                     schema_id= 'import_application',
69                                     layout_mode = "edit",
70                                     context=context,
71                                     mapping=validate and REQUEST,
72                                     ob=object,
73                                     commit = False,
74                                    )
75
76
77if psm == 'invalid':
78    return context.apply_admission_manage_form(rendered = res,
79                                   psm = "Please correct your input!",
80                                   #psm = "%s, %s" % (psm,ds),
81                                   ds = ds,
82                                  )
83elif psm == '':
84    if search and not found:
85        psm = 'Registration Number not found!'
86    return context.apply_admission_manage_form(rendered = res,
87                                   psm = psm,
88                                   reg_no = reg_no,
89                                   ds = ds,
90                                  )
91elif psm == 'valid':
92    psm = ''
93    pass
94
95data = {}
96dm = ds.getDataModel()
97for field in context.applicants_catalog.schema():
98    if dm.has_key("%s" % field):
99        data[field] = dm.get(field)
100
101
102if reset and reg_no:
103    #data['reg_no'] = reg_no
104    psm = "You successfully reset the record! The applicant will be able to edit and resubmit the data."
105    data['status'] = "reset"
106    context.applicants_catalog.modifyRecord(**data)
107    logger.info('%s reset application record of %s' % (member,reg_no))
108
109if edit and reg_no:
110    #data['reg_no'] = reg_no
111    psm = "Content changed!"
112    context.applicants_catalog.modifyRecord(**data)
113    logger.info('%s edited application record of %s' % (member,reg_no))
114
115
116brains = context.applicants_catalog(reg_no = reg_no)
117for field in context.applicants_catalog.schema():
118    object[field] = getattr(brains[0],field,None)
119
120res,psm_dummy,ds = lt.renderLayout(layout_id= 'application_manage',
121                             schema_id= 'import_application',
122                             layout_mode = "edit",
123                             context=context,
124                             ob=object,
125                             commit = False,
126                            )
127
128
129return context.apply_admission_manage_form(rendered = res,
130                                      psm = psm,
131                                      reg_no = reg_no,
132                                      ds = ds
133                                     )
134
135
Note: See TracBrowser for help on using the repository browser.