def product_file(tiid): if request.method == "GET": try: product = get_product(tiid) if not product: return abort_json(404, "product not found") if product.has_file: my_file = product.get_file() resp = make_response(my_file, 200) return resp else: abort_json(404, "This product exists, but has no file.") except IndexError: abort_json(404, "That product doesn't exist.") except S3ResponseError: abort_json(404, "This product exists, but has no file.") elif request.method == "POST": current_user_must_own_tiid(tiid) file_to_upload = request.files['file'].stream product = get_product(tiid) resp = upload_file_and_commit(product, file_to_upload, db) return json_resp_from_thing(resp)
def product_from_tiid(url_slug, tiid): local_sleep(1) product = get_product(tiid) if not product: abort_json(404, "This product does not exist.") product_dict = product.to_dict() return json_resp_from_thing(product_dict)
def product_without_needing_profile(tiid): """ I think this is unused, replaced by product_from_tiid. If it is used, it's broken because all the markups it gives just point to /jason profile. """ local_sleep(1) product = get_product(tiid) if not product: return abort_json(404, "product not found") markup = Markup("jason", embed=False) product_dict = product.to_markup_dict( markup=markup ) product_dict["metrics"] = product.metrics product_dict["countries"] = product.countries product_dict["metrics"] = product.metrics product_dict["countries"] = product.countries return json_resp_from_thing(product_dict)
def product_pdf(tiid): if request.method == "GET": try: product = get_product(tiid) pdf = product.get_pdf() db.session.merge(product) # get pdf might have cached the pdf commit(db) if pdf: resp = make_response(pdf, 200) resp.mimetype = "application/pdf" resp.headers.add("Content-Disposition", "attachment; filename=impactstory-{tiid}.pdf".format( tiid=tiid)) return resp else: abort_json(404, "This product exists, but has no pdf.") except IndexError: abort_json(404, "That product doesn't exist.") except S3ResponseError: abort_json(404, "This product exists, but has no pdf.")
def product_embed_markup(tiid): product = get_product(tiid) html_markup = product.get_embed_markup() return json_resp_from_thing({"html": html_markup})