TypeError:“ UnboundField”对象不可调用

时间:2019-04-09 11:37:43

标签: python html forms

出现此错误,不知道为什么。当我尝试在表单中输入详细信息并提交时,我收到TypeError:'UnboundField'对象不可调用。我已经尝试了所有可以想到的方法,但仍然没有得到可以正常工作的结果。这是我的代码:

# Add appointment form class
class CreateAppointment(Form):
    today_date = date.today()
    tomorrow_date = today_date + timedelta(days=1)

patient_name = StringField('Patient Name', validators=[DataRequired(), validators.Length(min=1, max=50)], render_kw={"placeholder": "Enter Patient Name"})
appointment_date = DateField('Appointment Date', format='%Y-%m-%d', default= tomorrow_date, validators=[DateField(min=tomorrow_date, message="Please select a date after today"), DataRequired()])
appointment_time = SelectField('Appointment Time', choices=[('09:00', '09:00'), ('09:30', '09:30'), ('10:00', '10:00'), ('10:30', '10:30'), ('11:00', '11:00'), ('11:30', '11:30'), ('12:00', '12:00'), ('12:30', '12:30'), ('13:00', '13:00'), ('13:30', '13:30'), ('14:00', '14:00'), ('14:30', '14:30'), ('15:00', '15:00'), ('15:30', '15:30'), ('16:00', '16:00'), ('16:30', '16:30')], validators=[DataRequired()])


# Add an appointment
@app.route('/addappointment', methods=['GET', 'POST'])
@doctor_is_logged_in
def addappointment():
    form = CreateAppointment(request.form)
    if request.method == 'POST' and form.validate():
        appointment_date = form.appointment_date.data
        appointment_time = form.appointment_time.data
        patient_name = form.patient_name.data
        doctor_username = session.get('username', None)

        # Create cursor
        cur = mysql.connection.cursor()

        # Get patient_id, doctor_id and centre_id from relevant tables
        appointment_patient_id = cur.execute("SELECT patient_id FROM patients WHERE concat(patient_first_name, ' ', patient_last_name) =%s", [patient_name])
        actual_patient_id = cur.fetchone()
        appointment_doctor_id = cur.execute("SELECT doctor_id FROM doctors WHERE doctor_username =%s", [doctor_username])
        actual_doctor_id = cur.fetchone()
        appointment_centre_id = cur.execute("SELECT centre_id FROM doctors WHERE doctor_username =%s", [doctor_username])
        actual_centre_id = cur.fetchone()

        # Check if this doctor has a booking for this time and date
        confirmed_booking = cur.execute("SELECT appointment_id FROM appointments WHERE appointment_time =%s AND appointment_date =%s AND doctor_id =%s", (appointment_time, appointment_date, actual_doctor_id.get('doctor_id')))

        # If the selected slot is available
        if confirmed_booking == 0:
            # Execute query
            cur.execute("INSERT INTO appointments(appointment_date, appointment_time, patient_id, doctor_id, centre_id) VALUES(%s, %s, %s, %s, %s)", (appointment_date, appointment_time, actual_patient_id.get('patient_id'), actual_doctor_id.get('doctor_id'), actual_centre_id.get('centre_id')))

            # Making sure the appointment is made for a weekday
            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('addappointment'))

            else:
                error = 'Sorry, appointments cannot be made for a Saturday/Sunday'
                return render_template('/doctor/addappointment.html', error=error, form=form)

        else:
            error = 'Sorry, appointment unavailable'
            return render_template('/doctor/addappointment.html', error=error, form=form)

    return render_template('/doctor/addappointment.html', form=form)

任何帮助将不胜感激。

0 个答案:

没有答案