def create(): form = UserForm() if form.validate_on_submit(): try: m = hashlib.md5() password = form.data['password'].encode('utf-8') m.update(password) hashpass = m.hexdigest() insert('users', {'username': form.data['username'], 'password': hashpass}) except IntegrityError: getattr(form, 'username').errors = ( 'User with given name already exists.', ) return render_template('users/create.html', form=form)
def save_order(data): data_orders = {'client_id': data['client'], 'user_id': session.get('user')} statuses = select('order_statuses', {'status_name': data['status']}) if statuses: data_orders['status_id'] = statuses[0].id order_id = insert('orders', data_orders) for product in data['products']: data_products = { 'order_id': order_id, 'product_id': product['product'], 'price': product['price'], 'quantity': product['quantity'], } insert('order_products', data_products)
def edit_client(form, client_id): client_data = { 'name': form.data['name'], 'surname': form.data['surname'], 'email': form.data['email'], } utils.run_custom_query( """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format( client_id ), fetch=False ) utils.update('clients', {'id': client_id}, client_data) for phone in form.data['phones']: if phone['phone']: utils.insert( 'client_phones', {'client_id': client_id, 'phone': phone['phone']} ) if form.data['billing_address']: billing = utils.select('client_addresses', {'client_id': client_id, 'type': 'billing'}) data = form.data['billing_address'] utils.update( 'addresses', { 'id': billing[0].id, }, { 'country': data['country'], 'city': data['city'], 'street': data['street'] } ) if form.data['delivery_address']: delivery = utils.select('client_addresses', {'client_id': client_id, 'type': 'delivery'}) data = form.data['delivery_address'] utils.update( 'addresses', { 'id': delivery[0].id, }, { 'country': data['country'], 'city': data['city'], 'street': data['street'] } )
def create_client(form): client_data = { 'name': form.data['name'], 'surname': form.data['surname'], 'email': form.data['email'] } client_id = utils.insert('clients', client_data) for phone in form.data['phones']: if phone['phone']: utils.insert( 'client_phones', {'client_id': client_id, 'phone': phone['phone']} ) if form.data['billing_address']: data = form.data['billing_address'] address_id = utils.insert( 'addresses', { 'country': data['country'], 'city': data['city'], 'street': data['street'] } ) utils.insert( 'client_addresses', { 'client_id': client_id, 'address_id': address_id, 'type': 'billing' } ) if form.data['delivery_address']: data = form.data['delivery_address'] address_id = utils.insert( 'addresses', { 'country': data['country'], 'city': data['city'], 'street': data['street'] } ) utils.insert( 'client_addresses', { 'client_id': client_id, 'address_id': address_id, 'type': 'delivery' } )
def create(): form = UserForm() if form.validate_on_submit(): try: m = hashlib.md5() password = form.data['password'].encode('utf-8') m.update(password) hashpass = m.hexdigest() insert('users', { 'username': form.data['username'], 'password': hashpass }) except IntegrityError: getattr( form, 'username').errors = ('User with given name already exists.', ) return render_template('users/create.html', form=form)
def save_order(data): data_orders = { 'client_id': data['client'], 'user_id': session.get('user') } statuses = select('order_statuses', {'status_name': data['status']}) if statuses: data_orders['status_id'] = statuses[0].id order_id = insert('orders', data_orders) for product in data['products']: data_products = { 'order_id': order_id, 'product_id': product['product'], 'price': product['price'], 'quantity': product['quantity'], } insert('order_products', data_products)
def edit_client(form, client_id): client_data = { 'name': form.data['name'], 'surname': form.data['surname'], 'email': form.data['email'], } utils.run_custom_query( """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format(client_id), fetch=False) utils.update('clients', {'id': client_id}, client_data) for phone in form.data['phones']: if phone['phone']: utils.insert('client_phones', { 'client_id': client_id, 'phone': phone['phone'] }) if form.data['billing_address']: billing = utils.select('client_addresses', { 'client_id': client_id, 'type': 'billing' }) data = form.data['billing_address'] utils.update('addresses', { 'id': billing[0].id, }, { 'country': data['country'], 'city': data['city'], 'street': data['street'] }) if form.data['delivery_address']: delivery = utils.select('client_addresses', { 'client_id': client_id, 'type': 'delivery' }) data = form.data['delivery_address'] utils.update('addresses', { 'id': delivery[0].id, }, { 'country': data['country'], 'city': data['city'], 'street': data['street'] })
def update_order(order_id, data): order_data = { 'client_id': data['client'], } statuses = select('order_statuses', {'status_name': data['status']}) if statuses: order_data['status_id'] = statuses[0].id update('orders', {'id': order_id}, order_data) delete('order_products', {'order_id': order_id}) for product in data['products']: data_products = { 'order_id': order_id, 'product_id': product['product'], 'price': product['price'], 'quantity': product['quantity'], } insert('order_products', data_products)
def create_client(form): client_data = { 'name': form.data['name'], 'surname': form.data['surname'], 'email': form.data['email'] } client_id = utils.insert('clients', client_data) for phone in form.data['phones']: if phone['phone']: utils.insert('client_phones', { 'client_id': client_id, 'phone': phone['phone'] }) if form.data['billing_address']: data = form.data['billing_address'] address_id = utils.insert( 'addresses', { 'country': data['country'], 'city': data['city'], 'street': data['street'] }) utils.insert('client_addresses', { 'client_id': client_id, 'address_id': address_id, 'type': 'billing' }) if form.data['delivery_address']: data = form.data['delivery_address'] address_id = utils.insert( 'addresses', { 'country': data['country'], 'city': data['city'], 'street': data['street'] }) utils.insert('client_addresses', { 'client_id': client_id, 'address_id': address_id, 'type': 'delivery' })
def create_status(data): utils.insert('order_statuses', data)
def create_status(data): utils.insert("order_statuses", data)