def post(self, request): if validate_user(request): data = request.POST validate_user(request) leave_type = data.get('leave-type') start_date = data.get('start_date') end_date = data.get('end_date') reason = data.get('reason') halfday = data.get('halfday', False) today = date.today() username = request.session.get('user') user = get_object_or_404(Teacher, username=username) leave = Leave( teacher=user, type=leave_type, start_date=start_date, reason=reason, is_teacher=True, ) if halfday == True: leave.halfday = True if end_date != "": leave.end_date = end_date leave.save() return redirect('teacher_apply_leave') else: return redirect('teacher_login')
def post(self, request): if user_validate(request): data= request.POST leave_type = data.get('leave-type') start_date = data.get('start_date') end_date = data.get('end_date') reason = data.get('reason') halfday = data.get('halfday', False) start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d').date() # convert srt date to datetime end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d').date() # convert srt date to datetime if end_date < start_date: messages.error(request, "Start Date is grater than End Date") return redirect('sports_apply_leave') username = request.session.get('user') user = get_object_or_404(Teacher, username=username) leave = Leave( teacher = user, type = leave_type, start_date = start_date, reason = reason, is_teacher = True, ) if halfday == True: leave.halfday = True if end_date != "": leave.end_date = end_date leave.save() return redirect('sports_apply_leave') else: return redirect('login')
def post(self, request): if validate_user(request): data= request.POST validate_user(request) leave_type = data.get('leave-type') start_date = data.get('start_date') end_date = data.get('end_date') reason = data.get('reason') halfday = data.get('halfday', False) today = datetime.date.today() start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d').date()# convert srt date to datetime end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d').date()# convert srt date to datetime if end_date < start_date: messages.error(request, "Start Date is grater than End Date") return redirect('apply_leave') if today <= start_date: username = request.session.get('user') user = get_object_or_404(Students, username=username) leave = Leave( student= user, type = leave_type, start_date = start_date, reason = reason, is_student = True, ) if halfday: leave.halfday = True if end_date != "": leave.end_date = end_date # leave.save() else: messages.error(request, 'Please check you date ') return redirect('apply_leave') return redirect('login')