def get_shipping_info(req, resp, order_id): from common.data_access import data_access xml_resp = data_access(REMOTE_API_NAME.GET_SHIPPING_LIST, req, resp, id_order=order_id) shipments = xmltodict.parse(xml_resp)['shipments'] shipment_info = {} need_select_carrier = False for shipment in as_list(shipments['shipment']): method = int(shipment['@method']) if method == SCM.CARRIER_SHIPPING_RATE: if not shipment['delivery'].get('@postage'): xml_resp = data_access(REMOTE_API_NAME.GET_SHIPPING_FEE, req, resp, shipment=shipment['@id']) carriers = xmltodict.parse(xml_resp)['carriers'] shipment['delivery'].update({'carrier': carriers['carrier']}) need_select_carrier = True else: pass shipment['delivery'].update({'carrier': as_list(shipment['delivery'].get('carrier'))}) for car in shipment['delivery']['carrier']: car['service'] = as_list(car['service']) shipment['item'] = as_list(shipment['item']) shipment['@method'] = SCM.toReverseDict().get(int(shipment['@method'])) shipment_info[shipment['@id']] = shipment data = { 'order_id': order_id, 'order_created': format_date(shipments['@order_create_date']), 'shipments_detail': shipment_info, 'need_select_carrier': need_select_carrier, } return data
def _on_get(self, req, resp, **kwargs): user_info = data_access(REMOTE_API_NAME.GET_USERINFO, req, resp) general_user_values = user_info['general']['values'][0] if not general_user_values.get('first_name') \ or not general_user_values.get('last_name'): user_name = general_user_values['email'] else: user_name = '%s %s %s' % ( general_user_values.get('title') or '', general_user_values.get('first_name') or '', general_user_values.get('last_name') or '', ) limit = settings.ORDERS_COUNT_IN_MY_ACCOUNT orders = data_access(REMOTE_API_NAME.GET_ORDERS, req, resp, brand_id=settings.BRAND_ID, limit=limit) 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) data = {'user_name': user_name, 'user_info': general_user_values, 'order_list': order_list[:limit]} data.update(get_user_contact_info(user_info)) return data
def _payment_form(self, req, resp, **kwargs): id_trans = req.get_param('id_trans') or kwargs.get('id_trans') processor = req.get_param('processor') or kwargs.get('processor') id_order = req.get_param('id_order') or kwargs.get('id_order') form = None if int(processor) in PAYMENT_TYPES.toReverseDict(): trans = {'id_trans': id_trans} query = {'transaction': id_trans} if int(processor) == PAYMENT_TYPES.PAYPAL: query.update({ 'processor': processor, 'success': settings.PP_SUCCESS % trans, 'failure': settings.PP_FAILURE % trans, }) if int(processor) == PAYMENT_TYPES.PAYBOX: query.update({ 'processor': processor, 'success': settings.PB_SUCCESS % trans, 'failure': settings.PB_ERROR % trans, 'cancel': settings.PB_CANCEL % trans, 'waiting': settings.PB_WAITING % trans, }) if int(processor) == PAYMENT_TYPES.STRIPE: query.update({ 'processor': processor, 'success': settings.SP_SUCCESS % trans, 'failure': settings.SP_FAILURE % trans, }) form_resp = data_access(REMOTE_API_NAME.PAYMENT_FORM, req, resp, **query) form = form_resp.get('form') if not form: form = '<div class="errwrapper">NOT_SUPPORTED</div>' data = { 'step': 'form', 'form': form, 'order_id': id_order, 'processor': processor } all_sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp) order_resp = data_access(REMOTE_API_NAME.GET_ORDER_DETAIL, req, resp, id=id_order, brand_id=settings.BRAND_ID) order_data = get_order_table_info(id_order, order_resp, all_sales) data.update(order_data) return data
def _on_post(self, req, resp, **kwargs): params_list = [] for p in req._params: if p.startswith("carrier_service_"): shipment_id = p.split('_')[-1] carrier_id, service_id = req._params[p].split('_') params_list.append({ 'shipment': shipment_id, 'carrier': carrier_id, 'service': service_id, }) for params in params_list: data_access(REMOTE_API_NAME.SET_SHIPPING_CONF, req, resp, **params) _req_invoices(req, resp, req.get_param('id_order')) return {}
def _on_get(self, req, resp, **kwargs): _, basket_data = get_basket(req, resp) sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp, **req._params) err = req.get_param('err') or '' max_selection = 0 if err.startswith('COUPON_ERR_GIFTS_'): html_parser = HTMLParser.HTMLParser() params = ujson.loads(html_parser.unescape(req.get_param('params'))) max_selection = params['max_selection'] gifts = dict([(ujson.dumps({ 'id_sale': id_sale, 'id_shop': 0, 'id_attr': 0, 'id_variant': 0, 'id_price_type': 0, }), quantity) for id_sale, quantity in params['gifts_available']]) else: gifts = {} return { 'basket': get_basket_table_info(req, resp, basket_data, self.users_id), 'gifts': get_basket_table_info(req, resp, gifts, self.users_id), 'max_selection': max_selection, 'err': err, }
def get_category_tax_info(req, resp, from_country_code, from_province_code, to_country_code, to_province_code, category_id, is_business_account): from common.data_access import data_access taxes = data_access(REMOTE_API_NAME.GET_TAXES, req, resp, fromCountry=from_country_code, fromProvince=from_province_code, toCountry=to_country_code, toProvince=to_province_code, category=category_id) rate = 0 show_final_price = False for t in taxes.itervalues(): if (is_business_account and t.get('applies_to_personal_accounts') == 'True' or not is_business_account and t.get('applies_to_business_accounts') == 'True'): continue rate = float(t['rate']) show_final_price = t.get('display_on_front') == 'True' break return {'rate': rate, 'show_final_price': show_final_price}
def _on_post(self, req, resp, **kwargs): # combine birthday fields if req.get_param('birthday0'): req._params['birthday'] = '%s-%02d-%02d' % ( req.get_param('birthday0'), int(req.get_param('birthday1') or 1), int(req.get_param('birthday2') or 1)) # check country white_countries = allowed_countries() if white_countries: for p in req._params: if p.startswith('country_code_') \ or p.startswith('country_num_'): if req.get_param(p) not in white_countries: raise ValidationError('ERR_EU_COUNTRY') remote_resp = data_access(REMOTE_API_NAME.SET_USERINFO, req, resp, action="modify", **req._params) resp_dict = {} resp_dict.update(remote_resp) if resp_dict.get('res') == RESP_RESULT.F: resp_dict['err'] = _(resp_dict['err']) else: if req.get_param('first_time') == 'True': # send email email_data = {'name': req.get_param('first_name')} email_data.update(common_email_data) gevent.spawn(send_new_user_email, req.get_param('email'), email_data) return resp_dict
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 _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_invoices(req, resp, id_order): invoices = data_access(REMOTE_API_NAME.GET_INVOICES, req, resp, order=id_order, brand=settings.BRAND_ID) id_invoices = _get_invoice_ids(invoices) return invoices, id_invoices
def _on_get(self, req, resp, **kwargs): order_id = kwargs.get('id_order') if not order_id: raise ValidationError('ERR_ID') remote_resp = data_access(REMOTE_API_NAME.GET_INVOICES, req, resp, order=order_id, brand=settings.BRAND_ID) return {'obj': remote_resp, 'order_id': order_id}
def _on_get(self, req, resp, **kwargs): sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp, **req._params) return { 'category': dict(), 'product_list': get_random_products(sales, req, resp, self.users_id) }
def _on_get(self, req, resp, **kwargs): name = req.get_param('name') if not name: remote_resp = data_access(REMOTE_API_NAME.GET_USERINFO, req, resp) if 'general' in remote_resp: general_values = remote_resp['general']['values'][0] name = general_values.get('first_name') if not name: name = general_values.get('email', '').split('@')[0] return {'name': name}
def _on_get(self, req, resp, **kwargs): id_order = kwargs.get('id_order') if not id_order: raise ValidationError('ERR_ID') all_sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp) order_resp = data_access(REMOTE_API_NAME.GET_ORDER_DETAIL, req, resp, id=id_order, brand_id=settings.BRAND_ID) order_data = get_order_table_info(id_order, order_resp, all_sales) invoice_info = {} payment_url = "" shipping_info = get_shipping_info(req, resp, id_order) if not shipping_info['need_select_carrier']: invoice_info, id_invoices = _get_invoices(req, resp, id_order) if id_invoices: if order_data['order_status'] == ORDER_STATUS.AWAITING_PAYMENT: payment_url = get_payment_url(id_order, id_invoices) else: _req_invoices(req, resp, id_order) invoice_info, id_invoices = _get_invoices(req, resp, id_order) if id_invoices: payment_url = get_payment_url(id_order, id_invoices) if shipping_info['need_select_carrier']: step = "select" elif payment_url: step = "payment" else: step = "view" data = { 'step': step, 'invoice_info': invoice_info, 'payment_url': payment_url, } data.update(order_data) data.update(shipping_info) return data
def _on_post(self, req, resp, **kwargs): action = req.get_param('action') container = req.get_param('container') if action not in ('add', 'delete') or not container: raise ValidationError('INVALID_REQUEST') result = data_access(REMOTE_API_NAME.SET_CONTAINER_REMINDER, req, resp, container=container, action=action) return result
def _on_get(self, req, resp, **kwargs): all_sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp) id_order = kwargs.get('id_order') if id_order: order_resp = data_access(REMOTE_API_NAME.GET_ORDER_DETAIL, req, resp, id=id_order, brand_id=settings.BRAND_ID) order_data = get_order_table_info(id_order, order_resp, all_sales) else: order_data = { 'order_id': 0, 'order_created': '', 'status_name': '', 'user_name': '', 'dest_addr': '', 'shipments': {}, 'order_invoice_url': '', } return order_data
def _get_common_data(self, req, resp, **kwargs): myfleets = [] if self.users_id: result = data_access(REMOTE_API_NAME.GET_USER_FLEET, req, resp) if result.get('res') != RESP_RESULT.F: myfleets = result['objects'] return { 'vessels': [], 'myfleets': myfleets, 'ports': [], 'vessel_input': '', }
def login(req, resp): email = req.get_param('email') password = req.get_param('password') if not email: raise ValidationError('ERR_EMAIL') if not password: raise ValidationError('ERR_PASSWORD') remote_resp = data_access(REMOTE_API_NAME.LOGIN, req, resp, email=email, password=password) return remote_resp
def dragondollar_data(self, req, resp): data = {} slides = data_access(REMOTE_API_NAME.GET_SLIDE_SHOW, req, resp, **req._params) try: data['slides'] = slides.get('slideshow', {}).get('slide', []) except AttributeError: data['slides'] = [] try: with open(settings.DRAGON_FEED_CACHE_PATH, 'r') as f: data['coins'] = ujson.load(f) except IOError: data['coins'] = [] try: remote_resp = data_access(REMOTE_API_NAME.GET_TYPES, seller=settings.BRAND_ID) except: pass return data
def _on_get(self, req, resp, **kwargs): res_name = req.get_param('get') remote_resp = data_access(REMOTE_API_NAME.AUX, req, resp, **req._params) white_countries = allowed_countries() if remote_resp.get('res') != RESP_RESULT.F \ and res_name == 'countries' and white_countries: accept = remote_resp['accept'] remote_resp['accept'] = filter(lambda x: x[1] in white_countries, accept) if 'name' in remote_resp: remote_resp['name'] = _(remote_resp['name']) return remote_resp
def _on_get(self, req, resp, **kwargs): sales = data_access(REMOTE_API_NAME.GET_SALES, req, resp, **req._params) data = { 'product_list': get_brief_product_list(sales, req, resp, self.users_id) } if settings.BRAND_NAME == 'DRAGONDOLLAR': dd_data = self.dragondollar_data(req, resp) data.update(dd_data) return data
def _on_post(self, req, resp, **kwargs): action = req.get_param('action') imo = req.get_param('imo') mmsi = req.get_param('mmsi') if action not in ('add', 'delete') or not imo or not mmsi: raise ValidationError('INVALID_REQUEST') result = data_access(REMOTE_API_NAME.SET_VESSEL_REMINDER, req, resp, imo=imo, mmsi=mmsi, action=action) return result
def search_vessel(req, resp, query, **kwargs): vessels = [] if query.isdigit(): for search_by in ('imo', 'mmsi'): result = data_access(REMOTE_API_NAME.SEARCH_VESSEL, req, resp, search_by=search_by, q=query, **kwargs) if result.get('res') != RESP_RESULT.F: vessels = result['objects'] if len(vessels) > 0: break elif query: result = data_access(REMOTE_API_NAME.SEARCH_VESSEL, req, resp, search_by='name', q=query, **kwargs) if result.get('res') != RESP_RESULT.F: vessels = result['objects'] return vessels
def register(req, resp): email = req.get_param('email') password = req.get_param('password') password2 = req.get_param('password2') if not email: raise ValidationError('ERR_EMAIL') if not password or password != password2: raise ValidationError('ERR_PASSWORD') remote_resp = data_access(REMOTE_API_NAME.REGISTER, req, resp, action="create", email=email, password=password) return remote_resp
def _verify_user_online(self, req, resp, method_name): remote_resp = data_access(REMOTE_API_NAME.ONLINE, req, resp) if remote_resp.get('res') == RESP_RESULT.F: self.users_id = None if self.login_required.get(method_name): raise Redirection(self.get_auth_url(), err=remote_resp.get('err') or '') else: self.users_id = remote_resp['users_id'] # no cache for logged-in users resp.set_header('progma', 'no-cache') resp.set_header('cache-control', 'private, no-store, max-age=0, ' 'no-cache, must-revalidate, post-check=0, pre-check=0') resp.set_header('expires', '0')
def search_port(req, resp, query): ports = [] if query.isdigit(): return ports for search_by in ('locode', 'name'): result = data_access(REMOTE_API_NAME.SEARCH_PORT, req, resp, search_by=search_by, q=query) if result.get('res') != RESP_RESULT.F: ports = result['objects'] if len(ports) > 0: break return ports
def user_is_business_account(req, resp, users_id): is_b_account = False if users_id: from common.data_access import data_access user_info = data_access(REMOTE_API_NAME.GET_USERINFO, req, resp) general_user_values = user_info['general']['values'][0] is_b_account = general_user_values.get('is_business_account', False) else: front_personal_account_allowed = get_adm_settings( 'front_personal_account_allowed', req, resp) == 'True' front_business_account_allowed = get_adm_settings( 'front_business_account_allowed', req, resp) == 'True' if not front_personal_account_allowed and \ front_business_account_allowed: is_b_account = True return is_b_account
def _on_post(self, req, resp, **kwargs): email = req.get_param('email') if not is_valid_email(email): raise ValidationError('ERR_EMAIL') remote_resp = data_access(REMOTE_API_NAME.SET_USERINFO, req, resp, action="passwd", email=email) err = msg = '' if remote_resp.get('res') == RESP_RESULT.F: err = remote_resp.get('err') else: msg = _('The reset password email has been sent to %(email)s') \ % {'email': email} return {'err': err, 'msg': msg}
def _on_post(self, req, resp, **kwargs): imo = req.get_param('imo') mmsi = req.get_param('mmsi') if not imo and not mmsi: raise ValidationError('INVALID_REQUEST') result = data_access(REMOTE_API_NAME.GET_VESSEL_NAVPATH, req, resp, imo=imo, mmsi=mmsi) if result.get('res') != RESP_RESULT.F: positions = [(pos['latitude'], pos['longitude']) for pos in result['object'].get('positions', [])] else: positions = [] return {'positions': positions}
def search_container(req, resp, query): containers = [] if query.isdigit(): search_by = 'bill_of_landing' elif query: search_by = 'container' else: return containers result = data_access(REMOTE_API_NAME.SEARCH_CONTAINER, req, resp, search_by=search_by, q=query) if result.get('res') != RESP_RESULT.F: containers = result['objects'] return containers