def image(request,oid,name): toy = Toy.objects(pk=oid).first() for image in toy.images: if str(image.image.name) == name: return HttpResponse(image.image.read(), content_type=image.image.content_type, )
def gcode(request,oid,name): toy = Toy.objects(pk=oid).first() for gcode_file in toy.gcode: print gcode_file.data if str(gcode_file.data.name) == name: return HttpResponse(gcode_file.data.read(), content_type=gcode_file.data.content_type, )
def detail(request,oid): toy = Toy.objects(pk=oid).first() images = [] thumbnail = [] gcodes = [] thumbnail = get_thumbnail(toy) for image in toy.images: image_url = "api/image/"+str(toy.id)+"/"+str(image.image.name) images.append(image_url) for gcode in toy.gcode: gcode_url = "api/gcode/"+str(toy.id)+"/"+str(gcode.data.name) gcodes.append(gcode_url) toyDic = json.loads(toy.to_json()) # toyDic = {"name":toy.name,"image":images,"thumbnail":thumbnail, "gcode":gcodes} toyDic['images'] = images # toyDic['images'] = json.dumps(images) toyDic['thumbnail'] = thumbnail toyDic['gcode'] = gcodes toyDic['catalog'] = str(toy.catalog.id) del toyDic['_id'] toyJson = json.dumps(toyDic) return HttpResponse(toyJson)
def catalog(request,catalogId): print "catalogId is "+catalogId toys = Toy.objects(catalog=catalogId).all() toys_json = get_toy_list(toys) return HttpResponse(toys_json)