def _make_platform(wizard, locale, user, debug=None): agent = request.user_agent browser = agent.browser os = agent.platform root = '%s/' % request.script_root referer = request.form.get('helperHttpReferer') or request.form.get('refererURI') or request.form.get('helperURI') or '' close = request.form.get('closeURI') or request.form.get('refererURI') or request.form.get('helperURI') or '' links = { 'calculate' : '/?wizard=%s&locale=%s' % (wizard, locale), 'cancel' : '/?wizard=%s&locale=%s' % (wizard, locale), 'referer' : referer, 'close' : close, } if IsIE(): version = agent.version.split('.')[0] if version < '6': version = '6' elif IsSeaMonkey(): version = '' else: version = agent.version authorized = isAuthorized(user) css = '%s' % ( \ IsMobile() and (IsChrome() and '.android.' or '.mobile.') or IsIE(10) and '.ie10.' or IsOpera() and '.opera.' or IsFirefox() and '.firefox.' or '.' ) is_default = 1 or os in ('ipad', 'android',) and browser in ('safari', 'chrome',) and 1 or 0 is_frame = not IsMobile() and 1 or 0 platform = '[os:%s, browser:%s (%s), css:%s, %s %s%s%s%s]' % ( \ os, browser, version, css, locale, authorized and ' authorized' or '', is_default and ' default' or ' flex', is_frame and ' frame' or '', debug and ' debug' or '', ) kw = { \ 'agent' : agent.string, 'browser' : browser, 'os' : os, 'root' : root, 'referer' : referer, 'links' : links, 'version' : version, 'authorized' : authorized, 'css' : css, 'is_frame' : is_frame, 'platform' : platform, 'style' : { 'default' : is_default }, 'screen' : request.form.get('screen') or '', 'scale' : request.form.get('scale') or '', } return kw
def loader(): if not request.form.get('wizardID'): return '' host = request.form.get('host') debug = request.args.get('debug') == '1' and True or False demo(request.form.get('demo'), request=request) setReference(host, debug) if IsDebug: start = datetime.datetime.now() print '--> Started at %s' % start.strftime('%H:%M:%S:%f') wizard = request.form.get('wizardID') or session.get('wizard') action = request.form.get('action') or '204' check = request.form.get('check') or '' communication = request.form.get('helperCommunicationType') or default_communication locale = request.form.get('currentUsedLocalization') or session.get('locale') exchange_error = 0 if IsDebug: print '--> action: [%s]' % action print '--> communication: [%s]' % communication print '--> demo: [%s]' % demo() print '--> host: [%s]' % host print '--> wizard: [%s]' % wizard response = {} if not (action and action in valid_action_types): return '' IsChecked = True if not isAuthorized(request.form.get('userID')): exchange_error = -4 exchange_message = gettext('Sorry, you are not authorized.') IsChecked = False if IsChecked and action in ('207','307') and demo() and not _check(wizard, check): exchange_error = -5 exchange_message = gettext('Sorry, the confirmation code is invalid.')+'<br>'+gettext('Please, try more.') IsChecked = False if action in ('301','302','303','304','305','307','308',): if IsChecked: # ------------------------------------------------------------------------------------- # Get Data from DB (XML:data, DOM:dom, parsed XML-Items:items or Log-page content:data) # ------------------------------------------------------------------------------------- response = respond_log(action) if not (response and response.get('data')): pass elif action in ('303','304','307',): requested_action = str(int(action)-100) # -------------------------------------------------- # Get XML (update tags for a new request to Service) # -------------------------------------------------- check, data = getRequestXML(requested_action, request, session, data=response.get('items'), dom=response.get('dom'), title=response.get('title'), page='log', url=host) # ---------------------------------------- # Send request to Service and get response # ---------------------------------------- response = respond_external(requested_action, data=data, id=response.get('id')) response['action'] = action # ------------------------------------------------------------- # Get Data Dictionary (!!!) from response to send to Controller # ------------------------------------------------------------- if action == '303': dom, data = receive(action, request, session, data=response.get('data')) response['data'] = data response['dom'] = None response['items'] = None else: # -------------------------------------- # Remove DOM from response to Controller # -------------------------------------- response['dom'] = None response['items'] = None elif communication == COMMUNICATIONS['external'] or not communication: if IsDebug: print '--> check: [%s] = %s' % (check, IsChecked) if action == '100': # ------------------- # Validate the action # ------------------- if not demo(): response = {'x1' : None, 'x2' : None, 'op' : None} else: response = _set_checker(wizard) elif action in ('203','204','205',): # --------------------------------------------------------------- # Send External request to Service and get response (calculation) # --------------------------------------------------------------- response = respond_external(action) elif action in ('207',) and IsChecked: # --------------------------------------------------------- # Send External request to Service and get response (order) # --------------------------------------------------------- response = respond_external(action) if response: response['data'] = '' elif communication == COMMUNICATIONS['internal']: if action == '100': # ------------------- # Validate the action # ------------------- response = {'x1' : None, 'x2' : None, 'op' : None} elif action in ('203','204','205','206',): # ------------------------------------------------- # Send Internal request to Service and get response # ------------------------------------------------- response = respond_internal(action) if not response: response = { \ 'action' : action, 'op' : '', # ------------------------------- # Not authorized or check invalid # ------------------------------- 'exchange_error' : exchange_error, 'exchange_message' : exchange_message, 'error_code' : '', 'error_description' : '', 'errors' : '', # ----------------- # Results (no data) # ----------------- 'price' : '', 'data' : '', } if IsDebug: finish = datetime.datetime.now() t = finish - start print '--> Finished at %s' % finish.strftime('%H:%M:%S:%f') print '--> Spent time: %s sec' % ((t.seconds*1000000+t.microseconds)/1000000) return jsonify(response)