Пример #1
0
def personal_details():
    """
    Edit personal details.
    """
    # Create the form object, for updating details.
    update_personal_details_form = UpdatePersonalDetailsForm()

    if request.method == 'POST' and update_personal_details_form.validate_on_submit():
        # Form is valid.
        # Ensure the update box is checked.
        if update_personal_details_form.update_details.data:
            # Update all the details.
            current_user.update_user_details(
                first_name=update_personal_details_form.tutor_first_name.data,
                last_name=update_personal_details_form.tutor_last_name.data,
                email_address=update_personal_details_form.tutor_email_address.data,
                telephone_number=update_personal_details_form.telephone_number.data,
                speciality=update_personal_details_form.speciality.data
            )
            # Save the changes.
            db.session.commit()
            # Flash a success method.
            flash('Successfully updated personal details.')
            # Redirect to this page - some weird stuff was
            # happening with get_personal_details
            return redirect(url_for('staff.personal_details'))

    # Create a dictionary of the required personal details.
    user_details = current_user.get_personal_details()

    return render_template(
        'staff/personaldetails.html',
        update_personal_details_form=update_personal_details_form,
        personal_details=user_details
    )
Пример #2
0
def personal_details():
    """
    View and update personal details.
    """

    # Create the form object, for updating details.
    update_personal_details_form = UpdatePersonalDetailsForm()

    if request.method == 'POST' and update_personal_details_form.validate_on_submit():
        # Form is valid.
        # Ensure the update box is checked.
        if update_personal_details_form.update_details.data:
            # Update all the details.
            current_user.update_user_details(
                first_name=update_personal_details_form.student_first_name.data,
                last_name=update_personal_details_form.student_last_name.data,
                email_address=update_personal_details_form.student_email_address.data,
                tutor_group=update_personal_details_form.student_tutor_group.data,
                musical_instrument_type=update_personal_details_form.musical_instrument_type.data,
                musical_instrument=update_personal_details_form.musical_instrument.data,
                musical_style=update_personal_details_form.musical_style.data,
                musical_grade=update_personal_details_form.musical_grade.data
            )
            # Save the changes.
            db.session.commit()
            # Flash a success method.
            flash('Successfully updated personal details.')
            # Redirect to this page - some weird stuff was happening with get_personal_details
            return redirect(url_for('student.personal_details'))

    # Create a dictionary of the required personal details.
    user_details = current_user.get_personal_details()
    # Change the defaults in the form - for select boxes only!
    update_personal_details_form.musical_instrument_type.default = \
        user_details['musical_instrument_type']
    update_personal_details_form.musical_style.default = \
        user_details['musical_style']
    update_personal_details_form.musical_grade.default = \
        user_details['musical_grade']
    # Update the form to reflect changes.
    update_personal_details_form.process()

    return render_template(
        'student/personaldetails.html',
        update_personal_details_form=update_personal_details_form,
        personal_details=user_details
    )