コード例 #1
0
ファイル: views.py プロジェクト: ichar/player.python
def _make_exchange(mode, locale, country, region, user, document=None):
    return { \
        'communication' : request.form.get('helperCommunicationType', mode) or default_communication,
        'sessionID'     : data_encode(request.form.get('sessionID') or ''),
        'securityID'    : data_encode(request.form.get('securityID') or ''),
        'userID'        : getUserID(request.form.get('userID')),
        'userTypeID'    : request.form.get('userTypeID', ''),
        'userLogin'     : request.form.get('userLogin', ''),
        'userPswd'      : request.form.get('userPswd', ''),
        'httpHost'      : request.form.get('httpHost', ''),
        'webResource'   : request.form.get('webResource', ''),
        'documentID'    : document or n_a,
        'countryID'     : country or n_a,
        'regionID'      : region or n_a,
        'WebServiceURL' : request.form.get('WebServiceURL', ''),
        'currencyID'    : request.form.get('currencyID', ''),
        'priceTypeID'   : request.form.get('priceTypeID', ''),
        'countryName'   : request.form.get('countryName') or getCountry(country),
        'regionName'    : request.form.get('regionName') or getRegion(region),
        'clientName'    : getClient(user, locale),
    }
コード例 #2
0
ファイル: views.py プロジェクト: ichar/player.python
def respond_external(action, **kw):
    exchange_error = 0
    exchange_message = ''
    error_code = ''
    error_description = ''
    errors = ''
    response = {}
    dom = None
    data = ''
    total = ''
    price = ''
    currency = ''
    document = ''
    order_number = ''
    order_date = ''

    print_action(action, 'Respond.External')

    locale = request.form.get('currentUsedLocalization') or ''
    wizard = request.form.get('wizardID') or ''

    try:
        # -------------------------------------
        # Get DOM and XML response from Service
        # -------------------------------------
        exchange_error, exchange_message, dom, data = send(action, request, session, **kw)

        if demo():
            exchange_error, exchange_message, total, currency = _demo_price(action)
            order_number, order_date = _demo_order(action)
        elif exchange_error:
            total = 0.0
        elif dom is not None:
            total = float(getDOMItemValue(dom, 'total') or '0')
            currency = CURRENCIES.get(getDOMItemValue(dom, 'currency'), gettext('undefined'))
            error_code = getDOMItemValue(dom, 'errorCode').strip()
            error_description = getDOMItemValue(dom, 'errorDescription')

            if action == '207':
                order = _order(dom)
                order_number = order.get('number', '')
                order_date = order.get('date', '')
        elif data:
            x = request.form.get('price')
            total = x and float(x.split()[0])*1.288726 or 0
    except:
        msg = '--> Send error!'
        print_to(errorlog, [msg, data], request=request)
        # ----------------------
        # Service Exchange Error
        # ----------------------
        if IsDeepDebug:
            print msg
        raise

    #print_to(errorlog, ['>>> Data:', data])

    IsValid = data and True or False

    if exchange_message and exchange_message == exchange_error:
        exchange_message = ''
    if error_description and error_description == error_code:
        error_description = ''

    # -----------------
    # Response is valid
    # -----------------

    if IsValid:
        errors = getDOMErrors(dom) or ''

        if IsDeepDebug:
            print errors

        if currency in ('undefined', n_a, '') or not total:
            if not exchange_message:
                if action == '203' and error_code in ('', '0',):
                    pass
                else:
                    exchange_message = gettext('Calculation is not performed.')
            IsValid = False

        total = IsValid and '%.2f' % total or ''
        price = IsValid and '%s %s' % (total, currency) or ''

        if IsDebug:
            print '--> Total: %s' % price

        document = order_number and ('# %s %s %s' % (order_number, gettext('at'), order_date)) or ''

    # -------------------------------------------
    # Make parameters and Register response in DB
    # -------------------------------------------

    attrs = { \
        'locale'            : locale,
        'selected_item'     : kw.get('id') or request.form.get('selected_item'),
        'title'             : request.form.get('title') or '',
        'document'          : document or action,
        'total'             : total,
        'currency'          : currency,
        'countryID'         : getCountryID(getDOMItemValue(dom, 'countryID'), locale),
        'regionID'          : getRegionID(getDOMItemValue(dom, 'regionID'), locale),
        'userID'            : getUserID(getDOMItemValue(dom, 'userID'), locale),
        'userName'          : getClient(getDOMItemValue(dom, 'userName'), locale),
        'wizardID'          : wizard,
        'wizardName'        : request.form.get('wizardName') or '',
        'custom_code'       : request.form.get('custom_code') or '',
        'option_update'     : request.form.get('option_update') or '',
        'option_cost'       : request.form.get('option_cost') or '',
        'data'              : data, #getDOMTagStrippedValue(dom, 'parameters'),
    }

    #print_to(errorlog, ['>>> Total:', total])

    if IsValid and action in ('203','204','205','207',): # and dom
        response = register(action, dom, attrs)

        if IsDeepDebug:
            print '>>> DB Response:%s' % response

    order = action == '205' and response.get('custom_code') or document

    return { \
        'action'            : action,
        'op'                : '',
        # --------------
        # Service Errors
        # --------------
        'exchange_error'    : exchange_error, 
        'exchange_message'  : exchange_message,
        'error_code'        : error_code,
        'error_description' : error_description,
        'errors'            : errors,
        # ---
        # IDs
        # ---
        'countryID'         : getDOMItemValue(dom, 'countryID') or '',
        'regionID'          : getDOMItemValue(dom, 'regionID') or '',
        'userID'            : attrs['userID'],
        # --------------
        # Client Details
        # --------------
        'country_name'      : getDOMItemValue(dom, 'countryName') or getCountry(getDOMItemValue(dom, 'countryID'), locale),
        'region_name'       : getDOMItemValue(dom, 'regionName') or getRegion(getDOMItemValue(dom, 'regionID'), locale),
        'client_name'       : attrs['userName'],
        # ----------
        # Order Info
        # ----------
        'document_number'   : order_number,
        'document_date'     : order_date,
        'order'             : order,
        # -------
        # DB Data
        # -------
        'total_log_rows'    : getLogTotal({'userID' : attrs['userID'], 'wizardID' : wizard}),
        'custom_code'       : response.get('custom_code', ''),
        'next_custom_code'  : response.get('next_custom_code', ''),
        'option_update'     : response.get('option_update', ''),
        'option_cost'       : response.get('option_cost', ''),
        'title'             : response.get('title', ''),
        # ------------------------------
        # Results (Price & XML-Response)
        # ------------------------------
        'price'             : price,
        'data'              : data,
    }
