Esempio n. 1
0
 def process(self, request, session):
     _id = request.values.get('id')
     productObj = Product()
     prodDetail = productObj.find({'_id': ObjectId(_id)})
     if (prodDetail.count() != 1):
         return abort(404)
     log, u = checkLogin(session)
     return render_template('product.html', m=prodDetail[0], log=log, u=u)
Esempio n. 2
0
async def getProductByFilter(request):
    try:
        body = await request.json()
    except Exception as e:
        raise ClientException('Invalid body')

    name = body.get('name', None)
    properties = body.get('properties', None)

    filterOption = {}
    if name is not None: filterOption['name'] = name

    if properties is not None and isinstance(properties, dict):
        for key, value in properties.items():
            filterOption[f'properties.{key}'] = value

    prodList = [p.toSmallDict() async for p in Product.find(filterOption)]
    return web.json_response(prodList)
Esempio n. 3
0
async def deleteAllProducts(request):
    async for p in Product.find():
        await p.delete()
    return web.Response(status=200)