我当前正在预约约会。我希望执行if语句,以确保在选定的时间和日期有空。我目前拥有的代码如下:
def book():
form = BookAppointment(request.form)
if request.method == 'POST' and form.validate():
appointment_date = form.appointment_date.data
appointment_time = form.appointment_time.data
appointment_patient_id = form.appointment_patient_id.data
appointment_doctor_id = form.appointment_doctor_id.data
appointment_centre_id = form.appointment_centre_id.data
username = session.get('username', None)
# Create cursor
cur = mysql.connection.cursor()
find_doctor = cur.execute("SELECT * FROM doctors WHERE doctor_id =%s", [appointment_doctor_id])
find_date = cur.execute("SELECT * FROM appointments WHERE appointment_date =%s", [appointment_date])
find_time = cur.execute("SELECT * FROM appointments WHERE appointment_time =%s", [appointment_time])
msg = cur.fetchone()
# Execute query
cur.execute("INSERT INTO appointments(appointment_date, appointment_time, patient_id, doctor_id, centre_id, patient_username) VALUES(%s, %s, %s, %s, %s, %s)", (appointment_date, appointment_time, appointment_patient_id, appointment_doctor_id, appointment_centre_id, username))
if find_doctor == 0 and find_date == 0 and find_time == 0:
if appointment_date.weekday() == 0 or appointment_date.weekday() == 1 or appointment_date.weekday() == 2 or appointment_date.weekday() == 3 or appointment_date.weekday() == 4:
# Commit to DB
mysql.connection.commit()
# Close connection
cur.close()
flash('Appointment made successfully!', 'success')
return redirect(url_for('book'))
else:
error = 'Sorry, appointments cannot be made for a Saturday/Sunday'
return render_template('/patient/bookappointment.html', error=error, form=form)
else:
flash('Appointment unavailable, please select another date or time', 'danger')
return redirect(url_for('book'))
return render_template('/patient/bookappointment.html', form=form)
因此,如果当前没有在相同的日期和时间与同一位医生预约的约会,我希望进行预约。谢谢