def prepare_applicant_review_data(applicant): field_names = get_applicant_doc_name_list(applicant) completed_review_fields = CompletedReviewField.get_for_applicant(applicant) fields = prepare_applicant_review_fields(field_names) results = prepare_applicant_review_results(applicant, field_names) forms = prepare_applicant_forms(applicant, field_names, results) return build_review_data(fields, results, forms, completed_review_fields)
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 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 })