source: WAeUP_SRP/trunk/skins/waeup_student/apply_pume_manage.py @ 2168

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

add new layout for application record management
(please test!)

  • Property svn:keywords set to Id
File size: 3.8 KB
RevLine 
[2160]1## Script (Python) "apply_pume_manage"
[2156]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_manage.py 2168 2007-08-29 06:24:39Z 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_pume_manage')
24mtool = context.portal_membership
25member = mtool.getAuthenticatedMember()
26
27current = DateTime.DateTime()
28pr = context.portal_registration
29request = REQUEST
30
31
[2158]32if not context.isSectionOfficer():
[2156]33    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.absolete_url())
[2158]34
[2156]35#type_name = 'StudentApplication'
36#ti = context.portal_types[type_name]
37#REQUEST.set('type_name',type_name)
38reset = "reset" in request.keys()
[2168]39edit = "edit" in request.keys()
[2156]40lt = context.portal_layouts
[2157]41
[2160]42reg_no = request.get('reg_no','').upper()
43new_reg_no = request.get('new_reg_no','').upper()
[2157]44
[2168]45if reset or edit:
[2157]46    reg_no = reg_no
47elif new_reg_no:
48    reg_no = new_reg_no
49
[2156]50res = ''
51psm = ''
52object = {}
[2168]53ds = []
54
55if reg_no:
56    brains = context.applicants_catalog(reg_no = reg_no)
57    if len(brains) == 1:
58        for field in context.applicants_catalog.schema():
59            object[field] = getattr(brains[0],field,None)
60
61        res,psm,ds = lt.renderLayout(layout_id= 'application_manage',
62                                     schema_id= 'application',
63                                     layout_mode = "edit",
64                                     context=context,
65                                     mapping=REQUEST,
66                                     ob=object,
67                                     commit = False,
68                                    )
69if psm == 'invalid':
70    return context.apply_pume_manage_form(rendered = res,
71                                   psm = "Please correct your input!",
72                                   #psm = "%s, %s" % (psm,ds),
73                                   ds = ds,
74                                  )
75elif psm == '':
76    psm = 'Registration Number not found!'
77    return context.apply_pume_manage_form(rendered = res,
78                                   psm = psm,
79                                   ds = ds,
80                                  )
81elif psm == 'valid':
82    psm = ''
83    pass
84   
[2156]85data = {}
[2168]86dm = ds.getDataModel()
87for field in context.applicants_catalog.schema():
88    if dm.has_key("%s" % field):
89        data[field] = dm.get(field)
90
91
[2156]92if reset and reg_no:
[2168]93    #data['reg_no'] = reg_no
[2157]94    psm = "You successfully reset the record! The applicant will be able to edit and resubmit the data."
[2161]95    data['status'] = "reset"
[2156]96    context.applicants_catalog.modifyRecord(**data)
97    logger.info('%s reset application record of %s' % (member,reg_no))
[2157]98
[2168]99if edit and reg_no:
100    #data['reg_no'] = reg_no
101    psm = "Content changed!"
102    context.applicants_catalog.modifyRecord(**data)
103    logger.info('%s edited application record of %s' % (member,reg_no))
104
[2158]105#set_trace()
106
[2168]107
[2156]108if reg_no:
109    brains = context.applicants_catalog(reg_no = reg_no)
110    if len(brains) == 1:
111        for field in context.applicants_catalog.schema():
112            object[field] = getattr(brains[0],field,None)
[2168]113        res,psm_dummy,ds = lt.renderLayout(layout_id= 'application_manage',
[2156]114                                     schema_id= 'application',
[2168]115                                     layout_mode = "edit",
[2156]116                                     context=context,
117                                     ob=object,
118                                     commit = False,
119                                    )
120    else:
121        psm = "reg no %s not found" % reg_no
[2158]122
[2156]123return context.apply_pume_manage_form(rendered = res,
124                                      psm = psm,
125                                      reg_no = reg_no,
[2157]126                                      ds = ds
[2156]127                                     )
128
129
Note: See TracBrowser for help on using the repository browser.