def main(): next_round = round_number + 1 results = AdmissionResult.objects.filter(round_number=next_round).select_related(depth=1) for r in results: a = r.applicant amp = a.get_admission_major_preference(next_round) if amp: # already exists continue all_major_prefs = list(a.admission_major_preferences.all()) if len(all_major_prefs)>0: print a.national_id, 'copied' latest_admission_major_pref = all_major_prefs[0] admission_major_pref = ( AdmissionMajorPreference.new_for_applicant( a, latest_admission_major_pref.is_accepted_list, admission_result=r)) admission_major_pref.round_number = next_round if latest_admission_major_pref.is_nomove_request: majors = [m.id for m in a.preference.get_major_list()] admitted_major = a.get_latest_admission_result().admitted_major alist = [0] * len(majors) alist[majors.index(admitted_major.id)] = 1 admission_major_pref.is_accepted_list = alist admission_major_pref.set_ptype_cache()
def copy_previous_adm_major_pref(prev_pref, applicant, admitted_major, round_number): new_pref = AdmissionMajorPreference.new_for_applicant(applicant, prev_pref.is_accepted_list) new_pref.round_number = round_number new_pref.set_ptype_cache(save=False) return new_pref