def request_nomove(request, is_nomove): applicant = request.applicant admitted = applicant.is_admitted() if not admitted: return HttpResponseForbidden() first_admission = (applicant.admission_results.count() == 1) if first_admission: return HttpResponseForbidden() if request.method != 'POST': return HttpResponseForbidden() # check for deadline if admission_major_pref_deadline_passed(): return render_to_response('confirmation/pref_deadline_passed.html') current_round = AdmissionRound.get_recent() round_number = current_round.number admission_pref = applicant.get_admission_major_preference(round_number) if not admission_pref: return HttpResponseForbidden() admission_pref.is_nomove_request = is_nomove admission_pref.save() Log.create("request nomove (%s) - from: %s" % (str(is_nomove), request.META['REMOTE_ADDR']), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return redirect('status-index')
def confirm_round2(request): """ Obsoleted """ return HttpResponseForbidden() applicant = request.applicant if not applicant.submission_info.doc_reviewed_complete: return HttpResponseForbidden() if round2_confirmation_deadline_passed(): return HttpResponseForbidden() try: confirmation = applicant.round2_confirmation has_submitted = True except Round2ApplicantConfirmation.DoesNotExist: confirmation = Round2ApplicantConfirmation() confirmation.applicant = applicant has_submitted = False if request.method == 'POST': if 'cancel' in request.POST: if has_submitted: request.session['notice'] = 'ตัวเลือกการยืนยันไม่ถูกแก้ไข' else: request.session[ 'notice'] = 'ไม่ยืนยันการขอรับพิจารณาในการสมัครโครงการรับตรง (รอบที่ 2)' return HttpResponseRedirect(reverse('status-index')) else: form = Round2ConfirmationForm(request.POST, instance=confirmation) if form.is_valid(): confirmation = form.save() Log.create( "Confirmation round 2 - id: %d, from: %s, choices: %d,%d" % (applicant.id, request.META['REMOTE_ADDR'], confirmation.is_confirmed, confirmation.is_applying_for_survey_engr), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) request.session['notice'] = 'จัดเก็บตัวเลือกการยืนยันเรียบร้อย' return HttpResponseRedirect(reverse('status-index')) else: form = Round2ConfirmationForm(instance=confirmation) return render_to_response('confirmation/round2_confirmation.html', { 'applicant': applicant, 'form': form, 'has_submitted': has_submitted })
def confirm_round2(request): """ Obsoleted """ return HttpResponseForbidden() applicant = request.applicant if not applicant.submission_info.doc_reviewed_complete: return HttpResponseForbidden() if round2_confirmation_deadline_passed(): return HttpResponseForbidden() try: confirmation = applicant.round2_confirmation has_submitted = True except Round2ApplicantConfirmation.DoesNotExist: confirmation = Round2ApplicantConfirmation() confirmation.applicant = applicant has_submitted = False if request.method == 'POST': if 'cancel' in request.POST: if has_submitted: request.session['notice'] = 'ตัวเลือกการยืนยันไม่ถูกแก้ไข' else: request.session['notice'] = 'ไม่ยืนยันการขอรับพิจารณาในการสมัครโครงการรับตรง (รอบที่ 2)' return HttpResponseRedirect(reverse('status-index')) else: form = Round2ConfirmationForm(request.POST, instance=confirmation) if form.is_valid(): confirmation = form.save() Log.create("Confirmation round 2 - id: %d, from: %s, choices: %d,%d" % (applicant.id, request.META['REMOTE_ADDR'], confirmation.is_confirmed, confirmation.is_applying_for_survey_engr), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) request.session['notice'] = 'จัดเก็บตัวเลือกการยืนยันเรียบร้อย' return HttpResponseRedirect(reverse('status-index')) else: form = Round2ConfirmationForm(instance = confirmation) return render_to_response('confirmation/round2_confirmation.html', { 'applicant': applicant, 'form': form, 'has_submitted': has_submitted })
def main(): REMOVED_FIELDS = ['picture', 'nat_id', 'gat_score', 'pat1_score', 'pat3_score', 'anet_score', 'abroad_edu_certificat'] for applicant in Applicant.objects.all(): if ((not applicant.is_submitted) or (applicant.submission_info.doc_reviewed_complete)): continue else: review_results = ReviewFieldResult.objects.filter(applicant=applicant) if len(review_results)==0: # have no reviews continue print applicant.ticket_number(), applicant.full_name(), passed = True changed = False for r in review_results: if not r.is_passed: f = ReviewField.get_field_by_id(r.review_field_id) if f.short_name in REMOVED_FIELDS: print f.short_name, '(fixed)', r.is_passed = True r.internal_note = r.internal_note + '(fixed by admin)' r.save() msg = ('Updated ReviewFieldResult (id:%d) %s for %d, set to passed' % (r.id, f.short_name, applicant.id)) Log.create(msg, 'console', applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) changed = True else: passed = False if changed and passed: print 'PASSED' applicant.submission_info.doc_reviewed_complete = True applicant.submission_info.save() msg = ('Updated SubmissionInfo (id:%d) for %d, set doc_reviewed_complete to True' % (applicant.submission_info.applicantion_id, applicant.id)) Log.create(msg, 'console', applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) else: print 'FAILED'
def render_confirmation_form_second_round(request, applicant): second_round_admitted = False if applicant.has_admission_result(): second_round_admitted = (applicant.admission_result.is_final_admitted and (not applicant.admission_result.is_admitted)) if not second_round_admitted: raise Http404 admission_result = applicant.admission_result Log.create("view confirmation second round - id: %d, from: %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return render_to_response('confirmation/second_round_confirmation.html', { 'applicant': applicant, 'admission_result': admission_result })
def quota_reset_choice(request): """ reset choice between quota & direct """ applicant = request.applicant if not applicant.has_additional_result: return HttpResponseForbidden() additional_result = applicant.additional_result current_round = AdmissionRound.get_recent() round_number = current_round.number admission_result = applicant.get_latest_admission_result() if additional_result.round_number != round_number: return HttpResponseForbidden() if not admission_result: return HttpResponseForbidden() if request.method!='POST': return HttpResponseForbidden() # remove from quota waived AdmissionWaiver.unwaive_applicant(applicant) # remove from direct waived additional_result.is_waived = False additional_result.save() AdmissionConfirmation.delete_for(applicant, current_round.number) AdmissionMajorPreference.objects.filter(applicant=applicant, round_number=current_round.number).delete() registration = applicant.get_student_registration() if registration: registration.delete() Log.create("Reset quota/direct waiver applicant %s from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index')
def quota_reset_choice(request): """ reset choice between quota & direct """ applicant = request.applicant if not applicant.has_additional_result: return HttpResponseForbidden() additional_result = applicant.additional_result current_round = AdmissionRound.get_recent() round_number = current_round.number admission_result = applicant.get_latest_admission_result() if additional_result.round_number != round_number: return HttpResponseForbidden() if not admission_result: return HttpResponseForbidden() if request.method != 'POST': return HttpResponseForbidden() # remove from quota waived AdmissionWaiver.unwaive_applicant(applicant) # remove from direct waived additional_result.is_waived = False additional_result.save() AdmissionConfirmation.delete_for(applicant, current_round.number) AdmissionMajorPreference.objects.filter( applicant=applicant, round_number=current_round.number).delete() registration = applicant.get_student_registration() if registration: registration.delete() Log.create("Reset quota/direct waiver applicant %s from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index')
def quota_choice(request, applicant, admission_result): current_round = AdmissionRound.get_recent() round_number = current_round.number additional_result = applicant.additional_result is_result_for_current_round = ( additional_result.round_number == round_number) can_edit = (not admission_major_pref_deadline_passed() ) and is_result_for_current_round student_registration = applicant.get_student_registration() if request.method == 'POST' and not can_edit: return render_to_response('confirmation/pref_deadline_passed.html', {'admission_round': current_round}) if request.method == 'POST': if request.POST['major_select'] == 'quota': AdmissionWaiver.waive_applicant(applicant) Log.create("Waive applicant %s to quota from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index') if request.POST['major_select'] == 'direct': additional_result.is_waived = True additional_result.save() Log.create("Waive applicant %s to direct from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index') return render_to_response( 'confirmation/quota/choices.html', { 'applicant': applicant, 'admission_result': admission_result, 'additional_result': additional_result, 'student_registration': student_registration, 'can_edit': can_edit, 'can_log_out': True })
def quota_choice(request, applicant, admission_result): current_round = AdmissionRound.get_recent() round_number = current_round.number additional_result = applicant.additional_result is_result_for_current_round = (additional_result.round_number == round_number) can_edit = (not admission_major_pref_deadline_passed()) and is_result_for_current_round student_registration = applicant.get_student_registration() if request.method=='POST' and not can_edit: return render_to_response('confirmation/pref_deadline_passed.html', {'admission_round': current_round}) if request.method=='POST': if request.POST['major_select']=='quota': AdmissionWaiver.waive_applicant(applicant) Log.create("Waive applicant %s to quota from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index') if request.POST['major_select']=='direct': additional_result.is_waived = True additional_result.save() Log.create("Waive applicant %s to direct from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('status-index') return render_to_response('confirmation/quota/choices.html', { 'applicant': applicant, 'admission_result': admission_result, 'additional_result': additional_result, 'student_registration': student_registration, 'can_edit': can_edit, 'can_log_out': True })
def generate_password(request, applicant_id): applicant = get_object_or_404(Applicant, pk=applicant_id) if not (applicant.can_password_be_generated() and request.user.is_staff): return HttpResponseForbidden() new_password = applicant.random_password() applicant.save() submission_info = applicant.submission_info log = Log.create("Generated password: %s" % (applicant_id,), request.user.username, applicant_id=int(applicant_id), applicantion_id=submission_info.applicantion_id) return render_to_response("review/password_generated.html", { 'applicant': applicant, 'password': new_password })
def create_payment(request, applicant_id): applicant = get_object_or_404(Applicant, pk=applicant_id) try: submission_info = applicant.submission_info except: submission_info = None if submission_info and (not submission_info.is_paid): submission_info.is_paid = True submission_info.paid_at = datetime.now() submission_info.save() log = Log.create("Manual accept payment: %s (%s)" % (applicant_id, applicant.national_id), request.user.username, applicant_id=int(applicant_id)) return redirect('review-show-app', applicant_id)
def create_payment(request, applicant_id): applicant = get_object_or_404(Applicant, pk=applicant_id) try: submission_info = applicant.submission_info except: submission_info = None if submission_info and (not submission_info.is_paid): submission_info.is_paid = True submission_info.paid_at = datetime.now() submission_info.save() log = Log.create("Manual accept payment: %s (%s)" % (applicant_id, applicant.national_id), request.user.username, applicant_id=int(applicant_id)) return redirect('review-show-app',applicant_id)
def generate_password(request, applicant_id): applicant = get_object_or_404(Applicant, pk=applicant_id) if not (applicant.can_password_be_generated() and request.user.is_staff): return HttpResponseForbidden() new_password = applicant.random_password() applicant.save() submission_info = applicant.submission_info log = Log.create("Generated password: %s" % (applicant_id, ), request.user.username, applicant_id=int(applicant_id), applicantion_id=submission_info.applicantion_id) return render_to_response("review/password_generated.html", { 'applicant': applicant, 'password': new_password })
def update_majors(request): max_major_rank = settings.MAX_MAJOR_RANK if max_major_rank == 1: return update_major_single_choice(request) from form_views import prepare_major_selections applicant = request.applicant form_data = { 'majors': Major.get_all_majors() } if request.method == 'POST': if 'cancel' not in request.POST: result, pref_list, errors = handle_major_form(request, max_major_rank) log = Log.create("Update major pref: %s from %s" % (applicant.id,request.META['REMOTE_ADDR'])) if result: request.session['notice'] = 'การแก้ไขอันดับสาขาวิชาเรียบร้อย' return HttpResponseRedirect(reverse('status-index')) selections = prepare_major_selections(pref_list, max_major_rank) form_data['errors'] = errors else: request.session['notice'] = 'อันดับสาขาวิชาไม่ถูกแก้ไข' return HttpResponseRedirect(reverse('status-index')) else: if applicant.has_major_preference(): pref_list = applicant.preference.get_major_list() else: pref_list = [None] * max_major_rank selections = prepare_major_selections(pref_list, max_major_rank) # add step info form_data['step_name'] = 'แก้ไขอันดับสาขาวิชา' form_data['can_log_out'] = True form_data['selections'] = selections form_data['max_major_rank'] = max_major_rank return render_to_response('application/update/majors.html', form_data)
def update_majors(request): max_major_rank = settings.MAX_MAJOR_RANK if max_major_rank == 1: return update_major_single_choice(request) from form_views import prepare_major_selections applicant = request.applicant form_data = {'majors': Major.get_all_majors()} if request.method == 'POST': if 'cancel' not in request.POST: result, pref_list, errors = handle_major_form( request, max_major_rank) log = Log.create("Update major pref: %s from %s" % (applicant.id, request.META['REMOTE_ADDR'])) if result: request.session['notice'] = 'การแก้ไขอันดับสาขาวิชาเรียบร้อย' return HttpResponseRedirect(reverse('status-index')) selections = prepare_major_selections(pref_list, max_major_rank) form_data['errors'] = errors else: request.session['notice'] = 'อันดับสาขาวิชาไม่ถูกแก้ไข' return HttpResponseRedirect(reverse('status-index')) else: if applicant.has_major_preference(): pref_list = applicant.preference.get_major_list() else: pref_list = [None] * max_major_rank selections = prepare_major_selections(pref_list, max_major_rank) # add step info form_data['step_name'] = 'แก้ไขอันดับสาขาวิชา' form_data['can_log_out'] = True form_data['selections'] = selections form_data['max_major_rank'] = max_major_rank return render_to_response('application/update/majors.html', form_data)
def auto_review_all_apps(request): submission_infos = SubmissionInfo.objects.filter( doc_received_at__isnull=False).filter( has_been_reviewed=False).select_related(depth=1) applicants = get_applicants_from_submission_infos(submission_infos) passed_count = 0 for applicant in applicants: doc_name_list = get_applicant_doc_name_list(applicant) completed_review_fields = CompletedReviewField.get_for_applicant( applicant) completed_names = set( [rf.short_name for rf in completed_review_fields]) failed = False for field in doc_name_list: if field not in completed_names: failed = True break if failed: continue # have already submitted all doc from round 1 passed_count += 1 submission_info = applicant.submission_info submission_info.has_been_reviewed = True submission_info.doc_reviewed_at = datetime.now() submission_info.doc_reviewed_complete = True submission_info.save() # add a log entry log = Log.create("Auto review doc", request.user.username, applicant_id=int(applicant.id), applicantion_id=submission_info.applicantion_id) send_validation_successful_by_email(applicant) request.session['notice'] = 'ตรวจผ่านทั้งสิ้น %d คน' % (passed_count, ) return HttpResponseRedirect(reverse('review-ticket'))
def auto_review_all_apps(request): submission_infos = SubmissionInfo.objects.filter(doc_received_at__isnull=False).filter(has_been_reviewed=False).select_related(depth=1) applicants = get_applicants_from_submission_infos(submission_infos) passed_count = 0 for applicant in applicants: doc_name_list = get_applicant_doc_name_list(applicant) completed_review_fields = CompletedReviewField.get_for_applicant(applicant) completed_names = set([rf.short_name for rf in completed_review_fields]) failed = False for field in doc_name_list: if field not in completed_names: failed = True break if failed: continue # have already submitted all doc from round 1 passed_count += 1 submission_info = applicant.submission_info submission_info.has_been_reviewed = True submission_info.doc_reviewed_at = datetime.now() submission_info.doc_reviewed_complete = True submission_info.save() # add a log entry log = Log.create("Auto review doc", request.user.username, applicant_id=int(applicant.id), applicantion_id=submission_info.applicantion_id) send_validation_successful_by_email(applicant) request.session['notice'] = 'ตรวจผ่านทั้งสิ้น %d คน' % (passed_count,) return HttpResponseRedirect(reverse('review-ticket'))
def review_document(request, applicant_id, return_to_manual=False): applicant = get_object_or_404(Applicant, pk=applicant_id) submission_info = applicant.submission_info if not submission_info.can_be_reviewed(): request.session['notice'] = 'ยังไม่สามารถตรวจสอบเอกสารได้เนื่องจากยังไม่พ้นช่วงเวลาสำหรับการแก้ไข' return HttpResponseRedirect(reverse('review-ticket')) if (request.method=='POST') and ('submit' in request.POST): if not request.user.has_perm('review.change_reviewfieldresult'): request.session['notice'] = 'คุณไม่สามารถแก้ข้อมูลได้ในขณะนี้' return HttpResponseRedirect(reverse('review-ticket')) # auto set received flag submission_info.set_doc_received_at_now_if_not() log_messages = [] field_names = get_applicant_doc_name_list(applicant) fields = prepare_applicant_review_fields(field_names) results = prepare_applicant_review_results(applicant, field_names) forms = prepare_applicant_forms(applicant, field_names, results, request.POST) completed_review_fields = CompletedReviewField.get_for_applicant(applicant) completed_names = [rf.short_name for rf in completed_review_fields] error = False for f in forms: if not f.is_valid(): error = True if not error: failed_fields = [] for field, result, form in zip(fields, results, forms): if field.short_name in completed_names: # skip completed review fields continue if not result: old_value = '-' # for logging result = ReviewFieldResult() else: old_value = result.is_passed result.applicant_note = form.cleaned_data['applicant_note'] result.internal_note = form.cleaned_data['internal_note'] result.review_field = field result.applicant = applicant if (field.required) or (form.cleaned_data['is_submitted']): result.is_passed = form.cleaned_data['is_passed'] new_value = str(int(form.cleaned_data['is_passed'])) if result.id!=None: result.save(force_update=True) else: result.save(force_insert=True) if not result.is_passed: failed_fields.append((field,result)) else: new_value = '-' if result.id!=None: result.delete() log_messages.append('%d:%s-%s' % (field.id, old_value, new_value)) submission_info.has_been_reviewed = True submission_info.doc_reviewed_at = datetime.now() submission_info.doc_reviewed_complete = (len(failed_fields)==0) submission_info.save() # add a log entry log = Log.create("Review doc: " + '; '.join(log_messages), request.user.username, applicant_id=int(applicant_id), applicantion_id=submission_info.applicantion_id) if submission_info.doc_reviewed_complete: send_validation_successful_by_email(applicant) request.session['notice'] = 'จัดเก็บและแจ้งผลการตรวจว่าผ่านกับผู้สมัครแล้ว' else: send_validation_error_by_email(applicant, failed_fields) request.session['notice'] = 'จัดเก็บและแจ้งผลการตรวจว่าหลักฐานไม่ผ่านกับผู้สมัครแล้ว' if not return_to_manual: return HttpResponseRedirect(reverse('review-ticket')) else: return HttpResponseRedirect(reverse('manual-index')) elif 'cancel' in request.POST: request.session['notice'] = 'ยกเลิกการตรวจสอบ ผลตรวจทุกอย่างคงเดิม' #print return_to_manual if not return_to_manual: return HttpResponseRedirect(reverse('review-ticket')) else: return HttpResponseRedirect(reverse('manual-index')) else: data = prepare_applicant_review_data(applicant) if applicant.online_doc_submission(): appdocs = applicant.appdocs else: appdocs = None can_request_password = request.user.is_staff and applicant.can_password_be_generated() return render_to_response("review/show.html", { 'applicant': applicant, 'appdocs': appdocs, 'submission_info': submission_info, 'review_data': data, 'can_request_password': can_request_password })
def confirm(request, preview=False): """ Obsoleted. """ return HttpResponseForbidden() if request.method != 'POST': return HttpResponseForbidden() if not request.user.has_perm('confirmation.add_admissionconfirmation'): return HttpResponseForbidden( 'ขออภัยคุณไม่มีสิทธิ์ในการทำรายการดังกล่าว') if 'cancel' in request.POST: request.session['notice'] = u'ยกเลิกการทำรายการ' return HttpResponseRedirect(reverse('confirmation-index')) import re if (('application_id' not in request.POST) or (not re.match(r'53[123]\d{5}', request.POST['application_id']))): request.session[ 'notice'] = u'เกิดข้อผิดพลาด หมายเลขประจำตัวผู้สมัครไม่ถูกต้อง' return HttpResponseRedirect(reverse('confirmation-index')) application_id = request.POST['application_id'] submission_info = SubmissionInfo.find_by_ticket_number(application_id) if submission_info == None: request.session['notice'] = ( u'เกิดข้อผิดพลาด ไม่พบผู้สมัครที่ใช้หมายเลข %s' % application_id) return HttpResponseRedirect(reverse('confirmation-index')) applicant = submission_info.applicant if (not applicant.has_admission_result() or not applicant.admission_result.is_final_admitted): request.session['notice'] = ( u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) ' u'ไม่ผ่านการคัดเลือกเข้าศึกษาต่อ' % (application_id, applicant.full_name())) return HttpResponseRedirect(reverse('confirmation-index')) try: if applicant.admission_confirmation != None: request.session['notice'] = ( u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) ' u'ได้ยืนยันสิทธิ์แล้ว ถ้าต้องการยกเลิกกรุณาแจ้งผู้ดูแล' % (application_id, applicant.full_name())) return HttpResponseRedirect(reverse('confirmation-index')) except: pass if preview: return render_to_response('confirmation/preview.html', {'applicant': applicant}) else: confirmation = AdmissionConfirmation(applicant=applicant, confirming_user=request.user) Log.create("admission confirmation - from: %s" % (request.META['REMOTE_ADDR'], ), user=request.user.username, applicant_id=applicant.id, applicantion_id=application_id) try: confirmation.save() except: Log.create("ERROR: admission confirmation - from: %s" % (request.META['REMOTE_ADDR'], ), user=request.user.username, applicant_id=applicant.id, applicantion_id=application_id) request.session[ 'notice'] = u'เกิดข้อผิดพลาดในการยืนยันสิทธิ์ กรุณาแจ้งผู้ดูแลด่วน' return HttpResponseRedirect(reverse('confirmation-index')) request.session[ 'notice'] = u'บันทึกการยืนยันสิทธิ์เรียบร้อย ชื่อผู้ยืนยันควรปรากฏในตารางด้านล่าง' return HttpResponseRedirect(reverse('confirmation-index'))
def confirm(request, preview=False): """ Obsoleted. """ return HttpResponseForbidden() if request.method != 'POST': return HttpResponseForbidden() if not request.user.has_perm('confirmation.add_admissionconfirmation'): return HttpResponseForbidden('ขออภัยคุณไม่มีสิทธิ์ในการทำรายการดังกล่าว') if 'cancel' in request.POST: request.session['notice'] = u'ยกเลิกการทำรายการ' return HttpResponseRedirect(reverse('confirmation-index')) import re if (('application_id' not in request.POST) or (not re.match(r'53[123]\d{5}', request.POST['application_id']))): request.session['notice'] = u'เกิดข้อผิดพลาด หมายเลขประจำตัวผู้สมัครไม่ถูกต้อง' return HttpResponseRedirect(reverse('confirmation-index')) application_id = request.POST['application_id'] submission_info = SubmissionInfo.find_by_ticket_number(application_id) if submission_info==None: request.session['notice'] = (u'เกิดข้อผิดพลาด ไม่พบผู้สมัครที่ใช้หมายเลข %s' % application_id) return HttpResponseRedirect(reverse('confirmation-index')) applicant = submission_info.applicant if (not applicant.has_admission_result() or not applicant.admission_result.is_final_admitted): request.session['notice'] = (u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) ' u'ไม่ผ่านการคัดเลือกเข้าศึกษาต่อ' % (application_id, applicant.full_name())) return HttpResponseRedirect(reverse('confirmation-index')) try: if applicant.admission_confirmation!=None: request.session['notice'] = (u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) ' u'ได้ยืนยันสิทธิ์แล้ว ถ้าต้องการยกเลิกกรุณาแจ้งผู้ดูแล' % (application_id, applicant.full_name())) return HttpResponseRedirect(reverse('confirmation-index')) except: pass if preview: return render_to_response('confirmation/preview.html', { 'applicant': applicant }) else: confirmation = AdmissionConfirmation(applicant=applicant, confirming_user=request.user) Log.create("admission confirmation - from: %s" % (request.META['REMOTE_ADDR'],), user=request.user.username, applicant_id=applicant.id, applicantion_id=application_id) try: confirmation.save() except: Log.create("ERROR: admission confirmation - from: %s" % (request.META['REMOTE_ADDR'],), user=request.user.username, applicant_id=applicant.id, applicantion_id=application_id) request.session['notice'] = u'เกิดข้อผิดพลาดในการยืนยันสิทธิ์ กรุณาแจ้งผู้ดูแลด่วน' return HttpResponseRedirect(reverse('confirmation-index')) request.session['notice'] = u'บันทึกการยืนยันสิทธิ์เรียบร้อย ชื่อผู้ยืนยันควรปรากฏในตารางด้านล่าง' return HttpResponseRedirect(reverse('confirmation-index'))
def pref(request): if settings.SHOW_ONLY_RESULTS: return HttpResponseForbidden() applicant = request.applicant admitted = applicant.is_admitted() if not admitted: return HttpResponseForbidden() first_admission = (applicant.admission_results.count() == 1) if not first_admission: return HttpResponseForbidden() registration = applicant.get_student_registration() if not registration: return HttpResponseForbidden() # check for deadline if admission_major_pref_deadline_passed(): return render_to_response('confirmation/pref_deadline_passed.html') current_round = AdmissionRound.get_recent() round_number = current_round.number is_last_round = False admission_result = applicant.get_latest_admission_result() preferred_majors = applicant.preference.get_major_list() higher_majors = get_higher_ranked_majors(preferred_majors, admission_result.admitted_major) admission_pref = applicant.get_admission_major_preference(round_number) if admission_pref: pref_type = admission_pref.get_pref_type() accepted_major_ids = [m.id for m in admission_pref.get_accepted_majors()] is_accepted_list = [(m.id in accepted_major_ids) for m in higher_majors] else: pref_type = AdmissionMajorPreference.PrefType.new_empty() try: is_accepted_list = [False] * len(higher_majors) except: Log.create("Error: empty higher majors: %d" % (applicant.id,)) raise form_check_message = '' if request.method=='POST': if 'submit' in request.POST: check_result, form_check_message = check_form_submission(request.POST, higher_majors) if check_result: admission_pref = update_admission_major_preference( admission_pref, applicant, preferred_majors, higher_majors, round_number, request.POST) admission_pref.set_ptype_cache(save=False) if is_last_round and ( admission_pref.get_pref_type().is_move_up_inclusive() or admission_pref.get_pref_type().is_move_up_strict()): return HttpResponseForbidden() admission_pref.save() request.session['notice'] = 'เก็บข้อมูลการยืนยันอันดับการเลือกสาขาวิชาแล้ว' Log.create("confirmation - from: %s,type: %d (%s), val: %s" % (request.META['REMOTE_ADDR'], admission_pref.get_pref_type().ptype, request.POST['pref_type'], str(admission_pref.is_accepted_list)), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return HttpResponseRedirect(reverse('status-index')) else: if admission_pref: request.session['notice'] = 'ยกเลิกการแก้ไขอันดับการเลือกสาขาวิชา' else: request.session['notice'] = 'ยกเลิกการยืนยันอันดับการเลือกสาขาวิชา' Log.create("confirmation: cancel", applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return HttpResponseRedirect(reverse('status-index')) else: pass return render_to_response('confirmation/pref.html', { 'applicant': applicant, 'admission_result': admission_result, 'current_round': current_round, 'is_last_round': is_last_round, 'registration': registration, 'higher_majors': higher_majors, 'majors_with_is_accepted': zip(higher_majors, is_accepted_list), 'admission_pref': admission_pref, 'pref_type': pref_type, 'form_check_message': form_check_message })
def main(request, is_edit_registration=False): if settings.SHOW_ONLY_RESULTS: return HttpResponseForbidden() applicant = request.applicant admitted = applicant.is_admitted() if not admitted: return HttpResponseForbidden() first_admission = (applicant.admission_results.count() == 1) if not first_admission: return HttpResponseForbidden() current_round = AdmissionRound.get_recent() round_number = current_round.number is_last_round = False # check for deadline if admission_major_pref_deadline_passed(): return render_to_response('confirmation/pref_deadline_passed.html', {'admission_round': current_round}) admission_result = applicant.get_latest_admission_result() preferred_majors = applicant.preference.get_major_list() higher_majors = get_higher_ranked_majors(preferred_majors, admission_result.admitted_major) is_best_major = (len(higher_majors)==0) if AdmissionWaiver.is_waived(applicant): waiver = applicant.admission_waiver else: waiver = None registration = applicant.get_student_registration() if request.method=='GET' and registration and not is_edit_registration and not is_best_major: return redirect('confirmation-pref') if request.method=='POST' and 'confirm' in request.POST: form = StudentRegistrationForm(request.POST, instance=registration) if form.is_valid(): registration = form.save(commit=False) registration.applicant = applicant registration.save() AdmissionConfirmation.create_for(applicant, current_round.number) send_admission_confirmation_by_email(applicant) if not is_best_major: Log.create("Confirm applicant %s from %s" % (applicant.id,request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('confirmation-pref') else: Log.create("Confirm applicant %s (for best) from %s" % (applicant.id,request.META['REMOTE_ADDR']), applicant_id=applicant.id) save_best_admission_major_pref(applicant, current_round, admission_result) return redirect('status-index') elif request.method=='POST' and 'waive' in request.POST: AdmissionWaiver.waive_applicant(applicant) if registration: registration.delete() AdmissionConfirmation.delete_for(applicant, current_round.number) save_waive_admission_major_pref(applicant, current_round) Log.create("Waive applicant %s from %s" % (applicant.id,request.META['REMOTE_ADDR']), applicant_id=applicant.id) send_admission_waive_by_email(applicant) request.session['notice'] = u'คุณได้สละสิทธิ์การเข้าศึกษาต่อผ่านโครงการรับตรงแล้ว' return redirect('status-index') elif request.method=='POST' and 'unwaive' in request.POST: AdmissionWaiver.unwaive_applicant(applicant) AdmissionMajorPreference.objects.filter(applicant=applicant, round_number=current_round.number).delete() Log.create("Unwaive applicant %s from %s" % (applicant.id,request.META['REMOTE_ADDR']), applicant_id=applicant.id) send_admission_unwaive_by_email(applicant) return redirect('confirmation-app-index') elif request.method=='POST' and 'cancel' in request.POST: return redirect('status-index') else: form = StudentRegistrationForm(instance=registration) return render_to_response('confirmation/index.html', { 'applicant': applicant, 'admission_result': admission_result, 'current_round': current_round, 'is_last_round': is_last_round, 'is_best_major': is_best_major, 'registration': registration, 'waiver': waiver, 'form': form, 'can_log_out': True})
def review_document(request, applicant_id, return_to_manual=False): applicant = get_object_or_404(Applicant, pk=applicant_id) submission_info = applicant.submission_info if not submission_info.can_be_reviewed(): request.session[ 'notice'] = 'ยังไม่สามารถตรวจสอบเอกสารได้เนื่องจากยังไม่พ้นช่วงเวลาสำหรับการแก้ไข' return HttpResponseRedirect(reverse('review-ticket')) if (request.method == 'POST') and ('submit' in request.POST): if not request.user.has_perm('review.change_reviewfieldresult'): request.session['notice'] = 'คุณไม่สามารถแก้ข้อมูลได้ในขณะนี้' return HttpResponseRedirect(reverse('review-ticket')) # auto set received flag submission_info.set_doc_received_at_now_if_not() log_messages = [] field_names = get_applicant_doc_name_list(applicant) fields = prepare_applicant_review_fields(field_names) results = prepare_applicant_review_results(applicant, field_names) forms = prepare_applicant_forms(applicant, field_names, results, request.POST) completed_review_fields = CompletedReviewField.get_for_applicant( applicant) completed_names = [rf.short_name for rf in completed_review_fields] error = False for f in forms: if not f.is_valid(): error = True if not error: failed_fields = [] for field, result, form in zip(fields, results, forms): if field.short_name in completed_names: # skip completed review fields continue if not result: old_value = '-' # for logging result = ReviewFieldResult() else: old_value = result.is_passed result.applicant_note = form.cleaned_data['applicant_note'] result.internal_note = form.cleaned_data['internal_note'] result.review_field = field result.applicant = applicant if (field.required) or (form.cleaned_data['is_submitted']): result.is_passed = form.cleaned_data['is_passed'] new_value = str(int(form.cleaned_data['is_passed'])) if result.id != None: result.save(force_update=True) else: result.save(force_insert=True) if not result.is_passed: failed_fields.append((field, result)) else: new_value = '-' if result.id != None: result.delete() log_messages.append('%d:%s-%s' % (field.id, old_value, new_value)) submission_info.has_been_reviewed = True submission_info.doc_reviewed_at = datetime.now() submission_info.doc_reviewed_complete = (len(failed_fields) == 0) submission_info.save() # add a log entry log = Log.create("Review doc: " + '; '.join(log_messages), request.user.username, applicant_id=int(applicant_id), applicantion_id=submission_info.applicantion_id) if submission_info.doc_reviewed_complete: send_validation_successful_by_email(applicant) request.session[ 'notice'] = 'จัดเก็บและแจ้งผลการตรวจว่าผ่านกับผู้สมัครแล้ว' else: send_validation_error_by_email(applicant, failed_fields) request.session[ 'notice'] = 'จัดเก็บและแจ้งผลการตรวจว่าหลักฐานไม่ผ่านกับผู้สมัครแล้ว' if not return_to_manual: return HttpResponseRedirect(reverse('review-ticket')) else: return HttpResponseRedirect(reverse('manual-index')) elif 'cancel' in request.POST: request.session['notice'] = 'ยกเลิกการตรวจสอบ ผลตรวจทุกอย่างคงเดิม' #print return_to_manual if not return_to_manual: return HttpResponseRedirect(reverse('review-ticket')) else: return HttpResponseRedirect(reverse('manual-index')) else: data = prepare_applicant_review_data(applicant) if applicant.online_doc_submission(): appdocs = applicant.appdocs else: appdocs = None can_request_password = request.user.is_staff and applicant.can_password_be_generated( ) return render_to_response( "review/show.html", { 'applicant': applicant, 'appdocs': appdocs, 'submission_info': submission_info, 'review_data': data, 'can_request_password': can_request_password })
def main(request, is_edit_registration=False): if settings.SHOW_ONLY_RESULTS: return HttpResponseForbidden() applicant = request.applicant admitted = applicant.is_admitted() if not admitted: return HttpResponseForbidden() first_admission = (applicant.admission_results.count() == 1) if not first_admission: return HttpResponseForbidden() current_round = AdmissionRound.get_recent() round_number = current_round.number is_last_round = False # check for deadline if admission_major_pref_deadline_passed(): return render_to_response('confirmation/pref_deadline_passed.html', {'admission_round': current_round}) admission_result = applicant.get_latest_admission_result() preferred_majors = applicant.preference.get_major_list() higher_majors = get_higher_ranked_majors(preferred_majors, admission_result.admitted_major) is_best_major = (len(higher_majors) == 0) if AdmissionWaiver.is_waived(applicant): waiver = applicant.admission_waiver else: waiver = None registration = applicant.get_student_registration() if request.method == 'GET' and registration and not is_edit_registration and not is_best_major: return redirect('confirmation-pref') if request.method == 'POST' and 'confirm' in request.POST: form = StudentRegistrationForm(request.POST, instance=registration) if form.is_valid(): registration = form.save(commit=False) registration.applicant = applicant registration.save() AdmissionConfirmation.create_for(applicant, current_round.number) send_admission_confirmation_by_email(applicant) if not is_best_major: Log.create("Confirm applicant %s from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) return redirect('confirmation-pref') else: Log.create("Confirm applicant %s (for best) from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) save_best_admission_major_pref(applicant, current_round, admission_result) return redirect('status-index') elif request.method == 'POST' and 'waive' in request.POST: AdmissionWaiver.waive_applicant(applicant) if registration: registration.delete() AdmissionConfirmation.delete_for(applicant, current_round.number) save_waive_admission_major_pref(applicant, current_round) Log.create("Waive applicant %s from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) send_admission_waive_by_email(applicant) request.session[ 'notice'] = u'คุณได้สละสิทธิ์การเข้าศึกษาต่อผ่านโครงการรับตรงแล้ว' return redirect('status-index') elif request.method == 'POST' and 'unwaive' in request.POST: AdmissionWaiver.unwaive_applicant(applicant) AdmissionMajorPreference.objects.filter( applicant=applicant, round_number=current_round.number).delete() Log.create("Unwaive applicant %s from %s" % (applicant.id, request.META['REMOTE_ADDR']), applicant_id=applicant.id) send_admission_unwaive_by_email(applicant) return redirect('confirmation-app-index') elif request.method == 'POST' and 'cancel' in request.POST: return redirect('status-index') else: form = StudentRegistrationForm(instance=registration) return render_to_response( 'confirmation/index.html', { 'applicant': applicant, 'admission_result': admission_result, 'current_round': current_round, 'is_last_round': is_last_round, 'is_best_major': is_best_major, 'registration': registration, 'waiver': waiver, 'form': form, 'can_log_out': True })
def pref(request): if settings.SHOW_ONLY_RESULTS: return HttpResponseForbidden() applicant = request.applicant admitted = applicant.is_admitted() if not admitted: return HttpResponseForbidden() first_admission = (applicant.admission_results.count() == 1) if not first_admission: return HttpResponseForbidden() registration = applicant.get_student_registration() if not registration: return HttpResponseForbidden() # check for deadline if admission_major_pref_deadline_passed(): return render_to_response('confirmation/pref_deadline_passed.html') current_round = AdmissionRound.get_recent() round_number = current_round.number is_last_round = False admission_result = applicant.get_latest_admission_result() preferred_majors = applicant.preference.get_major_list() higher_majors = get_higher_ranked_majors(preferred_majors, admission_result.admitted_major) admission_pref = applicant.get_admission_major_preference(round_number) if admission_pref: pref_type = admission_pref.get_pref_type() accepted_major_ids = [ m.id for m in admission_pref.get_accepted_majors() ] is_accepted_list = [(m.id in accepted_major_ids) for m in higher_majors] else: pref_type = AdmissionMajorPreference.PrefType.new_empty() try: is_accepted_list = [False] * len(higher_majors) except: Log.create("Error: empty higher majors: %d" % (applicant.id, )) raise form_check_message = '' if request.method == 'POST': if 'submit' in request.POST: check_result, form_check_message = check_form_submission( request.POST, higher_majors) if check_result: admission_pref = update_admission_major_preference( admission_pref, applicant, preferred_majors, higher_majors, round_number, request.POST) admission_pref.set_ptype_cache(save=False) if is_last_round and ( admission_pref.get_pref_type().is_move_up_inclusive() or admission_pref.get_pref_type().is_move_up_strict()): return HttpResponseForbidden() admission_pref.save() request.session[ 'notice'] = 'เก็บข้อมูลการยืนยันอันดับการเลือกสาขาวิชาแล้ว' Log.create( "confirmation - from: %s,type: %d (%s), val: %s" % (request.META['REMOTE_ADDR'], admission_pref.get_pref_type().ptype, request.POST['pref_type'], str(admission_pref.is_accepted_list)), applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return HttpResponseRedirect(reverse('status-index')) else: if admission_pref: request.session[ 'notice'] = 'ยกเลิกการแก้ไขอันดับการเลือกสาขาวิชา' else: request.session[ 'notice'] = 'ยกเลิกการยืนยันอันดับการเลือกสาขาวิชา' Log.create( "confirmation: cancel", applicant_id=applicant.id, applicantion_id=applicant.submission_info.applicantion_id) return HttpResponseRedirect(reverse('status-index')) else: pass return render_to_response( 'confirmation/pref.html', { 'applicant': applicant, 'admission_result': admission_result, 'current_round': current_round, 'is_last_round': is_last_round, 'registration': registration, 'higher_majors': higher_majors, 'majors_with_is_accepted': zip(higher_majors, is_accepted_list), 'admission_pref': admission_pref, 'pref_type': pref_type, 'form_check_message': form_check_message })