Ejemplo n.º 1
0
def getStatictics(action, request, session):
    """
        Get Price items from DB by selected log item's ID.

        Arguments:
            action  - 305
            request - form (selected_item)
            session - current session

        Returns:
            exchange_error, exchange_message - exchange error info
            id      - parsed ID of selected_item
            data    - XML (Order.data)
    """
    form = request.form

    print_action(action, 'DBase.GetLogStatistics')

    exchange_message = ''
    exchange_error = 0
    response = None
    order = None

    id = form.get('selected_item', None)

    if IsDebug:
        print '>>> Selected LogItem ID: [%s]' % id

    if id:
        order = Order.get_by_id(id)
    else:
        exchange_message = '%s: <id>' % gettext('Missing argument')
        exchange_error = -10

    total, order_id, data, query = statistics(DEFAULT_LOG_MODE, order=order)

    items = []
    headers = get_statistics_headers()
    line_in_page = 0

    for row in data:
        x = dict(zip(headers[0], row))
        line_in_page += 1

        x['root'] = '%s' % request.script_root
        x['num'] = line_in_page
        x['cdate'] = cdate(x['reg_date'], fmt=LOCAL_EASY_TIMESTAMP)

        for n, column in enumerate(headers[1]):
            x['%s_title' % column['id']] = column['title']

        items.append([x['id'], [ column.has_key('value') and (column['value'] % x) or x[column['id']]
            for n, column in enumerate(headers[1])
                if column.get('visible') ]
        ])

    return (exchange_error, exchange_message, id, total, items)
Ejemplo n.º 2
0
def getLogPage(action, request, session):
    """
        Get Log page from DB by selected number filtered by requested userID and wizardID.

        Arguments:
            action  - 301
            request - form (page, per_page, userID, wizardID)
            session - current session

        Filter by (attrs):
            userID  - user ID
            wizardID- wizard ID
            otype   - order type (Config.valid_order_types)
            context - search context

        Returns:
            exchange_error, exchange_message - exchange error info
            data    - Pagination object from DB models
            items   - page column items
    """
    print_db_state()

    form = request.form

    print_action(action, 'DBase.GetLogPage')

    exchange_message = ''
    exchange_error = 0
    data = None

    page = int(form.get('page', 0)) or 1
    per_page = int(form.get('per_page', 0)) or DEFAULT_PER_PAGE

    sort = form.get('sort') or ''

    userID = form.get('userID', None)
    user = userID and User.query.filter_by(userID=userID).first()

    if IsDebug and userID:
        print '>>> User[%s]: %s' % (userID, user and user.userID == userID and 'OK' or 'invalid!')

    wizardID = form.get('wizardID', None)
    module = wizardID and Module.query.filter_by(wizardID=wizardID).first()

    if IsDebug and wizardID:
        print '>>> Module[%s]: %s' % (wizardID, module and module.wizardID == wizardID and 'OK' or 'invalid!')

    otype = int(form.get('otype', -1))

    if IsDebug and otype in valid_order_types:
        print '>>> Order type[%s]: %s' % (otype, valid_order_names[otype])

    context = form.get('search_context', None)

    if IsDebug and context:
        print '>>> Search context: [%s]' % context

    data = log(DEFAULT_LOG_MODE, page, per_page, user=user, module=module, otype=otype, context=context, check=IsDBCheck, sort=sort)

    items = []
    headers = get_log_headers()
    line_in_page = 0 #(page-1) * per_page

    for row in data.items:
        x = dict(zip(headers[0], row))
        line_in_page += 1

        s = x['document'] or ''
        if s and s.startswith('#'):
            x['document'] = s[1:].strip()

        x['root'] = '%s' % request.script_root
        x['image'] = '%s-16.png' % ( \
            x['rating'] == RATING_UP and 'up' or x['rating'] == RATING_DOWN and 'down' or 
            x['rating'] == RATING_EQUAL and 'equal' or 'undef')
        x['num'] = line_in_page
        x['cdate'] = cdate(x['reg_date'], fmt=LOCAL_EASY_TIMESTAMP)
        x['price'], x['currency'] = x['current_price'].split()
        x['code'] = x['otype'] == ORDER_DONE and x['document'] or x['code']
        x['updatable'] = x['option_update'] and 'updatable' or x['option_cost'] and 'cost' or 'fixed'

        for n, column in enumerate(headers[1]):
            x['%s_title' % column['id']] = column['title']

        items.append([x['id'], [ column.has_key('value') and (column['value'] % x) or x[column['id']]
            for n, column in enumerate(headers[1])
                if column.get('visible') ]
        ])

    return (exchange_error, exchange_message, data, items)