Пример #1
0
def index(mode, **kw):
    host = request.form.get('host') or request.form.get('helperURI') or request.host_url
    debug = request.args.get('debug') == '1' and True or False
    demo(request.args.get('demo'), request=request)

    setReference(host, debug)

    wizard = request.args.get('wizard', 'BillGateDUS120') #'StreetGateDUS210'
    locale = _validate('locale', request.args.get('locale'))

    country = kw.get('country')
    region = kw.get('region')
    user = kw.get('user')
    document = kw.get('document')

    exchange = _make_exchange(mode, locale, country, region, user, document)

    page = _make_page(wizard, locale, init_only=False)

    kw = _make_platform(wizard, locale, user, debug)

    kw['extra'] = { \
        'selected_action' : request.form.get('selected_action') or 'null',
        'selected_item'   : request.form.get('selected_item') or 'null',
    }

    forms = ('index', 'log',)

    keywords = _make_keywords()

    session['communication'] = exchange['communication']
    session['session'] = exchange['sessionID']
    session['security'] = exchange['securityID']
    session['browser'] = kw['browser']
    session['locale'] = locale
    session['wizard'] = wizard
    session['name'] = page and page.get_title(False) or ''

    kw.update({ \
        'title'    : gettext('Helper Configurator Main Page'),
        'host'     : host,
        'wizard'   : wizard,
        'locale'   : locale, 
        'exchange' : exchange, 
        'keywords' : keywords, 
        'forms'    : forms, 
        'page'     : page,
    })

    if IsDebug:
        print '$$$'
        print '%s: %s %s %s %s session:[%s]' % (getTime(), host, wizard, locale, exchange['clientName'], exchange['sessionID'])
        print '%s: %s %s communication:[%s]' % (getTime(), kw['browser'], kw['agent'], exchange['communication'])
        print '%s: %s demo:%s' % (getTime(), kw['platform'], demo())

    return respond(template='index.html', debug=debug, **kw)
Пример #2
0
def log(mode, **kw):
    host = request.form.get('host') or request.form.get('helperURI') or request.host_url
    debug = request.args.get('debug') == '1' and True or False
    demo(request.args.get('demo'), request=request)

    setReference(host, debug)

    mode = request.form.get('helperCommunicationType', session.get('communication'))
    wizard = request.args.get('wizard', request.form.get('wizardID', session.get('wizard')))
    locale = _validate('locale', request.form.get('currentLocale', session.get('locale')))

    country = request.form.get('countryID', n_a)
    region = request.form.get('regionID', n_a)
    user = request.form.get('userID', n_a)

    exchange = _make_exchange(mode, locale, country, region, user=request.form.get('clientName', n_a))
    exchange['wizard'] = wizard

    page = _make_page(wizard, locale, init_only=True)

    kw = _make_platform(wizard, locale, user, debug)

    kw['links']['close'] = re.sub(r'index|log(?i)', '', request.referrer or request.url)

    kw['extra'] = { \
        'log_headers'        : getLogVisibleHeaders(),
        'statistics_headers' : getStatisticsVisibleHeaders(),
        'images'             : getLogImages(),
    }

    forms = ('load', 'search',)

    keywords = _make_keywords()

    kw.update({ \
        'title'    : gettext('Helper Configurator Order Log Page'),
        'host'     : host,
        'wizard'   : wizard,
        'locale'   : locale, 
        'exchange' : exchange, 
        'keywords' : keywords, 
        'forms'    : forms, 
        'page'     : page,
    })

    return respond('log.html', debug, **kw)
Пример #3
0
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)