Beispiel #1
0
def copy():
    session['auths'] = session.get('auths') or []
    id = short_url.get_id(request.form.get('result_id'))
    results = load_result(id)
    results['modified'] = time.time()

    result_id = save_result(results, public=True, result_id=False)
    results['result_id'] = short_url.get_code(result_id)
    session['auths'].append(results['result_id'])

    return render_template('results.html', results=results,
        from_igb=is_from_igb(), full_page=request.form.get('load_full'))
Beispiel #2
0
def change_quantity():
    "Should this sent the whole result windo again, or simply update the inventory and total prices?"
    app.logger.debug("Qty Change")
    session['auths'] = session.get('auths') or []
    id = short_url.get_id(request.form.get('result_id'))
    result_id = id
    fit_id = request.form.get('fit_id')
    new_qty = request.form.get('qty')
    results = load_result(id)

    eve_types = collections.OrderedDict()
    fits = collections.OrderedDict()
    for item in results['line_items'].values():
        eve_types[item['typeID']] = EveType(item['typeID']).from_dict(EveType, item)
    for item in results['fits'].values():
        fits[str(item['typeID'])+item['name']] = EveFit(item['typeID']).from_dict(EveFit, item)


    old_qty = fits[fit_id].qty
    fits[fit_id].qty = new_qty
    eve_types[int(fits[fit_id].type_id)].count = int(new_qty)
    #app.logger.debug(fits)

    for item in fits[fit_id].modules:
        item=int(item)
        eve_types[item].count -= int(old_qty)
        eve_types[item].count += int(new_qty)

    # Populate types with pricing data
    populate_market_values(eve_types.values(), region=session['region_id'])

    # calculate the totals
    totals = {'sell': 0, 'buy': 0, 'volume': 0}
    for t in eve_types.values():
        for total_key in ['sell', 'buy', 'volume']:
            totals[total_key] += t.pricing_info['totals'][total_key]

    #sort buy price
    sorted_eve_types = sorted(eve_types.values(), key=lambda k: -k.representative_value())

    sorted_fits            = sorted(fits.values())
    displayable_line_items = collections.OrderedDict()
    display_fits           = collections.OrderedDict()

    for eve_type in sorted_eve_types:
        displayable_line_items[str(eve_type.type_id)] = eve_type.to_dict()
    for fit in sorted_fits:
        fit.modules.sort(key=lambda k: eve_types.get(int(k)).sort_order())
        display_fits[str(fit.id)] = fit.to_dict()

    results = {
        'from_igb': is_from_igb(),
        'totals': totals,
        'bad_line_items': results['bad_line_items'],
        'line_items': displayable_line_items, # dict of inventory
        'fits': display_fits, #dict of fits
        'region_name':  REGIONS[session['region_id']],
        'modified': time.time(),
        'auth_hash': results['auth_hash']
    }

    if len(sorted_eve_types) > 0:
        if session['save'] == 'true':
            result_id = save_result(results, public=True, result_id=result_id)
            results['result_id'] = short_url.get_code(result_id)
            session['auths'].append(results['result_id'])
        else:
            result_id = save_result(results, public=False, result_id=result_id)


    results.pop('auth_hash', None)
    return render_template('results.html', results=results,
        from_igb=is_from_igb(), full_page=request.form.get('load_full'))
Beispiel #3
0
def submit():
    "Main function. So direty work of submission and returns results"
    raw_paste = request.form.get('raw_paste', '')

    session['paste_autosubmit'] = request.form.get('paste_autosubmit', 'false')
    session['hide_buttons'] = request.form.get('hide_buttons', 'false')
    session['save'] = request.form.get('save', 'true')
    session['auths'] = session.get('auths') or []
    session['region_id'] = request.form.get('trade_region', '10000002')

    try:
        qty = int(request.form.get('qty', '0'))
    except ( ValueError ):
        qty = 1

    if session['region_id'] not in REGIONS.keys():
        session['region_id'] = '10000002'

    new_result = True  # flag for new results
    authorized = False # flag for authorization to modify

    result_id = short_url.get_id(request.form.get('result_id', 'true'))
    results = load_result(result_id)

    '''
        If results exists, this means we are trying to modify existing result.
        Go through the motions of authenticating user, and return return some variables
    '''
    if results:
        auth = results['auth_hash']
        if (request.form.get('result_id', 'true') not in session.get('auths')):
            results.pop('auth_hash', None)
            results['result_id'] = request.form.get('result_id', 'true')
            return render_template('results.html', error='Not authorized', results=results,
                from_igb=is_from_igb(), full_page=request.form.get('load_full'))

        new_result = False
        prev_types = collections.OrderedDict()
        prev_fits = collections.OrderedDict()
        for  item in results['line_items'].values():
            prev_types[item['typeID']] = EveType(item['typeID']).from_dict(EveType, item)
        for item in results['fits'].values():
            prev_fits[str(item['typeID'])+item['name']] = EveFit(item['typeID']).from_dict(EveFit, item)
        eve_types, fits, bad_lines = parse_paste_items(raw_paste, prev_types, prev_fits, qty)
    else:
        eve_types, fits, bad_lines = parse_paste_items(raw_paste, qty = qty)

    # Populate types with pricing data
    populate_market_values(eve_types.values(), region=session['region_id'])

    # calculate the totals
    totals = {'sell': 0, 'buy': 0, 'volume': 0}
    for t in eve_types.values():
        for total_key in ['sell', 'buy', 'volume']:
            totals[total_key] += t.pricing_info['totals'][total_key]

    #sort buy price
    sorted_eve_types = sorted(eve_types.values(), key=lambda k: -k.representative_value())

    sorted_fits            = sorted(fits.values())
    displayable_line_items = collections.OrderedDict()
    display_fits           = collections.OrderedDict()

    for eve_type in sorted_eve_types:
        displayable_line_items[str(eve_type.type_id)] = eve_type.to_dict()
    for fit in sorted_fits:
        fit.modules.sort(key=lambda k: eve_types.get(int(k)).sort_order())
        display_fits[str(fit.id)] = fit.to_dict()

    results = {
        'from_igb': is_from_igb(),
        'totals': totals,
        'bad_line_items': bad_lines,
        'line_items': displayable_line_items, # dict of inventory
        'fits': display_fits, #dict of fits
        'region_name':  REGIONS[session['region_id']],
        'modified': time.time(),
        'auth_hash': short_hash(6) if new_result else auth
    }

    if len(sorted_eve_types) > 0:
        if session['save'] == 'true':
            result_id = save_result(results, public=True, result_id=(result_id if not new_result else False))
            results['result_id'] = short_url.get_code(result_id)
            session['auths'].append(results['result_id'])
        else:
            result_id = save_result(results, public=False, result_id=(result_id if not new_result else False))

    if not new_result:
        results.pop('auth_hash', None)

    return render_template('results.html', results=results,
        from_igb=is_from_igb(), full_page=request.form.get('load_full'))