def get(self, request, *args, **kwargs): form = self.form_class(initial=self.initial) # is supervisor email valid (present in DB)? invalid_supervisor_email = False invalid_contact = False hod_file = pd.read_csv('hod_list.csv') hod_1 = hod_file[ (hod_file["Campus"] == request.user.userprofile.campus) & ((hod_file["Department"] == request.user.username[4:6]) | (hod_file["Department"] == request.user.username[6:8]))] hod_email_list = hod_1['Email'].tolist() self.context = { 'student_name': request.user.get_full_name(), 'student_ID': request.user.username, 'student_branch': get_branch_from_branch_code(request.user.username[4:6]) + get_branch_from_branch_code(request.user.username[6:8]), 'contact': request.user.userprofile.contact, 'form': form, 'hod_email_list': hod_email_list, 'invalid_supervisor_email': invalid_supervisor_email, 'invalid_contact': invalid_contact, } return render(request, self.template_name, self.context)
def post(self, request, *args, **kwargs): if not get_deadline_status(TransferType.PS2TS.value): return redirect('/TMS/student/dashboard/') post = request.POST.copy() post['applicant'] = request.user.userprofile request.POST = post form = self.form_class(request.POST) # is supervisor email valid (present in DB)? invalid_supervisor_email = False contact = post['contact'] invalid_contact = False if not validate_contact(contact): invalid_contact = True if form.is_valid() and not invalid_contact: email = form.cleaned_data.get('supervisor_email') supervisor_email_qs = UserProfile.objects.filter( user_type=UserType.SUPERVISOR.value, user__email=email) if supervisor_email_qs: current_user = request.user.userprofile current_user.contact = contact current_user.save() form.save() data = PS2TSTransfer.objects.filter( applicant=request.user.userprofile)[0] notify_ps2ts(data, "supervisor") return redirect('/TMS/student/dashboard/') else: invalid_supervisor_email = True hod_file = pd.read_csv('hod_list.csv') hod_1 = hod_file[ (hod_file["Campus"] == request.user.userprofile.campus) & ((hod_file["Department"] == request.user.username[4:6]) | (hod_file["Department"] == request.user.username[6:8]))] hod_email_list = hod_1['Email'].tolist() self.context = { 'student_name': request.user.get_full_name(), 'student_ID': request.user.username, 'student_branch': get_branch_from_branch_code(request.user.username[4:6]) + get_branch_from_branch_code(request.user.username[6:8]), 'contact': request.user.userprofile.contact, 'form': form, 'hod_email_list': hod_email_list, 'invalid_supervisor_email': invalid_supervisor_email, 'invalid_contact': invalid_contact, } return render(request, self.template_name, self.context)
def post(self, request, *args, **kwargs): if not get_deadline_status(TransferType.TS2PS.value): return redirect('/TMS/student/dashboard/') post = request.POST.copy() post['applicant'] = request.user.userprofile request.POST = post form = self.form_class(request.POST) contact = post['contact'] invalid_contact = False if not validate_contact(contact): invalid_contact = True if form.is_valid() and not invalid_contact: current_user = request.user.userprofile current_user.contact = contact current_user.save() form.save() notify_ts2ps(request) return redirect('/TMS/student/dashboard/') hod_file = pd.read_csv('hod_list.csv') hod_1 = hod_file[ (hod_file["Campus"] == request.user.userprofile.campus) & ((hod_file["Department"] == request.user.username[4:6]) | (hod_file["Department"] == request.user.username[6:8]))] hod_email_list = hod_1['Email'].tolist() self.context = { 'student_name': request.user.get_full_name(), 'student_ID': request.user.username, 'student_branch': get_branch_from_branch_code(request.user.username[4:6]) + get_branch_from_branch_code(request.user.username[6:8]), 'contact': request.user.userprofile.contact, 'form': form, 'hod_email_list': hod_email_list, 'invalid_contact': invalid_contact, } return render(request, self.template_name, self.context)