コード例 #3
0
ファイル: views.py プロジェクト: ichar/player.python
def respond_internal(action, **kw):
    exchange_error = 0
    exchange_message = ''
    error_code = ''
    error_description = ''
    response = {}
    dom = None
    data = ''
    currency = ''
    order_number = ''
    order_date = ''

    print_action(action, 'Respond.Internal')

    op = request.form.get('op') or kw.get('op')

    if IsDebug:
        print '--> op: [%s]' % op

    if not op:
        pass

    elif op == 'get':
        # --------------------------------------------------------------
        # Generate and Send XML to Service (from WEB-form to JavaScript)
        # --------------------------------------------------------------
        data = getXml(action, request, session)
        errors = []

    elif op == 'set':
        # -----------------------------------------------
        # Receive XML from Service (loaded by JavaScript)
        # -----------------------------------------------
        dom, data = receive(action, request, session, **kw)

        if demo():
            exchange_error, exchange_message, total, currency = _demo_price(action)
            order_number, order_date = _demo_order(action)
        else:
            total = float(getDOMItemValue(dom, 'total'))
            currency = CURRENCIES.get(getDOMItemValue(dom, 'currency'), gettext('undefined'))
            error_code = getDOMItemValue(dom, 'errorCode').strip()
            error_description = getDOMItemValue(dom, 'errorDescription')

        errors = getDOMErrors(dom) or ''

        if IsDebug:
            print '--> Total: %s %s' % (total, currency)

        total = '%.2f' % total or ''
        price = '%s %s' % (total, currency) or ''

    return { \
        'action'            : action,
        'op'                : op,
        # --------------
        # Service Errors
        # --------------
        'exchange_error'    : exchange_error, 
        'exchange_message'  : exchange_message,
        'error_code'        : error_code,
        'error_description' : error_description,
        'errors'            : errors,
        # ---
        # IDs
        # ---
        'countryID'         : getDOMItemValue(dom, 'countryID') or '',
        'regionID'          : getDOMItemValue(dom, 'regionID') or '',
        'userID'            : getUserID(getDOMItemValue(dom, 'userID')),
        # --------------
        # Client Details
        # --------------
        'country_name'      : getDOMItemValue(dom, 'countryName') or getCountry(getDOMItemValue(dom, 'countryID')),
        'region_name'       : getDOMItemValue(dom, 'regionName') or getRegion(getDOMItemValue(dom, 'regionID')),
        'client_name'       : getClient(getDOMItemValue(dom, 'userName')),
        # ------------------------------
        # Results (Price & XML-Response)
        # ------------------------------
        'price'             : price,
        'data'              : data,
    }