def get_controller(): """responds with the form for the example""" if views.ds_token_ok(): form = ClientForm() if form.validate() == False: flash:('All fields are required.') return render_template('form.html', form = form) else: # Save the current operation so it will be resumed after authentication session["eg"] = url_for(eg) return redirect(url_for("ds_login"))
def add_client(data): key, secret = data['form'].split('&') key = key.split('=')[-1] secret = secret.split('=')[-1] form = ClientForm(apiKey=key, secret=secret) if form.validate(): try: table.add_client(key, secret) table.update_all() table.view() emit('data success', {'msg': 'Successfully added!', 'income': 'Client!'}) emit('reload-table', table.gen_data()) return except sqlalchemy.exc.IntegrityError: emit('data error', {'msg': 'already exists!', 'income': 'Client'}) return emit('data error', {'msg': 'fail!', 'income': 'Client'}) return
def new_client(): # TODO db = get_db() aids = [(x['name'], x['name']) for x in db.do_get_aid()] bags = [(x['bag_name'], x['bag_name']) for x in db.do_attenuator()] form = ClientForm(request.form) form.aid.choices = aids form.bag.choices = bags if request.method == 'GET': return render_template('new_client.html', form=form) elif request.method == 'POST' and form.validate(): db = get_db() db.do_new_client({ 'gender': 'M' if form.gender.data == 'Male' else 'F', 'dob': form.birthdate.data, 'start_date': form.start_date.data, 'street': form.street.data, 'city': form.city.data, 'state': form.state.data, 'zip': form.zipcode.data, 'apartment': form.apartment_num.data, 'firstname': form.first_name.data, 'lastname': form.last_name.data, 'phone': form.phone.data, 'bag_name': form.bag.data, 'pickup_day': form.pick_up_day.data }) flash("New client created!") # hack - pull the client-id result = db._sqlconn.execute( ''.join([ 'SELECT * FROM clients WHERE firstname = ? ', 'AND lastname = ?' ]), (form.first_name.data, form.last_name.data)) client_id = db._row_to_dict(result)[0]['id'] if form.aid.data: db.do_client_add_aid(client_id, form.aid.data) return redirect('clients/family/{}/'.format(client_id)) else: print "validation failed" return render_template('new_client.html', form=form)
def new_client(): # TODO db = get_db() aids = [(x['name'], x['name']) for x in db.do_get_aid()] bags = [(x['bag_name'], x['bag_name']) for x in db.do_bag_list()] form = ClientForm(request.form) form.aid.choices = aids form.bag.choices = bags if request.method == 'GET': return render_template('new_client.html', form=form) elif request.method == 'POST' and form.validate(): db = get_db() db.do_new_client({ 'gender': 'M' if form.gender.data == 'Male' else 'F', 'dob': form.birthdate.data, 'start_date': form.start_date.data, 'street': form.street.data, 'city': form.city.data, 'state': form.state.data, 'zip': form.zipcode.data, 'apartment': form.apartment_num.data, 'firstname': form.first_name.data, 'lastname': form.last_name.data, 'phone': form.phone.data, 'bag_name': form.bag.data, 'pickup_day': form.pick_up_day.data }) flash("New client created!") # hack - pull the client-id result = db._sqlconn.execute(''.join([ 'SELECT * FROM clients WHERE firstname = ? ', 'AND lastname = ?' ]), (form.first_name.data, form.last_name.data)) client_id = db._row_to_dict(result)[0]['id'] if form.aid.data: db.do_client_add_aid(client_id, form.aid.data) return redirect('clients/family/{}/'.format(client_id)) else: print "validation failed" return render_template('new_client.html', form=form)