## Script (Python) "apply_admission" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST ##title= ## # $Id: apply_admission.py 2380 2007-10-18 07:39:19Z henrik $ """ process the Application Form """ try: from Products.zdb import set_trace except: def set_trace(): pass import DateTime import logging logger = logging.getLogger('Skins.apply_admission') mtool = context.portal_membership member = mtool.getAuthenticatedMember() current = DateTime.DateTime() pr = context.portal_registration request = REQUEST #type_name = 'StudentApplication' #ti = context.portal_types[type_name] #REQUEST.set('type_name',type_name) create = "create" in request.keys() apply_admission = "apply" in request.keys() edit = "edit" in request.keys() slip = "slip" in request.keys() manage = "manage" in request.keys() submitted = False mode = request.get('mode','') if not mode: if apply_admission or edit or manage: mode = "edit" else: mode = "create" validate = create or edit or apply_admission if manage: validate = False without_reg_no = False lt = context.portal_layouts pin = request.form.get('pin','') reg_no = request.get('widget__reg_no','').upper() if not reg_no: reg_no = request.form.get('reg_no','').upper() if not reg_no: reg_no = request.get('widget__pin_n','').upper() object = {} 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) if not object['passport']: object['passport'] = '' if object['status'] and 'submitted' in object['status']: submitted = True if not (create or slip) and (pin != object['pin'] and not context.isSectionOfficer()): logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) # For the next application session it should be reverted to # (see comment 09/06/07 16:40:52 in ticket #328): #if not create and (pin != object['pin'] and not context.isSectionOfficer()): #logger.info('%s/%s entered wrong pin %s' % (member,reg_no,pin)) #return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) screening_types = ('prence','pume','pce','pde','cest') headings = {} headings['pume'] = 'Apply for Post UME Screening Test (2007/2008)! ' headings['pde'] = 'Apply for Post UDE Screening Test (2007/2008)! ' headings['prence'] = 'Apply for Pre-NCE Programme (2007/2008)! ' headings['pce'] = 'Apply for PCE Screening (2007/2008)! ' headings['cest'] = 'Apply for Common Entrance Screening Test (2007/2008)! ' headings_slip = {} headings_slip['pume'] = 'Post UME Screening (2007/2008) Aknowledgement Slip!' headings_slip['pde'] = 'Post UDE Screening (2007/2008) Aknowledgement Slip' headings_slip['prence'] = 'Pre-NCE Application (2007/2008) Aknowledgement Slip' headings_slip['pce'] = 'PCE Screening (2007/2008) Aknowledgement Slip' headings_slip['cest'] = 'Common Entrance Screening (2007/2008) Aknowledgement Slip' deadline = {} deadline['pume'] = '[Date of PUME Deadline]' deadline['pde'] = 'Saturday, 3rd November 2007' deadline['prence'] = '[Date of PRENCE Deadline]' deadline['pce'] = '[Date of PCE Deadline]' deadline['cest'] = '[Date of CEST Deadline]' info = {} if traverse_subpath and traverse_subpath[0] in screening_types: screening_type = info['screening_type'] = traverse_subpath[0] info['heading'] = headings[screening_type] info['heading_slip'] = headings_slip[screening_type] info['deadline'] = deadline[screening_type] layout = "application_%s" % screening_type without_reg_no = screening_type in ('prence',) elif manage: if object['screening_type']: st = object['screening_type'] else: st = 'pume' screening_type = info['screening_type'] = st info['heading'] = headings[screening_type] info['heading_slip'] = headings_slip[screening_type] info['deadline'] = deadline[screening_type] layout = "application_%s" % screening_type without_reg_no = screening_type in ('prence',) else: return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) if slip: mode = "view_slip" logger.info('%s/%s views application slip' % (member,reg_no)) res,psm,ds = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping=validate and REQUEST, ob=object, commit = False, ) if slip: return context.apply_admission_slip(rendered = res, psm = "", mode = mode, ds = ds, info = info, ) if psm == 'invalid': return context.apply_admission_form(rendered = res, psm = "Please correct your input!", mode = mode, ds = ds, info = info, ) elif psm == '' and not manage: return context.apply_admission_form(rendered = res, psm = psm, ds = ds, mode = mode, info = info, ) # elif psm == 'valid' or (psm == '' and manage): # pass if without_reg_no: reg_no = ds.get('reg_no') data = {} dm = ds.getDataModel() for field in context.applicants_catalog.schema(): if dm.has_key("%s" % field): data[field] = dm.get(field) data['reg_no'] = reg_no if apply_admission: if submitted: mode = "view" psm = "The form has already been submitted and you are not allowed to resubmit the data!" logger.info('%s/%s tried to resubmit application record' % (member,reg_no)) res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping={}, ob=object, commit = False, ) elif not request.has_key('confirm'): mode = "edit" psm = "Please confirm Passport Photograph!" logger.info('%s/%s tried to submit without ticking confirmation check box' % (member,reg_no)) else: mode = "view" psm = "You successfully applied for admission!" if object['status'] == 'edited': data['status'] = "submitted" data['application_date'] = current logger.info('%s/%s modified and submitted application record' % (member,reg_no)) elif object['status'] == 'reset': data['status'] = 'resubmitted on %s' % DateTime.DateTime().strftime('%A, %B %d, %Y') logger.info('%s/%s modified and resubmitted application record' % (member,reg_no)) object['status'] = data['status'] context.applicants_catalog.modifyRecord(**data) res,psm_dummy,ds = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping=validate and REQUEST, ob=object, commit = False, ) elif create: if submitted: mode = "view" logger.info('%s/%s views application record' % (member,reg_no)) else: mode = "edit" logger.info('%s/%s edits application record' % (member,reg_no)) psm = "" if without_reg_no: object['reg_no'] = reg_no object['pin'] = str(ds.get('pin')) res,psm,ds_dummy = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping={}, ob=object, commit = False, ) elif edit: if submitted: mode = "view" psm = "The form has already been submitted and you are not allowed to modify the data!" logger.info('%s/%s tried to edit submitted application record' % (member,reg_no)) res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping={}, ob=object, commit = False, ) else: mode = "edit" psm = "Content changed!" data['status'] = "edited" #set_trace() context.applicants_catalog.modifyRecord(**data) logger.info('%s/%s modified application record' % (member,reg_no)) elif manage: if submitted: mode = "view" psm = "You are now assuming the applicant's role!" logger.info('%s/%s entered application record' % (member,reg_no)) res,psm_dummy,ds_dummy = lt.renderLayout(layout_id= layout, schema_id= 'application', layout_mode = mode, context=context, mapping={}, ob=object, commit = False, ) else: mode = "edit" psm = "You are now assuming the applicant's role!" logger.info('%s/%s entered application record' % (member,reg_no)) try: passport_uploaded = bool(data['passport']) except: passport_uploaded = False return context.apply_admission_form(rendered = res, psm = psm, mode = mode, show_submit = passport_uploaded, ds = ds, info = info, )