## Script (Python) "apply_pume_manage" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST ##title= ## # $Id: apply_pume_manage.py 2168 2007-08-29 06:24:39Z henrik $ """ search for Pume Applications """ try: from Products.zdb import set_trace except: def set_trace(): pass import DateTime import logging logger = logging.getLogger('Skins.apply_pume_manage') mtool = context.portal_membership member = mtool.getAuthenticatedMember() current = DateTime.DateTime() pr = context.portal_registration request = REQUEST if not context.isSectionOfficer(): return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.absolete_url()) #type_name = 'StudentApplication' #ti = context.portal_types[type_name] #REQUEST.set('type_name',type_name) reset = "reset" in request.keys() edit = "edit" in request.keys() lt = context.portal_layouts reg_no = request.get('reg_no','').upper() new_reg_no = request.get('new_reg_no','').upper() if reset or edit: reg_no = reg_no elif new_reg_no: reg_no = new_reg_no res = '' psm = '' object = {} ds = [] if reg_no: brains = context.applicants_catalog(reg_no = reg_no) if len(brains) == 1: for field in context.applicants_catalog.schema(): object[field] = getattr(brains[0],field,None) res,psm,ds = lt.renderLayout(layout_id= 'application_manage', schema_id= 'application', layout_mode = "edit", context=context, mapping=REQUEST, ob=object, commit = False, ) if psm == 'invalid': return context.apply_pume_manage_form(rendered = res, psm = "Please correct your input!", #psm = "%s, %s" % (psm,ds), ds = ds, ) elif psm == '': psm = 'Registration Number not found!' return context.apply_pume_manage_form(rendered = res, psm = psm, ds = ds, ) elif psm == 'valid': psm = '' pass data = {} dm = ds.getDataModel() for field in context.applicants_catalog.schema(): if dm.has_key("%s" % field): data[field] = dm.get(field) if reset and reg_no: #data['reg_no'] = reg_no psm = "You successfully reset the record! The applicant will be able to edit and resubmit the data." data['status'] = "reset" context.applicants_catalog.modifyRecord(**data) logger.info('%s reset application record of %s' % (member,reg_no)) if edit and reg_no: #data['reg_no'] = reg_no psm = "Content changed!" context.applicants_catalog.modifyRecord(**data) logger.info('%s edited application record of %s' % (member,reg_no)) #set_trace() if reg_no: brains = context.applicants_catalog(reg_no = reg_no) if len(brains) == 1: for field in context.applicants_catalog.schema(): object[field] = getattr(brains[0],field,None) res,psm_dummy,ds = lt.renderLayout(layout_id= 'application_manage', schema_id= 'application', layout_mode = "edit", context=context, ob=object, commit = False, ) else: psm = "reg no %s not found" % reg_no return context.apply_pume_manage_form(rendered = res, psm = psm, reg_no = reg_no, ds = ds )