def provider_add(): """Adds provider to db.""" form = ProviderAddForm() form.populate_choices() form_dict = form.data if form.validate_on_submit(): address = Address(unknown=form.address.unknown.data, line1=form.address.line1.data, line2=form.address.line2.data, city=form.address.city.data, state_id=form.address.state.data, zip=form.address.zip.data) categories = [Category.query.get(cat) for cat in form.category.data] provider = Provider.create(name=form.name.data, email=form.email.data, telephone=form.telephone.data, website=form.website.data, address=address, categories=categories) address.get_coordinates() flash(provider.name + " added.") return redirect(url_for("main.index")) elif request.method == "POST" and not form.validate(): flash("Failed to add provider") return render_template("provideradd.html", title="Add Provider", form=form, form_dict=form_dict), 422 if not current_user.email_verified: disableForm(form) flash("Form disabled. Please verify email to unlock.") return render_template("provideradd.html", title="Add Provider", form=form, form_dict=form_dict)
def index(): form = AddressForm() if form.validate_on_submit(): address = Address(active=form.active.data, street_address=form.street_address.data, city=form.city.data, state=form.state.data, zip_code=form.zip_code.data, latitude=0,longitude=0, user=current_user) db.session.add(address) address.get_coordinates() db.session.commit() flash('Your address has been added!') return redirect(url_for('addresses.index')) return render_template('addresses/index.html', title='Addresses', form=form)