Esempio n. 1
0
def character_assets_by_market_group(request, charID, marketGroupID=None):
    response = HttpResponse(mimetype="application/json")
    logger.debug("User %s request assets for character %s by market group %s" % (request.user.username, charID, marketGroupID))
    char = Character.objects.get(pk=charID)

    expand = lambda obj: {
        "typeID":obj['typeID'],
        "typeName": invTypes.objects.get(pk=obj['typeID']).typeName,
        "locationName":mapDenormalize.objects.get(pk=obj['locationID']).itemName,
        "locationID":obj['locationID'],
        "quantity":obj['total'],
    }

    if marketGroupID == None:
        assets = char.assetList.asset_set.filter(typeID__marketGroupID = marketGroupID).values('typeID','locationID').annotate(total = Sum('quantity')).order_by('-total')

        result = [expand(x) for x in assets]
        jsonResponse = JSONResponse(success=True, result=result)
        response.write(jsonResponse.json())

    else:
        marketGroup = invMarketGroups.objects.get(pk=marketGroupID)
        assets = char.assetList.asset_set.filter(typeID__marketGroupID__in = marketGroup.findMarketGroupIDs()).values('typeID','locationID').annotate(total = Sum('quantity')).order_by('-total')

        result = [expand(x) for x in assets]
        jsonResponse = JSONResponse(success=True, result=result)
        response.write(jsonResponse.json())

    return response
Esempio n. 2
0
def inv_market_group(request, marketGroupID):
    response = HttpResponse(mimetype="application/json")

    result = invMarketGroups.objects.values().get(pk=marketGroupID)
    response.write(simplejson.dumps(result, indent=2))

    logger.debug("User %s requested inv_market_group %s" % (request.user.username, marketGroupID))
    return response
Esempio n. 3
0
def inv_type(request, typeID):
    response = HttpResponse(mimetype="application/json")

    result = invTypes.objects.values().get(pk=typeID)
    response.write(simplejson.dumps(result, indent=2))

    logger.debug("User %s requested inv_typ %s" % (request.user.username, typeID))
    return response