def addraw(json_response): rawdata = Rawdata() rawdata.upload = datetime.now().strftime('%Y-%m-%d %H:%M:%S') rawdata.data = json_response session.add(rawdata) session.commit() session.close()
def updateclear(name, photo, method, recid, date): update = session.query(Cleardata).filter_by(recid=recid).first() update.name = name update.photo = photo update.method = method update.upload = date session.commit() session.close()
def create_user(name): count_users_by_name = session.query(User).filter(User.username==name).count() if count_users_by_name > 0: return 'User Already Exists' user = User(username=name) session.add(user) session.commit() return f'Successfully Added user {name}'
def addclear(name, photo, method, recid, date): cleardata = Cleardata() cleardata.name = name cleardata.photo = photo cleardata.method = method cleardata.recid = recid cleardata.upload = date session.add(cleardata) session.commit() session.close()
def removeclear(date): ondelete = session.query(Cleardata).filter(Cleardata.upload < date) if ondelete is not None: for data in ondelete: print('delete '+data.recid) session.delete(data) session.commit() session.close() else: print('delete is none')
def register(): form = RegistrationForm(request.form) if request.method == 'POST' and form.validate(): user = Users(name=form.username.data, password=form.password.data) session.add(user) session.commit() session.flush() flash('Thanks for registering') return redirect(url_for('login')) return render_template('register.html', form=form)
def submit_form(user_id, form_id, data): current_pending = session.query( Users.pending_forms).filter(Users.uid == user_id).one() current_completed = session.query( Users.completed_forms).filter(Users.uid == user_id).one() new_completed = [int(form_id)] for form in current_completed[0]: if int(form) not in new_completed and int(form_id) != int(form): new_completed.append(int(form)) new_pending = [] for form in current_pending[0]: if int(form) not in new_pending and int(form_id) != int(form): new_pending.append(int(form)) session.query(Users) \ .filter(Users.uid == user_id) \ .update(dict(completed_forms=new_completed,pending_forms=new_pending)) session.commit() # insert a result for each assessment question for question in data["results"]: value = (10 / question["answer"]) answer_type = 3 if question["answer"] > 7: answer_type = 4 elif question["answer"] < 4: answer_type = 2 extra_data = session \ .query(Companies.company_name, Assessment.title, Users.uid, Assessment.assessment_id, Companies.company_id) \ .filter(Users.uid == user_id,Users.company_id == Companies.company_id, Assessment.assessment_id == question["questionId"]) \ .one() results = Results() results.user_uid = extra_data[2] results.category = extra_data[1] results.parent_company = extra_data[0] results.value = int(round(value)) results.assessment_id = int(question["questionId"]) results.answer_type_id = answer_type session.add(results) session.commit() return get_user(user_id)
def close_orders(): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%Y-%m-%d") if request.args.get('st'): status = request.args.get('st') id = request.args.get('id') stmt = update(Close_orders).where(Close_orders.id == id).values(status = status) session.execute(stmt) logs = Logs(user=namesd, time=date_today, message='Изменен статус завершенного заказа №: ' + id) session.add(logs) session.commit() session.flush() flash('Статус заказа успешно изменен') return redirect(url_for('close_orders')) if request.args.get('del') == "yes": id = request.args.get('id') yes = session.query(Close_orders).filter(Close_orders.id == id).first() if yes.toner == 0 and yes.opc == 0 and yes.pcr == 0 and yes.wiper_blade == 0 and yes.recovery_blade == 0 and yes.develop_blade == 0 and yes.doctor_blade == 0: session.query(Close_orders).filter(Close_orders.id == id).delete() logs = Logs(user=namesd, time=date_today, message='Удален завершенный заказ №: ' + id) session.add(logs) session.commit() session.flush() flash ('Заказ был успешно удален') return redirect(url_for('close_orders')) else: flash ('Заказ не был удален') return redirect(url_for('close_orders')) full = session.query(Close_orders.id, Cartridges.name, Customers.name, Close_orders.toner, Close_orders.opc, Close_orders.pcr, Close_orders.wiper_blade, Close_orders.recovery_blade, Close_orders.develop_blade, Close_orders.doctor_blade, Close_orders.barcode, Close_orders.mark,Close_orders.user_close, Close_orders.date, Close_orders.date_close, Close_orders.status)\ .order_by(desc(Close_orders.id))\ .join(Cartridges, Close_orders.cartridge == Cartridges.id)\ .join(Customers, Close_orders.customer == Customers.id) tmp_orders = {} for order in full: if order.name not in tmp_orders: tmp_orders[order.name] = [] tmp_orders[order.name].append(order) return render_template('close_orders.html', full=tmp_orders, fullnames = namesd)
def import_categories(): filename = 'Qoo10GoodsDataLinkageMgt_CategoryInfo.csv' filepath = os.path.join(os.path.dirname(__file__), 'templates', filename) with open(filepath, 'r', encoding='utf-8') as f: reader = csv.reader(f) header = next(reader) for row in reader: category = models.Qoo10Category() category.l_category_id = row[0] category.l_category_name = row[1] category.m_category_id = row[2] category.m_category_name = row[3] category.s_category_id = row[4] category.s_category_name = row[5] session.add(category) session.commit()
def send_form(user_id, form_id): current_pending = session.query( Users.pending_forms).filter(Users.uid == user_id).one() new_pending = [int(form_id)] for form in current_pending[0]: if int(form) not in new_pending: new_pending.append(int(form)) session.query(Users) \ .filter(Users.uid == user_id) \ .update(dict(pending_forms=new_pending)) session.commit() return get_user(user_id)
def insert_db(filename, tmp_filename, share_dict): himitsu_lun = Himitsu_lun() enc_json = enc_db_share(share_dict["3"].decode("utf-8")) enc_json = json.loads(enc_json) now = datetime.now() himitsu_lun.filename = filename himitsu_lun.enc_filename = tmp_filename himitsu_lun.share_id = "3" himitsu_lun.share = enc_json["cipher_text"] himitsu_lun.nonce = enc_json["nonce"] himitsu_lun.created_at = now himitsu_lun.delete_at = now + timedelta(days=3) session.add(himitsu_lun) session.commit()
def create_tag_post(tag, post): """Function creates combination tag and post in db and checks existance of tag""" # get tag tag_object = get_tag_object(tag) if not tag_object: tag_to_insert = Tag(name=tag) session.add(tag_to_insert) # get post post_object = get_post_object(post) if post_object: tag_to_insert.posts.append(post_object) session.commit() return f'Successfully Added tag {tag} to post {post}' return f'Incorrect combination'
def delete_file(): now = datetime.now() shares = session.query(Himitsu_lun).filter( Himitsu_lun.delete_at < now).all() delete_file_list = [] for share in shares: delete_file_list.append(f"{share.enc_filename}") for enc_filename in delete_file_list: count = 0 while count < 2: print(count) if os.path.exists(PATH + enc_filename): os.remove(PATH + enc_filename) break else: count += 1 session.query(Himitsu_lun).filter( Himitsu_lun.enc_filename == enc_filename).delete() session.commit()
def get_categories(): # 一覧ページからカテゴリーを取得 results = [] base_url = 'https://komai0526.thebase.in/' resp = requests.get(base_url) soup = BeautifulSoup(resp.content, 'html.parser') top_categories = soup.select('.leftSide ul#appsItemCategoryTag li') for top_category in top_categories[2:]: # 親カテゴリー取得 link = top_category.select('a')[0] name = link.text url = link.get('href') category_id = url.split('/')[-1] # サブカテゴリー取得 sub_categories = top_category.select('ul li a') # 一旦親カテゴリーを登録 parent_category = models.Category(name=name, source_url=url, category_id=category_id) parent_category = get_or_create(session, models.Category, parent_category, 'category_id') session.add(parent_category) session.commit() if sub_categories: for link in sub_categories: url = link.get('href') category_id = url.split('/')[-1] category = models.Category(name=link.text, source_url=url, category_id=category_id, parent_id=parent_category.id) category = get_or_create(session, models.Category, category, 'category_id') results.append(category) else: results.append(parent_category) return results
def archive_all(): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%Y-%m-%d") query = session.query(Close_orders).filter(Close_orders.status == 'success').all() for order in query: cartridge = order.cartridge customer = order.customer toner = order.toner opc = order.opc pcr = order.pcr wiper_blade = order.wiper_blade recovery_blade = order.recovery_blade develop_blade = order.develop_blade doctor_blade = order.doctor_blade barcode = order.barcode mark = order.mark user_close = order.user_close date = order.date date_close = order.date_close status = order.status comment = order.comment archive = Archive_orders(cartridge=cartridge,customer=customer,toner=toner,opc=opc,pcr=pcr,wiper_blade=wiper_blade, recovery_blade=recovery_blade,develop_blade=develop_blade,doctor_blade=doctor_blade, user_close=user_close,barcode=barcode,mark=mark,date=date,date_close=date_close,status=status, comment=comment) session.add(archive) logs = Logs(user=namesd, time=date_today, message='Завершенные заказы перемещены в архив') session.add(logs) session.query(Close_orders).filter(Close_orders.id == order.id).delete() session.commit() session.flush() flash ('Заказы перемещены в архив') return redirect(url_for('close_orders'))
def create_posts(posts_list, userid): for post in posts_list: post_to_insert = Post(title=post, user_id=userid) session.add(post_to_insert) session.commit() return f'Successfully Added posts {", ".join(posts_list)}'
#-*- coding: utf-8 -*- from settings import session from models import Pais # p = Pais('México DF', 'México', 65, 'Peso') # session.add(p) # session.commit() paises = session.query(Pais).all() for pais in paises: pais.continente = 'América' session.commit()
def full_close_order(): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%d.%m.%Y") if request.args.get('barcode'): barcode = request.args['barcode'] user = Users.query.all() full = session.query(Close_orders, Cartridges, Customers)\ .filter_by(barcode=barcode)\ .join(Cartridges, Close_orders.cartridge == Cartridges.id)\ .join(Customers, Close_orders.customer == Customers.id) full1 = session.query(Archive_orders, Cartridges, Customers)\ .filter_by(barcode=barcode)\ .join(Cartridges, Archive_orders.cartridge == Cartridges.id)\ .join(Customers, Archive_orders.customer == Customers.id) return render_template('full_close_order.html', user=user, full=full, full1=full1, fullnames = namesd) if request.form['action'] == 'Edit': id = request.form['id'] user_close = request.form['user_close'] mark = request.form['mark'] update = session.query(Close_orders).filter_by(id=id).first() comment = request.form['comment'] try: toner = request.form['toner'] except: toner = 0 try: opc = request.form['opc'] except: opc = 0 try: pcr = request.form['pcr'] except: pcr = 0 try: wiper_blade = request.form['wiper_blade'] except: wiper_blade = 0 try: recovery_blade = request.form['recovery_blade'] except: recovery_blade = 0 try: develop_blade = request.form['develop_blade'] except: develop_blade = 0 try: doctor_blade = request.form['doctor_blade'] except: doctor_blade = 0 session.query(Close_orders).filter(Close_orders.id == id).update({'cartridge' : update.cartridge, 'customer' : update.customer,'toner' : toner,'opc' : opc,'pcr' : pcr,'wiper_blade' : wiper_blade, 'recovery_blade' : recovery_blade,'develop_blade' : develop_blade,'doctor_blade' : doctor_blade, 'barcode' : update.barcode,'mark' : mark,'user_close' : user_close,'date' : update.date, 'date_close' : date_today, 'comment' : comment}) logs = Logs(user=namesd, time=date_today, message='Завершенный заказ изменен. Штрихкод: '+update.barcode) session.add(logs) session.commit() session.flush() flash('Заказ успешно изменен') return redirect(url_for('close_orders'))
def barcode(rows=None): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%d.%m.%Y") full = session.query(Barcode, Cartridges,Customers).join(Cartridges, Barcode.cartridge == Cartridges.id).join(Customers, Barcode.customer == Customers.id).order_by(Barcode.id) cartridges = Cartridges.query.order_by(Cartridges.name).all() customers = Customers.query.order_by(Customers.name).all() if request.method == 'POST': if request.form['action'] == 'Find': if request.form['barcode']: barcod = request.form['barcode'] full = session.query(Barcode, Cartridges, Customers).join(Cartridges, Barcode.cartridge == Cartridges.id).join( Customers, Barcode.customer == Customers.id).filter(Barcode.barcode.like('%'+barcod+'%')).all() return render_template('barcode.html', full=full, fullnames = namesd) else: flash('Штрихкод не найден') if request.form['action'] == 'Edit': barcode = request.form['barcod'] cartridge = request.form['cartridge'] customer = request.form['customer'] session.query(Barcode).filter(Barcode.barcode == barcode).update({'cartridge': cartridge, 'customer': customer, 'barcode': barcode}) session.query(Close_orders).filter(Close_orders.barcode == barcode).update({'cartridge': cartridge, 'customer': customer}) session.query(Archive_orders).filter(Archive_orders.barcode == barcode).update({'cartridge': cartridge, 'customer': customer}) session.query(Orders).filter(Orders.barcode == barcode).update({'cartridge': cartridge, 'customer': customer}) logs = Logs(user=namesd, time=date_today, message='Штрихкод № ' + barcode + ' изменен') session.add(logs) session.commit() session.flush() flash('Штрихкод был успешно изменён') return redirect(url_for('barcode')) if request.args.get('edit') == "yes": barcode = request.args.get('barcode') barcod = Barcode.query.filter_by(barcode = barcode).first() cartridgee = Cartridges.query.filter_by(id = barcod.cartridge).first() customerr = Customers.query.filter_by(id = barcod.customer).first() return render_template('barcode_edit.html', cartridges=cartridges, customers=customers,barcode=barcode,customerr=customerr,cartridgee=cartridgee, fullnames = namesd) if request.args.get('del') == "yes": barcode = request.args.get('barcode') yes = Archive_orders.query.filter_by(barcode = barcode).count() yess = Close_orders.query.filter_by(barcode = barcode).count() if yes == 0 and yess == 0: session.query(Barcode).filter(Barcode.barcode == barcode).delete() logs = Logs(user=namesd, time=date_today, message='Штрихкод № ' + barcode + ' удален') session.add(logs) session.commit() session.flush() flash('Штрихкод был успешно удален') return redirect(url_for('barcode')) else: flash('Штрихкод не был удален') return redirect(url_for('barcode')) return render_template('barcode.html', full=full, cartridges=cartridges, customers=customers, fullnames = namesd)
def cartridges(rows=None): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%d.%m.%Y") if request.args.get('del') == "yes": id = request.args.get('id') yes = Archive_orders.query.filter_by(cartridge=id).count() yess = Close_orders.query.filter_by(cartridge=id).count() cart = session.query(Cartridges).filter(Cartridges.id == id).one() if yes == 0 and yess == 0: session.query(Cartridges).filter(Cartridges.id == id).delete() logs = Logs(user=namesd, time=date_today, message='Картридж ' + cart.name + ' удален') session.add(logs) session.commit() session.flush() flash('Картридж успешно удален') return redirect(url_for('cartridges')) else: flash('Картридж не удален') return redirect(url_for('cartridges')) if request.method == 'POST': if request.form['action'] == 'Add': return render_template('cartridge_add.html', fullnames = namesd) if request.form['action'] == 'Cancel': return redirect(url_for('cartridges')) if request.form['action'] == 'Find': if request.form['name']: name = request.form['name'] cartridges = session.query(Cartridges).filter(Cartridges.name.like('%'+name+'%')).all() return render_template('cartridges.html', rows=cartridges, fullnames = namesd) else: flash('Картридж не найден') if request.form['action'] == 'Edit': id = request.form['id'] name = request.form['name'] printer = request.form['printer'] try: toner = request.form['toner'] except: toner = 0 try: opc = request.form['opc'] except: opc = 0 try: pcr = request.form['pcr'] except: pcr = 0 try: wiper_blade = request.form['wiper_blade'] except: wiper_blade = 0 try: recovery_blade = request.form['recovery_blade'] except: recovery_blade = 0 try: develop_blade = request.form['develop_blade'] except: develop_blade = 0 try: doctor_blade = request.form['doctor_blade'] except: doctor_blade = 0 try: printer = request.form['printer'] except: printer = "" session.query(Cartridges).filter(Cartridges.id == id).update( {'name': name, 'toner': toner, 'opc': opc, 'pcr': pcr, 'wiper_blade': wiper_blade, 'recovery_blade': recovery_blade, 'develop_blade': develop_blade, 'doctor_blade': doctor_blade, 'printers': printer}) logs = Logs(user=namesd, time=date_today, message='Картридж ' + name + ' изменен') session.add(logs) session.commit() session.flush() flash('Картридж успешно изменён') return redirect(url_for('cartridges')) if request.form['action'] == 'Adds': name = request.form['name'] try: toner = request.form['toner'] except: toner = 0 try: opc = request.form['opc'] except: opc = 0 try: pcr = request.form['pcr'] except: pcr = 0 try: wiper_blade = request.form['wiper_blade'] except: wiper_blade = 0 try: recovery_blade = request.form['recovery_blade'] except: recovery_blade = 0 try: develop_blade = request.form['develop_blade'] except: develop_blade = 0 try: doctor_blade = request.form['doctor_blade'] except: doctor_blade = 0 try: printer = request.form['printer'] except: printer = "" cartridge = Cartridges(name=name,toner=toner,opc=opc,pcr=pcr,wiper_blade=wiper_blade,recovery_blade=recovery_blade, develop_blade=develop_blade,doctor_blade=doctor_blade,printers=printer) session.add(cartridge) logs = Logs(user=namesd, time=date_today, message='Картридж ' + name + ' добавлен') session.add(logs) session.commit() session.flush() flash ('Картридж успешно добавлен') return redirect(url_for('cartridges')) cartridges = Cartridges.query.order_by('name').all() return render_template('cartridges.html',rows=cartridges, fullnames = namesd)
def customers(rows=None): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%d.%m.%Y") if request.args.get('del') == "yes": id = request.args.get('id') yes = Archive_orders.query.filter_by(customer=id).count() yess = Close_orders.query.filter_by(customer=id).count() cust = session.query(Customers).filter(Customers.id == id).one() if yes == 0 and yess == 0: session.query(Customers).filter(Customers.id == id).delete() logs = Logs(user=namesd, time=date_today, message='Клиент ' + cust.name + ' удален') session.add(logs) session.commit() session.flush() flash('Клиент успешно удален') return redirect(url_for('customers')) else: flash('Клиент не удален') return redirect(url_for('customers')) if request.method == 'POST': if request.form['action'] == 'Add': return render_template('customer_add.html', fullnames = namesd) if request.form['action'] == 'Full': return render_template('full_customers.html', fullnames = namesd) if request.form['action'] == 'Cancel': return redirect(url_for('customers')) if request.form['action'] == 'Find': if request.form['name']: name = request.form['name'] customers = session.query(Customers).filter(Customers.name.like('%' + name + '%')).all() customerss = session.query(Customers).filter(Customers.inn.like('%' + name + '%')).all() return render_template('customers.html', rows=customers, rowss=customerss, fullnames = namesd) else: flash('Картридж не найден') if request.form['action'] == 'Edit': id = request.form['id'] name = request.form['name'] inn = request.form['inn'] try: inn = request.form['inn'] except: inn = "" session.query(Customers).filter(Customers.id == id).update( {'name': name, 'inn': inn}) logs = Logs(user=namesd, time=date_today, message='Клиент ' + name + ' изменен') session.add(logs) session.commit() session.flush() flash('Клиент успешно изменён') return redirect(url_for('customers')) if request.form['action'] == 'Adds': name = request.form['name'] try: inn = request.form['inn'] except: inn = "" customer = Customers(name=name,inn=inn) session.add(customer) logs = Logs(user=namesd, time=date_today, message='Клиент ' + name + ' добавлен') session.add(logs) session.commit() session.flush() flash ('Клиент успешно добавлен') return redirect(url_for('customers')) customers = Customers.query.order_by('name').all() return render_template('customers.html',rows=customers, fullnames = namesd)
def orders(rows=None,cartridges=None,customers=None,tows=None,full=None): auth = request.authorization user1 = session.query(Users).filter_by(name=auth.username).first() namesd = user1.fullname date = datetime.date.today() date_today = date.strftime("%Y-%m-%d") cartridges = Cartridges.query.order_by(Cartridges.name).all() customers = Customers.query.order_by(Customers.name).all() tows = Tow.query.all() user = Users.query.filter_by(vision='1').order_by(desc(Users.id)).all() full = session.query(Orders.id, Cartridges.name, Customers.name, Tow.fullname, Orders.barcode, Orders.mark, Orders.date)\ .order_by(desc(Orders.id))\ .join(Cartridges, Orders.cartridge == Cartridges.id)\ .join(Customers, Orders.customer == Customers.id)\ .join(Tow, Orders.tow == Tow.id) tmp_orders = {} for order in full: if order.name not in tmp_orders: tmp_orders[order.name] = [] tmp_orders[order.name].append(order) if request.method == 'POST': if request.form['action'] == 'Add': if request.form['barcode']: barcod = request.form['barcode'] orderss = Orders.query.filter_by(barcode=barcod).count() if orderss != 0: barcodd = request.form['barcode'] full = session.query(Orders.id, Cartridges.name, Customers.name, Tow.fullname, Orders.barcode, Orders.mark, Orders.date)\ .filter_by(barcode=barcodd).join(Cartridges, Orders.cartridge == Cartridges.id)\ .join(Customers, Orders.customer == Customers.id).join(Tow, Orders.tow == Tow.id) tmps_orders = {} for order in full: if order.name not in tmps_orders: tmps_orders[order.name] = [] tmps_orders[order.name].append(order) return render_template('orders.html', tows=tows, full=tmps_orders, user=user) else: barcode = Barcode.query.filter_by(barcode=barcod).count() if barcode == 0: flash ('Штрих-код не найден') else: barcode = session.query(Barcode).filter_by(barcode=barcod).first() cartridge = barcode.cartridge customer = barcode.customer mark = request.form['mark'] tow = request.form['tow'] barcod = barcode.barcode order = Orders(cartridge=cartridge,customer=customer,tow=tow,barcode=barcod,mark=mark,date=date_today) session.add(order) logs = Logs(user=namesd, time=date_today, message='Добавлен заказ. Штрихкод: '+str(barcod)) session.add(logs) session.commit() session.flush() flash ('Заказ успешно добавлен') return redirect(url_for('orders')) else: return render_template('orders_add.html',cartridges=cartridges,customers=customers,tows=tows, date=date_today, fullnames = namesd) if request.form['action'] == 'Full': return render_template('full_orders.html') if request.form['action'] == 'Chancel': return redirect(url_for('orders')) if request.form['action'] == 'cst_ord_add': cst = request.form['cst_ord'] customerr = Customers.query.filter_by(name=cst).first() return render_template('orders_add_cust.html',cartridges=cartridges,customerr=customerr,tows=tows, date=date_today, fullnames = namesd) if request.form['action'] == 'Adds': if not request.form['barcode']: barcod = random.randint(10000000, 99999999 ) barcod = str(barcod) barcode = Barcode.query.filter_by(barcode=barcod).count() while barcode != 0: barcod = random.randint(10000000, 99999999 ) barcod = str(barcod) barcode = Barcode.query.filter_by(barcode=barcod).count() elif request.form['barcode']: barcod = request.form['barcode'] barcode = Barcode.query.filter_by(barcode=barcod).count() if barcode == 0: barcod = random.randint(10000000, 99999999 ) barcod = str(barcod) barcode = Barcode.query.filter_by(barcode=barcod).count() else: barcod = request.form['barcode'] barcode = Barcode.query.filter_by(barcode=barcod).count() if barcode == 0: from bar_gen import Code128 code = str(barcod) full_barcode = path_barcode Code128(code).save(formats=['gif'],outDir=full_barcode, fnRoot=code ) barcode_add = Barcode(cartridge=request.form['cartridge'],customer=request.form['customer'],barcode=barcod) session.add(barcode_add) order = Orders(cartridge=request.form['cartridge'],customer=request.form['customer'],tow=request.form['tow'],barcode=barcod,mark=request.form['mark'],date=request.form['date']) session.add(order) logs = Logs(user=namesd, time=date_today, message='Добавлен заказ. Штрихкод: '+str(barcod)) session.add(logs) session.commit() session.flush() flash ('Заказ успешно добавлен') return redirect(url_for('orders')) if request.form['action'] == 'Close': id = request.form['id'] user_close = request.form['user_close'] mark = request.form['mark'] comment = request.form['comment'] delete = session.query(Orders).filter_by(id=id).first() try: toner = request.form['toner'] except: toner = 0 try: opc = request.form['opc'] except: opc = 0 try: pcr = request.form['pcr'] except: pcr = 0 try: wiper_blade = request.form['wiper_blade'] except: wiper_blade = 0 try: recovery_blade = request.form['recovery_blade'] except: recovery_blade = 0 try: develop_blade = request.form['develop_blade'] except: develop_blade = 0 try: doctor_blade = request.form['doctor_blade'] except: doctor_blade = 0 add = Close_orders(cartridge=delete.cartridge,customer=delete.customer,toner=toner,opc=opc,pcr=pcr, wiper_blade=wiper_blade,recovery_blade=recovery_blade,develop_blade=develop_blade, doctor_blade=doctor_blade,barcode=delete.barcode,mark=mark,user_close=user_close, date = delete.date,date_close = date_today,comment = comment) session.add(add) session.delete(delete) logs = Logs(user=namesd, time=date_today, message='Закрыт заказ. Штрихкод: '+str(delete.barcode)) session.add(logs) session.commit() session.flush() flash('Заказ успешно закрыт') return redirect(url_for('orders')) return render_template('orders.html',tows=tows, full=tmp_orders, user=user, fullnames = namesd)
def create_tag(tag): tag_to_insert = Tag(name=tag) session.add(tag_to_insert) session.commit() return f'Successfully Added tag {tag}'