def donate(campaign_id): if current_user.has_roles('admin'): m = re.search('(\d+)', campaign_id) id = m.group(0) return redirect("/admin/donate/"+str(id)) else: campaign = campaign_from_url(campaign_id) admin_fields_enable = False if request.method == 'GET': if (campaign.status != 'Approved'): return render_template('donor_form_not_open.html') elif (campaign.needs() <= 0): return render_template('donor_form_full.html') else: form = DonorForm() if current_user.is_active(): form.set_data(current_user) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) elif request.method == 'POST': form = DonorForm(request.form) if form.validate(): result = donate_service.create_donation(form, campaign) if not result['error']: return donate_service.ccavRequest(form, result['donation']) else: print result flash('Oops something went wrong, please try again') app.logger.warning(form.errors) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable)
def donate_1(campaign_id): if current_app.config.get('DEBUG', True): campaign = Campaign.query.get(campaign_id) admin_fields_enable = False if request.method == 'GET': form = DonorForm() if current_user.is_active(): form.set_data(current_user) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) elif request.method == 'POST': form = DonorForm(request.form) if form.validate(): amount = form.amount_choice.data if not amount: amount = form.customize_amount.data donor = current_user if current_user.is_active() else admin_user() donation = Donation(amount=amount, donor=donor, first_name=form.first_name.data, last_name=form.last_name.data, campaign=campaign, address=form.address.data, state=form.state.data, city=form.city.data, confirmation=12345, identification_type="PAN Card", identification=form.pan_number.data, tax_exemption_certificate=form.tax_exemption_certificate.data, ann_choice=form.ann_choice.data) db.session.add(donation) db.session.commit() curr_percent = campaign.percent_funded() old_percent = curr_percent - int(round(donation.amount * 100) /campaign.target()) send_mail(old_percent=old_percent,curr_percent=curr_percent,campaign=campaign,donation=donation) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) else: print form.errors return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable)
def donate_1(campaign_id): if current_app.config.get('DEBUG', True): campaign = campaign_from_url(campaign_id) admin_fields_enable = False if request.method == 'GET': form = DonorForm() if current_user.is_active(): form.set_data(current_user) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) elif request.method == 'POST': form = DonorForm(request.form) if form.validate(): amount = form.amount_choice.data if not amount: amount = form.customize_amount.data donor = current_user if current_user.is_active() else admin_user() donation = Donation(amount=amount, donor=donor, first_name=form.first_name.data, last_name=form.last_name.data, campaign=campaign, address=form.address.data, state=form.state.data, city=form.city.data, confirmation=12345, identification_type="PAN Card", identification=form.pan_number.data, tax_exemption_certificate=form.tax_exemption_certificate.data, ann_choice=form.ann_choice.data) db.session.add(donation) db.session.commit() curr_percent = campaign.percent_funded() old_percent = curr_percent - int(round(donation.amount * 100) /campaign.target()) send_mail(old_percent=old_percent,curr_percent=curr_percent,campaign=campaign,donation=donation) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) else: print form.errors return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable)
def donate_admin(campaign_id): campaign = campaign_from_url(campaign_id) admin_fields_enable = True if request.method == 'GET': form = DonorForm() if current_user.is_active(): form.set_data(current_user) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) elif request.method == 'POST': form = DonorForm(request.form) if form.validate(): amount = form.amount_choice.data if not amount: amount = form.customize_amount.data donor = User.query.filter(func.lower(User.email)==func.lower(form.user_email.data)).first() if donor: donation = Donation(amount=amount, donor=donor, first_name=form.first_name.data, last_name=form.last_name.data, campaign=campaign, address=form.address.data, state=form.state.data, city=form.city.data, confirmation=form.confirmation.data, identification_type="PAN Card", identification=form.pan_number.data, tax_exemption_certificate=form.tax_exemption_certificate.data, ann_choice=form.ann_choice.data) db.session.add(donation) db.session.commit() curr_percent = campaign.percent_funded() old_percent = curr_percent - int(round(donation.amount * 100) /campaign.target()) send_mail(old_percent=old_percent,curr_percent=curr_percent,campaign=campaign,donation=donation) if (curr_percent >= 100): campaign.status = 'Closed' db.session.add(campaign) db.session.commit() flash('Successfully donated for this campaign') return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) else: flash('Unable to find donor in the system with the given email. Please try another email.') return render_template("donor_form.html", form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) else: print form.errors return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable)
def memories(): all_memories = Memory.query.filter_by(can_share=True).all() if request.method == 'GET': form = MemoryForm() return render_template('memories.html', form=form, memories=all_memories) else: form = MemoryForm(request.form) user = current_user if current_user.is_active() else None if form.validate(): memory = Memory(name=form.name.data, city=form.city.data, state=form.state.data, email=form.email.data, can_share=form.can_share.data, memory_by=user, words=form.words.data) db.session.add(memory) db.session.commit() all_memories = Memory.query.filter_by(can_share=True).all() return render_template("memories.html", memories=all_memories) else: return render_template("memories.html", memories=all_memories, form=form)
def donate(campaign_id): if current_user.has_roles('admin'): return redirect("/admin/donate/"+str(campaign_id)) else: campaign = Campaign.query.get(campaign_id) admin_fields_enable = False if request.method == 'GET': form = DonorForm() if current_user.is_active(): form.set_data(current_user) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable) elif request.method == 'POST': form = DonorForm(request.form) if form.validate(): result = donate_service.create_donation(form, campaign) if not result['error']: return donate_service.ccavRequest(form, result['donation']) else: print result flash('Oops something went wrong, please try again') app.logger.warning(form.errors) return render_template('donor_form.html', form=form, campaign=campaign, admin_fields_enable=admin_fields_enable)
def get(self): form = BeneficiarySignupForm() if (current_user.is_active() and current_user.organization_created): form.set_data(current_user.organization_created[0]) return render_template('start.html', form=form)
def campaign(id): campaign = campaign_from_url(id) if request.method == 'GET' or request.method == 'HEAD': return render_template('campaign.html', campaign=campaign, enable_inactive_campaign=current_user.is_active() and current_user.has_roles('admin')) else: form = BeneficiarySignupForm(request.form) if form.validate(): image = request.files['imageUpload'] filename = secure_filename(image.filename) if filename and allowed_file(filename): full_save_path = os.path.join(app.config['UPLOAD_DIRECTORY'], 'tmp', filename) image.save(full_save_path) result = signup_service.edit_beneficiary(campaign, form, filename) if not result['error']: flash('You successfully edited the campaign') return render_template('campaign.html', campaign=campaign, enable_inactive_campaign=current_user.is_active() and current_user.has_roles('admin')) else: flash('Oops something went wrong, please try again') return render_template('beneficiary_form.html', form=form)
def get(self): form = BeneficiarySignupForm() if (current_user.is_active() and current_user.organization_created): form.set_data(current_user.organization_created[-1]) return render_template('start.html', form=form)