def _on_get(self, req, resp, **kwargs): page = req.get_param('page') or 0 if not valid_int(page, False): page = 0 limit = settings.ORDERS_COUNT_PER_PAGE orders = data_access(REMOTE_API_NAME.GET_ORDERS, req, resp, brand_id=settings.BRAND_ID, limit=limit, page=page) order_list = [] for order in orders: for order_id, order_data in order.iteritems(): order_info = get_order_table_info(order_id, order_data) if order_info: order_list.append(order_info) prev_page_url = next_page_url = "" if int(page) > 0: prev_page_url = "%s?page=%s" % (get_url_format( FRT_ROUTE_ROLE.ORDER_LIST), int(page) - 1) if len(order_list) > limit: next_page_url = "%s?page=%s" % (get_url_format( FRT_ROUTE_ROLE.ORDER_LIST), int(page) + 1) data = { 'user_name': order_list[0]['user_name'] if order_list else '', 'order_list': order_list[:limit], 'prev_page_url': prev_page_url, 'next_page_url': next_page_url, } return data
def _add_common_data(self, resp_dict): resp_dict['users_id'] = self.users_id resp_dict['tabs'] = copy.deepcopy(self.tabs) resp_dict['cur_tab_index'] = self.cur_tab_index if self.cur_tab_index >= 0: resp_dict['tabs'][self.cur_tab_index]['current'] = True resp_dict['css_loader'] = get_loader_css(settings.BRAND_NAME.lower()) resp_dict['js_loader'] = get_loader_js(settings.BRAND_NAME.lower()) resp_dict['js_defer_loader'] = get_loader_js( settings.BRAND_NAME.lower(), True) if 'err' not in resp_dict: resp_dict['err'] = '' resp_dict['err'] = get_err_msg(resp_dict['err']) resp_dict['as_list'] = as_list resp_dict['countdown_time'] = countdown_time resp_dict['refresh_time'] = refresh_time resp_dict['cur_symbol'] = cur_symbol resp_dict['format_amount'] = format_amount resp_dict['format_datetime'] = format_datetime resp_dict['get_thumbnail'] = get_thumbnail resp_dict['zero'] = zero resp_dict.update({ 'auth_url_format': get_url_format(FRT_ROUTE_ROLE.USER_AUTH), 'logout_url_format': get_url_format(FRT_ROUTE_ROLE.USER_LOGOUT), 'reset_pwd_req_url_format': get_url_format(FRT_ROUTE_ROLE.RESET_PWD_REQ), 'user_url_format': get_url_format(FRT_ROUTE_ROLE.USER_INFO), 'my_account_url_format': get_url_format(FRT_ROUTE_ROLE.MY_ACCOUNT), })
def _on_get(self, req, resp, **kwargs): set_cookie(resp, USER_AUTH_COOKIE_NAME, "") redirect_to = get_url_format(FRT_ROUTE_ROLE.USER_AUTH) if 'referer' in req.headers: redirect_to = req.headers['referer'] self.redirect(redirect_to) return
def _on_post(self, req, resp, **kwargs): email = req.get_param('email') key = req.get_param('key') password = req.get_param('password') password2 = req.get_param('password2') err = '' if not key or not is_valid_email(email): err = 'INVALID_REQUEST' elif not password or password != password2: err = 'ERR_PASSWORD' data = {'email': email, 'key': key} if err: data['err'] = err return data else: remote_resp = data_access(REMOTE_API_NAME.SET_USERINFO, req, resp, action="passwd", email=email, key=key, password=password) if remote_resp.get('res') == RESP_RESULT.F: data['err'] = remote_resp.get('err') return data else: self.redirect(get_url_format(FRT_ROUTE_ROLE.USER_AUTH)) return
def get_payment_url(id_order, id_invoices): url = get_url_format(FRT_ROUTE_ROLE.PAYMENT) url += "?%s" % urllib.urlencode({ 'id_order': id_order, 'id_invoices': ujson.dumps(id_invoices) }) return url
def _on_get(self, req, resp, **kwargs): data = super(OrderAuthResource, self)._on_get(req, resp, **kwargs) data['succ_redirect_to'] = get_url_format(FRT_ROUTE_ROLE.ORDER_ADDR) basket_key, basket_data = get_basket(req, resp) if basket_key and basket_data \ and basket_key != get_cookie_value(req, CURR_USER_BASKET_COOKIE_NAME): set_cookie(resp, CURR_USER_BASKET_COOKIE_NAME, basket_key) return data
def _on_get(self, req, resp, **kwargs): is_routed = is_routed_template(self.role) type_id = kwargs.get('id_type') if not type_id: raise ValidationError('ERR_ID') type_name = '' if is_routed: type_name = kwargs.get('type_name') if not type_name: raise ValidationError('ERR_NAME') req._params['type'] = type_id sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp, **req._params) if is_routed: type_info = get_type_from_sale(sales and sales.values()[0] or {}) normalized_type_name = get_normalized_name( FRT_ROUTE_ROLE.TYPE_LIST, 'type_name', type_info['name']) if type(normalized_type_name) == unicode: normalized_type_name = normalized_type_name.encode('UTF-8') if normalized_type_name != type_name: self.redirect( get_url_format(FRT_ROUTE_ROLE.TYPE_LIST) % { 'id_type': type_id, 'type_name': normalized_type_name }) return return { 'cur_type_id': type_id, 'category': get_category_from_sales(sales), 'product_list': get_brief_product_list(sales, req, resp, self.users_id) }
def _on_get(self, req, resp, **kwargs): is_routed = is_routed_template(self.role) sale_id = kwargs.get('id_sale') if not sale_id: raise ValidationError('ERR_ID') sale_name = type_id = type_name = None if is_routed: sale_name = kwargs.get('sale_name') if not sale_name: raise ValidationError('ERR_Name') type_id = kwargs.get('id_type') if not type_id: raise ValidationError('ERR_ID') type_name = kwargs.get('type_name') if not type_name: raise ValidationError('ERR_NAME') # all sales all_sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp) if not all_sales or sale_id not in all_sales: raise ValidationError('ERR_ID') product_info = all_sales[sale_id] product_info['desc'] = product_info.get('desc', '').split('\n') if is_routed: type_info = get_type_from_sale(product_info) normalized_type_name = get_normalized_name( FRT_ROUTE_ROLE.PRDT_INFO, 'type_name', type_info['name']) normalized_sale_name = get_normalized_name( FRT_ROUTE_ROLE.PRDT_INFO, 'sale_name', product_info.get('name', '')) if type(normalized_type_name) is unicode: normalized_type_name = normalized_type_name.encode('UTF-8') if type(normalized_sale_name) is unicode: normalized_sale_name = normalized_sale_name.encode('UTF-8') if normalized_type_name != type_name or \ normalized_sale_name != sale_name: self.redirect( get_url_format(FRT_ROUTE_ROLE.PRDT_INFO) % { 'id_type': type_id, 'type_name': normalized_type_name, 'id_sale': sale_id, 'sale_name': normalized_sale_name, }) return # product info if not settings.PRODUCTION and not product_info.get('img'): product_info['img'] = '/img/dollar-example.jpg' product_info['variant'] = as_list(product_info.get('variant')) # price product_info['display'] = dict() ori_price, price = get_product_default_display_price(product_info) product_info['display']['price'] = price product_info['display']['ori_price'] = ori_price ## if it uses type attribute price, disable the type attribute ## which has no price. type_attrs = as_list(product_info.get('type', {}).get('attribute')) if 'type' in product_info: product_info['type']['attribute'] = type_attrs unified_price = product_info.get('price', {}).get('#text') if not unified_price: for type_attr in type_attrs: if (not 'price' in type_attr or not float(type_attr['price'].get('#text', 0))): type_attr['disabled'] = True ## Disable the type attribute which has no quantity. stocks = as_list(product_info.get('available', {}).get('stocks')) if 'available' in product_info: product_info['available']['stocks'] = stocks for stock in stocks: stock['stock'] = as_list(stock.get('stock')) for type_attr in type_attrs: stock = sum([ sum(int(ss.get('#text', 0)) for ss in x.get('stock')) for x in stocks if x.get('@attribute') == type_attr.get('@id') ]) if stock <= 0: type_attr['disabled'] = True ## Disable the brand attribute which has no quantity. variants = as_list(product_info.get('variant')) product_info['variant'] = variants for var in variants: stock = sum([ sum(int(ss.get('#text', 0)) for ss in x.get('stock')) for x in stocks if x.get('@variant') == var.get('@id') ]) if stock <= 0: var['disabled'] = True taxes_rate = {} _cate_id = product_info.get('category', {}).get('@id', 0) shops = dict([(node['@id'], node) for node in as_list(product_info.get('shop'))]) shops.update({"0": product_info.get('brand', {})}) show_final_price = False for _id, node in shops.iteritems(): addr = node.get('address', {}).get('country') if addr and addr.get("#text"): country_code = addr["#text"] province_code = addr.get("@province") user_country_code, user_province_code = \ user_country_province(req, resp, self.users_id) is_business_account = \ user_is_business_account(req, resp, self.users_id) category_tax_info = get_category_tax_info( req, resp, country_code, province_code, user_country_code, user_province_code, _cate_id, is_business_account) taxes_rate[_id] = category_tax_info['rate'] show_final_price = category_tax_info['show_final_price'] return { 'cur_type_id': type_id, 'product_info': product_info, 'product_list': get_random_products(all_sales, req, resp, self.users_id), 'taxes_rate': taxes_rate, 'show_final_price': show_final_price, }
def _on_get(self, req, resp, **kwargs): return {'succ_redirect_to': get_url_format(FRT_ROUTE_ROLE.MY_ACCOUNT)}
def _get_user_info(self, req, resp): remote_resp = data_access(REMOTE_API_NAME.GET_USERINFO, req, resp) err = req.get_param('err') or '' user_profile = {} if remote_resp.get('res') == RESP_RESULT.F: err = remote_resp.get('err') first_time = False else: user_profile = remote_resp first_time = not user_profile['general']['values'][0].get('first_name') # translate name for fs_name, fs in user_profile.iteritems(): if 'name' in fs: fs['name'] = _(fs['name']) if 'fields' in fs: for f_name, f in fs['fields']: f['name'] = _(f['name']) if f['type'] == 'radio': f['accept'] = [[_(n), v] for n, v in f['accept']] # filter country list white_countries = allowed_countries() if white_countries: for f_name, f in user_profile['phone']['fields']: if f_name == 'country_num': f['accept'] = filter(lambda x:x[1] in white_countries, f['accept']) set_default_addr_country = not all( int(addr['id']) for addr in user_profile['address']['values']) set_default_phone_country = not all( int(p['id']) for p in user_profile['phone']['values']) if set_default_addr_country or set_default_phone_country: geolocation = get_location_by_ip(get_client_ip(req)) # give geolocation country calling code if no values if set_default_phone_country: for p in user_profile['phone']['values']: if not int(p['id']): country_code = geolocation['country']['iso_code'] p['country_num'] = unicode2utf8(country_code) # give geolocation country/province if no address values. if set_default_addr_country: for address in user_profile['address']['values']: if not int(address['id']): country_code = geolocation['country']['iso_code'] province_name = geolocation['subdivision']['name'] if country_code and province_name: remote_resp = data_access(REMOTE_API_NAME.AUX, req, resp, get='province_code', ccode=country_code, pname=province_name) address['country_code'] = unicode2utf8(country_code) if remote_resp and isinstance(remote_resp, str) \ and RESP_RESULT.F not in remote_resp: address['province_code'] = unicode2utf8(remote_resp) return {'user_profile': user_profile, 'err': err, 'succ_redirect_to': get_url_format(FRT_ROUTE_ROLE.MY_ACCOUNT), 'first_time': first_time, 'id_order': req.get_param('id_order') or ''}
def _add_common_data(self, resp_dict): resp_dict['users_id'] = self.users_id resp_dict['tabs'] = copy.deepcopy(self.tabs) resp_dict['cur_tab_index'] = self.cur_tab_index if self.cur_tab_index >= 0: resp_dict['tabs'][self.cur_tab_index]['current'] = True if self.cur_tab_index != 0: self.show_products_menu = False resp_dict['show_products_menu'] = self.show_products_menu resp_dict['css_loader'] = get_loader_css(settings.BRAND_NAME.lower()) resp_dict['js_loader'] = get_loader_js(settings.BRAND_NAME.lower()) resp_dict['js_defer_loader'] = get_loader_js(settings.BRAND_NAME.lower(), True) if self.show_products_menu: # navigation menu remote_resp = data_access(REMOTE_API_NAME.GET_TYPES, seller=settings.BRAND_ID) if remote_resp.get('res') == RESP_RESULT.F: resp_dict['err'] = remote_resp.get('err') else: resp_dict['menus'] = remote_resp.values() for v in resp_dict['menus']: v['url_name'] = get_normalized_name( FRT_ROUTE_ROLE.TYPE_LIST, 'type_name', v['name']) resp_dict['menus'].sort(cmp= lambda x, y: cmp(int(x.get('sort_order') or 0), int(y.get('sort_order') or 0))) if 'cur_type_id' not in resp_dict: resp_dict['cur_type_id'] = -1 if 'err' not in resp_dict: resp_dict['err'] = '' resp_dict['err'] = get_err_msg(resp_dict['err']) resp_dict['route_args'] = self.route_args need_calc_before_tax = calc_before_tax_price(self.request, self.response) resp_dict['calc_before_tax_price'] = need_calc_before_tax resp_dict['price_label'] = get_price_label(need_calc_before_tax) resp_dict['format_datetime'] = format_datetime resp_dict['as_list'] = as_list resp_dict['get_single_attribute'] = self.get_single_attribute resp_dict['format_amount'] = format_amount resp_dict['zero'] = zero resp_dict['cur_symbol'] = cur_symbol resp_dict['get_thumbnail'] = get_thumbnail resp_dict['basket_qty'] = self._add_basket_quantity() resp_dict.update({ 'prodlist_url_format': get_url_format(FRT_ROUTE_ROLE.PRDT_LIST), 'auth_url_format': get_url_format(FRT_ROUTE_ROLE.USER_AUTH), 'logout_url_format': get_url_format(FRT_ROUTE_ROLE.USER_LOGOUT), 'reset_pwd_req_url_format': get_url_format(FRT_ROUTE_ROLE.RESET_PWD_REQ), 'user_url_format': get_url_format(FRT_ROUTE_ROLE.USER_INFO), 'my_account_url_format': get_url_format(FRT_ROUTE_ROLE.MY_ACCOUNT), 'basket_url_format': get_url_format(FRT_ROUTE_ROLE.BASKET), 'order_auth_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_AUTH), 'order_user_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_USER), 'order_addr_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_ADDR), 'order_info_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_INFO), 'order_invoice_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_INVOICES), 'order_list_url_format': get_url_format(FRT_ROUTE_ROLE.ORDER_LIST), 'type_list_url_format': get_url_format(FRT_ROUTE_ROLE.TYPE_LIST), })
def get_auth_url(self): return get_url_format(FRT_ROUTE_ROLE.USER_AUTH)
def _on_get(self, req, resp, **kwargs): return self.redirect(get_url_format(FRT_ROUTE_ROLE.ORDER_LIST))
def _on_post(self, req, resp, **kwargs): if not valid_int_param(req, 'id_phone') \ or not valid_int_param(req, 'id_shipaddr') \ or not valid_int_param(req, 'id_billaddr'): redirect_to = get_url_format(FRT_ROUTE_ROLE.ORDER_USER) return {'redirect_to': redirect_to} if req.get_param_as_int('id_order'): basket_key = None basket_data = None data = { 'action': 'modify', 'id_order': req.get_param_as_int('id_order'), 'telephone': req.get_param('id_phone'), 'shipaddr': req.get_param('id_shipaddr'), 'billaddr': req.get_param('id_billaddr'), } else: all_sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp) orders = [] basket_key, basket_data = get_basket(req, resp) is_unique = use_unique_items(req, resp) for item, quantity in basket_data.iteritems(): try: item_info = ujson.loads(item) except: continue id_sale = item_info['id_sale'] if id_sale not in all_sales: continue orders.append({ 'id_sale': item_info['id_sale'], 'id_shop': item_info.get('id_shop'), 'quantity': 1 if is_unique else quantity, 'id_variant': item_info.get('id_variant') or 0, 'id_type': item_info.get('id_attr') or 0, 'id_weight_type': item_info.get('id_weight_type') or 0, 'id_price_type': item_info.get('id_price_type') or 0, }) data = { 'action': 'create', 'telephone': req.get_param('id_phone'), 'shipaddr': req.get_param('id_shipaddr'), 'billaddr': req.get_param('id_billaddr'), 'wwwOrder': ujson.dumps(orders), } if req.get_param('gifts'): data.update({'gifts': req.get_param('gifts')}) order_resp = data_access(REMOTE_API_NAME.CREATE_ORDER, req, resp, **data) if order_resp.get('res') == RESP_RESULT.F: errmsg = order_resp['err'] redirect_url = get_url_format(FRT_ROUTE_ROLE.BASKET) query = {} if errmsg.startswith('COUPON_ERR_GIFTS_'): query['params'] = ujson.dumps(order_resp['params']) elif 'OUT_OF_STOCK' in errmsg: errmsg = errmsg[errmsg.index('OUT_OF_STOCK'):] else: errmsg = 'FAILED_PLACE_ORDER' query['err'] = errmsg redirect_to = "%s?%s" % (redirect_url, urllib.urlencode(query)) else: if basket_key and basket_data: clear_basket(req, resp, basket_key, basket_data) id_order = order_resp['id'] redirect_to = get_url_format(FRT_ROUTE_ROLE.ORDER_INFO) % { 'id_order': id_order } try: _req_invoices(req, resp, id_order) invoice_info, id_invoices = _get_invoices(req, resp, id_order) if settings.BRAND_NAME == "BREUER": redirect_to = get_payment_url(id_order, id_invoices) except Exception, e: pass
def _on_get(self, req, resp, **kwargs): data = super(OrderUserResource, self)._on_get(req, resp, **kwargs) data['succ_redirect_to'] = get_url_format(FRT_ROUTE_ROLE.ORDER_ADDR) data['id_order'] = req.get_param('id_order') or '' return data