Example #1
0
def item(class_id, instance_id):
    # TODO: app, ctxid? don't know if class/instance are unique or not
    item = api('/item/%s/%s' % (class_id, instance_id))
    if item:
        has = False
        name = base64.b64encode(item['name'].encode('utf8'))
        if g.user:
            has = api('/user/{}/inventory/{}/{}/has'.format(
                    g.user['_id'], item['app_id'], name))

        item['total'] = item.get('available', 0)
        for var in item.get('variants', []):
            item['total'] += var.get('available', 0)

        g.set_context((item['app_id'], item['context_id']))
        has_game = False
        if g.context == 'games':
            app = g.steam_app = api('/steam/app', name=name)
            if g.user and app:
                games = g.user.get('games', [])
                has_game = any(str(a['appid']) == str(app['app_id']) for a in games)

        return render_template(
            'item.html', item=item,
            steam_app=g.steam_app,
            has_item=has, has_game=has_game,
        )
    else:
        return redirect('/', code=302)
Example #2
0
def ajax_recent(context=None):
    g.set_context(name=context)
    items = recent_items()
    return render_template('sub/recent.html', recent=items)