def get_user_carriers(): '''Creates a tuple per user to create a selectfield with WTForms''' carriers = Carrier.get_carrier_by_user(user_id=session['user_id']) tup_carriers = [] for carrier in carriers: tup_carriers.append((carrier.id, carrier.name)) return tup_carriers
def carriers(): '''Renders and handles carriers the user adds.''' # Checks if user has been autherized prior to allowing entrance to route. if 'user_id' not in session: flash('You must be logged to access', 'alert-danger') return redirect('/') form = DCCarrierForm() # Grabs all the carrier information. carriers = Carrier.get_carrier_by_user(user_id=session['user_id']) if form.validate_on_submit(): name = form.name.data address = form.address.data city = form.city.data state = form.state.data zip = form.zip.data phone = form.phone.data # Creates a carrier. carrier = Carrier(name=name, address=address, city=city, state=state, zip=zip, phone=phone, user_id=session['user_id']) # If carrier was created we commit it. if carrier: db.session.add(carrier) return try_commit_rollback( success='Carrier created!', fail= 'Something went wrong, please try again later. If this continues please email [email protected].', route='/carriers') return render_template('user/carriers.html', form=form, carriers=carriers)