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 select_url_label(self, field): return E.options(*[ E.option(E.value(r.url_label), u"%s [ %s ]" % (r.url_label, r.url_prefix)) for r in self.template_ref().dbconn.query(Urllabel).order_by( Urllabel.url_label) ])
def select_distrib_id(self, field): options = [] for r in self.template_ref().dbconn.query(Distributor): options.append( E.option(E.value(str(r.distrib_id)), "%s" % (r.discription))) options.append(E.option(E.value('0'), u'все')) return E.options(*options)
def select_group_id(self, field): options = [] group_id = self['group_id'] for r in self.template_ref().dbconn.query(Admin_group).order_by( Admin_group.group_info): options.append( E.option(E.value(str(r.group_id)), "%s [ %s ]" % (r.group_info, r.group_help))) return E.options(*options)
def E_data(self): dbconn = self.dbconn status = dbconn.query(Status_order) data = E.data() data_tag = data.xpath('//data')[0] for p in status: data_tag.append( E.status(status_id=str(p.status_order_id), name=p.name)) return data
def select_mark(self, field): return E.options( E.option(E.value('left'), u'слева'), E.option(E.value('right'), u'справа'), E.option(E.value('top'), u'сверху'), E.option(E.value('bottom'), u'снизу'), )
def E_data(self): dbconn = self.dbconn delivery = dbconn.query(Price_delivery) data = E.data() data_tag = data.xpath('//data')[0] for p in delivery: data_tag.append( E.delivery(delivery_id=str(p.price_delivery_id), name=p.name, price=str(p.price))) return data
def select_distrib_id(self, field): options = [] options.append(E.option(E.value('0'), u'все')) for r in self.template_ref().dbconn.query(Distributor).filter( Product.distrib_id == Distributor.distrib_id): options.append( E.option(E.value(str(r.distrib_id)), "%s" % (r.discription))) # options.append(E.option(E.value('-1'),u'----------------')) return E.options(*options)
def E_data(self): dbconn = self.dbconn status = dbconn.query(Banners) data = E.data() data_tag = data.xpath('//data')[0] for p in status: data_tag.append( E.banner(banner_id=str(p.banner_id), name=p.name, title=p.title, alt=p.alt, link=p.link, mark=p.mark)) return data
def E_data(self): dbconn = self.dbconn distributor = dbconn.query( Distributor, Category).filter(Distributor.category_id == Category.category_id) data = E.data() data_tag = data.xpath('//data')[0] for p in distributor: data_tag.append( E.distributor(distrib_id=str(p[0].distrib_id), category_name=p[1].name, category_id=str(p[1].category_id), discription=p[0].discription, rate='%10.2f' % (p[0].rate))) return data
def E_data(self): dbconn = self.dbconn delivery = dbconn.query( Delivery, Payment.name).filter(Delivery.payment_id == Payment.payment_id) data = E.data() data_tag = data.xpath('//data')[0] for p in delivery: data_tag.append( E.delivery(payment_id=str(p[0].payment_id), delivery_id=str(p[0].delivery_id), name=p[0].name, note=p[0].note, payment_name=p[1])) return data
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 E_menus(self): return E.menus( E.menu(E.url('/private/report/order'), E.text(u"Отчет по заказам")), E.menu(E.url('/private/report/management'), E.text(u"Управленческий учет")), )
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 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 E_data(self): dbconn = self.dbconn payment = dbconn.query(Payment) try: p = dbconn.query(Payment).filter( Payment.payment_id == self.form['payment_id']).one() text = p.text_email.replace('\n', " ").replace("'", '"') except sqlalchemy.orm.exc.NoResultFound: sys.exc_clear() text = u'Реквизиты' data = E.data(E.rich(), text=text) data_tag = data.xpath('//data')[0] for p in payment: data_tag.append( E.payment(payment_id=str(p.payment_id), name=p.name, sale_type=p.sale_type, discription=p.discription)) return data
def E_menus(self): return E.menus( E.menu(E.url(self.path_up), E.text(u"Перейти к меню")), E.menu( E.url("?".join(("/private/develop/urlmap_edit", self.urlencode( (('url_path', self.path_info), ))))), E.text(u"Привязать к данной пути выполнение кода страницы")), )
def E_data(self): dbconn = self.dbconn form = self.form date_begin = form['date_begin'] date_end = form['date_end'] distrib_id = form['distrib_id'] orders_tag = E.orders() data = E.data(orders_tag) limit = 100 if distrib_id == --1: return E.data() ids = set(r[0] for r in dbconn.execute( 'select * from(select * from (select order_id, status_order_id from porder join history_prod using(order_id) order by porder.order_id, history_prod.datetime desc) as c group by order_id ) as d where status_order_id=9' )) query = dbconn.query(Order).filter(not_(Order.order_id.in_(ids))) if date_begin: limit = 0 query = query.filter(Order.datetime >= date_begin) if date_end: limit = 0 query = query.filter(Order.datetime <= date_end) if distrib_id: query = query.filter(Order.order_id == Prod_order.order_id).filter( Prod_order.product_id == Product.product_id).filter( Product.distrib_id == distrib_id) for order in query: res = 0 test = dbconn.query( Prod_order.amount, Prod_order.count, Prod_order.close, Prod_order.sale).filter( Prod_order.order_id == order.order_id ).filter(Prod_order.close == "no").filter( Prod_order.product_id == Product.product_id).filter( Product.distrib_id == distrib_id) for amount, count, close, sale in test: res += float(amount) * float(count) - float(sale) order.amount = float(res) all_amount = 0 query = query.order_by(desc(Order.datetime)) if limit: query = query.limit(limit) count = 0 for order in query: count += 1 all_amount += float(order.amount) orders_tag.append( E.order(datetime=order.datetime.strftime('%Y-%m-%d'), order_id=str(order.order_id), amount=str(order.amount))) orders_tag.append(E.all_amount(str(all_amount))) if limit: str_limit = u"Выведены %s заказов" % str(limit) elif (date_begin or date_end or distrib_id): str_limit = u"Выведены все заказы" data.append(E.limit(limit=str_limit)) data.append(E.count(str(count))) return data