Пример #1
0
def update(id):
    to_update = Songs.query.get_or_404(id)
    form = UpdateForm()
    if request.method == 'POST':

        if form.validate_on_submit():
            to_update.title = form.title.data,
            to_update.artist = form.artist.data,
            to_update.genre = form.genre.data,
            to_update.instrument = form.instrument.data,
            to_update.link = form.link.data
            db.session.commit()
            return redirect(url_for('extravert_read'))
        else:
            print(form.errors)
    else:
        form.title.data = to_update.title
        form.artist.data = to_update.artist
        form.genre.data = to_update.genre
        form.instrument.data = to_update.instrument
        form.link.data = to_update.link

    return render_template('extravert_new.html',
                           title='Update',
                           form=form,
                           update=to_update)
Пример #2
0
def playerid(player_id):
    playerData = Players.query.filter_by(player_id=player_id).first()
    print(playerData)
    form = UpdateForm()
    if form.validate_on_submit():
        playerData.first_name=form.first_name.data
        playerData.last_name=form.last_name.data
        playerData.email=form.email.data
        db.session.add(playerData)
        db.session.commit()
        return redirect (url_for('home'))
    return render_template('playerid.html', title='Player', player=playerData, form=form)
Пример #3
0
def update():
    form = UpdateForm()
    if form.validate_on_submit():
        postData = shen_gong(
            shen_name=form.shen_name.data,
            power_rating=form.power_rating.data,
            description=form.description.data,
            shen_user=current_user,
        )
        db.session.add(postData)
        db.session.commit()
        return redirect(url_for('home'))

    else:
        print(form.errors)
    return render_template('update.html', title='Update', form=form)
Пример #4
0
def editstats(player_id):
    current_record = db.session.query(Players, Stats).select_from(db.join(Stats, Players))\
        .filter(Players.player_id== player_id).filter(Stats.player_id == Players.player_id).first()
    form = UpdateForm()
    if form.validate_on_submit():
        current_record.Stats.goals = form.goals.data
        current_record.Stats.assists = form.assists.data
        current_record.Stats.chances = form.chances.data
        current_record.Stats.shots = form.shots.data
        current_record.Stats.minutes = form.minutes.data
        current_record.Stats.date = form.date.data
        db.session.commit()
        return redirect(url_for('view'))
    elif request.method=='GET':
        form.goals.data = current_record.Stats.goals 
        form.assists.data = current_record.Stats.assists
        form.chances.data = current_record.Stats.chances
        form.shots.data = current_record.Stats.shots
        form.minutes.data = current_record.Stats.minutes
        form.date.data = current_record.Stats.date
    return render_template('editstats.html', title='Edit Stats Data', form=form, current= current_record)
Пример #5
0
def updaterecipe():
    updateform = UpdateForm()
    info = "Search for a recipe to rename"

    if updateform.validate_on_submit():
        name = updateform.oldrecipe_name.data
        newname = updateform.recipe_name.data
        recipe = Recipes.query.filter_by(name=name).first()
        recipe.name = newname
        db.session.commit()
        info = str(name) + " has been renamed to: " + str(newname)

        return render_template("update.html",
                               title="Update Recipe Name",
                               updateform=updateform,
                               info=info)

    return render_template("update.html",
                           title="Update Recipe Name",
                           updateform=updateform,
                           info=info)
Пример #6
0
def update_patient():
    # Assume that data is updated only after first retrieving the patient data using get button
    if 'user_id' in session and session['user_type'] == 'E':
        # code here
        form = UpdateForm()
        if form.validate_on_submit():
            sql = text(
                "SELECT  patient_ssn FROM patients WHERE patient_id = :x AND status = :state"
            )
            rslt = db.engine.execute(sql,
                                     x=form.patient_id.data,
                                     state='ACTIVE')
            name = [row[0] for row in rslt]
            if len(name) == 0:
                flash('Patient not found !', 'warning')
            else:
                if form.get.data:  # when get button is clicked
                    for field in form:
                        if field.name != 'update' and field.name != 'get':
                            field.render_kw = {
                                "readonly": False
                            }  # making fields editable
                    set_details(form, kw_flags=False
                                )  # populating fields only ssn is readonly
                elif form.update.data and form.patient_name.data:  # to ensure get has been called
                    empty_field = False
                    for field in form:
                        if not field.data and field.name != 'update' and field.name != 'get':
                            empty_field = True
                            break
                    if not empty_field:  # empty field check necessary to ensure no fields are none while updating
                        sql = text(
                            'UPDATE patients SET patient_name = :n, age = :ag, admission_date = :doa, bed_type = :bt, address = :ad, state = :s, '
                            'city = :c  WHERE patient_ssn = :ssn AND status = :state'
                        )
                        db.engine.execute(sql,
                                          n=form.patient_name.data,
                                          ag=int(form.age.data),
                                          doa=form.doa.data,
                                          bt=form.bed_type.data,
                                          ad=form.address.data,
                                          s=form.state.data,
                                          c=form.city.data,
                                          ssn=form.patient_id.data,
                                          state='ACTIVE')
                        flash('Patient update initiated successfully',
                              'success')
                        return redirect(
                            url_for('update_patient'))  # successful update
                    else:
                        flash('Update unsuccessful empty fields found',
                              'warning'
                              )  # unsuccessful update due to empty fields
                        return redirect(url_for('update_patient'))
                else:
                    flash(
                        'Please fill the fields using GET button then click on UPDATE button',
                        'warning')
                    return redirect(
                        url_for('update_patient')
                    )  # confirming the fields are filled using get
        elif form.patient_name.data:  # This is a necessity as when invalid comes it field gets locked
            for field in form:
                if field.name != 'update' and field.name != 'get':
                    field.render_kw = {"readonly": False}
            form.patient_id.render_kw = {"readonly": True}
        return render_template('update_patient.html',
                               form=form,
                               title='Update Patient Details')
    else:
        flash('You are not logged in ', 'danger')
        return redirect(url_for('login'))