def config(self, dbconn): self.xmlroot = E.ajax() form = self.form try: dbconn.query(Urlmapkw_info).filter( Urlmapkw_info.url_kw == form['group_kw']).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return E.ajax(code='not found') try: row = dbconn.query(Admin_operkw).filter( sqlalchemy.and_( Admin_operkw.oper_id == form['oper_id'], Admin_operkw.group_kw == form['group_kw'])).one() self.ormloaded = True except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() row = Admin_operkw() if form['group_include'] in '01': form.store_to_orm(row) dbconn.add(row) else: if self.ormloaded: dbconn.delete(row) dbconn.commit() return E.ajax(code='ok')
def data(self, dbconn): orders = dbconn.execute('select * from (select porder.order_id,porder.username, porder.sername, porder.patronymic, porder.email, porder.address, porder.phones, porder.sale_type, porder.note, porder.delivery_id, porder.payment_id, porder.amount, history_prod.datetime, status_order.name as name, status_order.status_order_id from porder join history_prod using (order_id) join status_order using (status_order_id) order by status_order.name desc, order_id) as t group by name, datetime;') delivery = dbconn.query(Delivery).all() payment = dbconn.query(Payment).all() ajax = [] for d in delivery: ajax.append(E.delivery( delivery_id = str(d.delivery_id), name = d.name, )) for p in payment: ajax.append(E.payment( payment_id = str(p.payment_id), name = p.name, )) for r in orders: ajax.append(E.order( order_id = str(r[0]), name = r[1], sename = r[2], patronymic = r[3], email = r[4], address = r[5], phones = r[6], sale_type = str(r[7]), note = r[8], delivery_id = str(r[9]), payment_id = str(r[10]), amount = str(r[11]), date = r[12].strftime('%Y-%m-%d'), status = r[13] )) return E.ajax(*ajax)
def config(self, dbconn): form = self.form action = form['action'] user_id = form['user_id'] login = form['login'] username = form['username'] sername = form['sername'] patronymic = form['patronymic'] email = form['email'] address = form['address'] phones = form['phones'] sale_type = form['sale_type'] send2email = form['send2email'] if user_id == 0 and login and username and sername and patronymic and email and address and phones and sale_type and send2email: user = User(login, '1234567', username, sername, patronymic, address, phones, email, sale_type=None, send2email=None) dbconn.add(user) try: dbconn.commit() except: pass elif user_id and login and username and sername and patronymic and email and address and phones and sale_type and send2email: try: user = dbconn.query(User).filter(User.user_id == user_id).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return E.ajax() form.store_to_orm(user) dbconn.commit() try: dbconn.commit() except: dbconn.rollback() finally: dbconn.close() return E.ajax()
def data(self, dbconn): form = self.form ajax = [ E.oper(E.group(group_info, id=str(r.group_id)), E.auth_name(r.auth_name), E.lastname(r.lastname), E.firstname(r.firstname), E.middlename(r.middlename), E.email(r.email), E.phones(r.phones), E.info(r.info), id=str(r.oper_id)) for r, group_info in dbconn.query( Distrib_oper, Admin_group.group_info).filter( Distrib_oper.group_id == Admin_group.group_id) ] return E.ajax(*ajax)
def data(self, dbconn): users = dbconn.query(User).all() ajax = [] for r in users: ajax.append( E.user( user_id=str(r.user_id), name=r.username, login=r.login, sername=r.sername, patronymic=r.patronymic, email=r.email, address=r.address, phones=r.phones, sale_type=r.sale_type, send2email=r.send2email, )) return E.ajax(*ajax)
def data(self, dbconn): form = self.form group_kwds = dict(((r.group_kw, '1') for r in dbconn.query(Admin_groupkw).filter( Admin_groupkw.group_id == form['group_id']))) oper_kwds = dict(((r.group_kw, r.group_include) for r in dbconn.query(Admin_operkw).filter( Admin_operkw.oper_id == form['oper_id']))) ajax = [] for kw, kw_info, kw_help in dbconn.query( Urlmapkw_info.url_kw, Urlmapkw_info.kw_info, Urlmapkw_info.kw_help, ).order_by(Urlmapkw_info.url_kw): ajax.append( E.kw(E.info(kw_info), E.comment(kw_help), E.group(group_kwds.pop(kw, '0')), E.oper(oper_kwds.pop(kw, 'default')), name=kw)) return E.ajax(*ajax)
def data(self, dbconn): form = self.form order_id = form['order_id'] orders = dbconn.query(Prod_order).filter(Prod_order.order_id == order_id).all() products = dbconn.execute('select p.product_id, p.name, c.name from product as p join distributor as d using (distrib_id) join category as c using (category_id)') ajax = [] for p in products: ajax.append(E.product( product_id = str(p[0]), name = p[1]+' '+p[2], )) for r in orders: ajax.append(E.order( prod_order_id = str(r.prod_order_id), order_id = str(r.order_id), product_id = str(r.product_id), product_name = r.product_name, count = str(r.count), amount = str(r.amount), bonus = str(r.bonus), close=r.close, sale=str(r.sale), )) return E.ajax(*ajax)
def config(self, dbconn): form = self.form action = form['action'] order_id = form['order_id'] prod_order_id = form['prod_order_id'] product_id = form['product_id'] count = form['count'] sale = form['sale'] bonus = 0 if prod_order_id == 0: try: prod = dbconn.query(Product).filter(Product.product_id == product_id).one() amount = prod.price distr = prod.distrib_id product_name = prod.name+' (art. '+prod.articul+')' except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return prod_order = Prod_order(order_id, product_id, amount, count, product_name, bonus,"no", distr, sale) dbconn.add(prod_order) try: dbconn.commit() except: dbconn.delete(prod_order) dbconn.commit() amount = dbconn.query(func.sum(Prod_order.amount*Prod_order.count-Prod_order.sale)).filter(Prod_order.order_id == order_id).filter(Prod_order.close=="no")[0][0] try: order = dbconn.query(Order).filter(Order.order_id == order_id).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return order.amount = amount dbconn.commit() else: try: prod_order = dbconn.query(Prod_order).filter(Prod_order.prod_order_id == prod_order_id).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return try: prod = dbconn.query(Product).filter(Product.product_id == product_id).one() product_name = prod.name except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return prod_order.count = count prod_order.bonus = bonus prod_order.order_id = order_id prod_order.prod_order_id = prod_order_id prod_order.product_name = product_name prod_order.sale = sale try: dbconn.commit() amount = dbconn.query(func.sum(Prod_order.amount*Prod_order.count-Prod_order.sale)).filter(Prod_order.order_id == order_id).filter(Prod_order.close=="no")[0][0] profit = dbconn.query(func.sum(Prod_order.amount*Prod_order.procent*Prod_order.count/100+Prod_order.profit*Prod_order.count-Prod_order.sale)).filter(Prod_order.order_id == order_id).filter(Prod_order.close=="no")[0][0] try: order = dbconn.query(Order).filter(Order.order_id == order_id).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return order.amount = amount order.profit = profit dbconn.commit() except: pass orders = dbconn.query(Prod_order).filter(Prod_order.order_id == order_id).all() products = dbconn.execute('select p.product_id, p.name, c.name from product as p join distributor as d using (distrib_id) join category as c using (category_id)') ajax = [] for p in products: ajax.append(E.product( product_id = str(p[0]), name = p[1]+' '+p[2], )) for r in orders: ajax.append(E.order( prod_order_id = str(r.prod_order_id), order_id = str(r.order_id), product_id = str(r.product_id), product_name = r.product_name, count = str(r.count), amount = str(r.amount), bonus = str(r.bonus), close=r.close, sale=str(r.sale), )) return E.ajax(*ajax)
def config(self, dbconn): form = self.form action = form['action'] order_id = form['order_id'] name = form['username'] sename = form['sername'] patronymic = form['patronymic'] email = form['email'] address = form['address'] phones = form['phones'] sale_type = form['sale_type'] note = form['note'] delivery_id = form['delivery_id'] payment_id = form['payment_id'] amount = form['amount'] order_id = order_id if order_id == 0: order = Order('', '','', '','','','all','', 0,0, 0) dbconn.add(order) dbconn.commit() form['order_id'] = order.order_id form.store_to_orm(order) try: dbconn.commit() history = History(order.order_id, datetime.datetime.now(), '1') dbconn.add(history) dbconn.commit() except: dbconn.delete(order) dbconn.commit() else: try: order = dbconn.query(Order).filter(Order.order_id == order_id).one() except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() return form.store_to_orm(order) dbconn.commit() try: dbconn.commit() except: dbconn.delete(order) dbconn.commit() orders = dbconn.query(Order, History.datetime).filter(sqlalchemy.and_(History.order_id == Order.order_id, History.status_order_id == 1)).all() delivery = dbconn.query(Delivery).all() payment = dbconn.query(Payment).all() ajax = [] for d in delivery: ajax.append(E.delivery( delivery_id = str(d.delivery_id), name = d.name, )) for p in payment: ajax.append(E.payment( payment_id = str(p.payment_id), name = p.name, )) for r in orders: ajax.append(E.order( order_id = str(r[0].order_id), name = r[0].username, sename = r[0].sername, patronymic = r[0].patronymic, email = r[0].email, address = r[0].address, phones = r[0].phones, sale_type = str(r[0].sale_type), note = r[0].note, delivery_id = str(r[0].delivery_id), payment_id = str(r[0].payment_id), amount = str(r[0].amount), date = r[1].strftime('%Y-%m-%d') )) return E.ajax(*ajax)