def create(): if request.method == 'GET': return render_template('create.jinja2') elif request.method == 'POST': try: donor = Donation.select().join(Donor).where( Donor.name == request.form['name']).get() except: return render_template('create.jinja2', error='Donor dose not exists') old_donation = donor.value added_donation = int(request.form['donation']) new_donation = old_donation + added_donation Donation.update(value=new_donation).where(donor).execute() return redirect(url_for('all'))
def update_donations(): if request.method == "GET": return render_template('update.jinja2') else: # It should retrieve the donor from the database with the indicated name donor_name = Donor.select().where( Donor.name == request.form['Name']).get() # and create a new donation with the indicated donor and donation amount. Donation.update(value=request.form['Donation'])\ .where(Donation.donor == donor_name)\ .execute() # Then it should redirect the visitor to the home page. return redirect(url_for('home'))