Exemplo n.º 1
0
def measure_version_file_download(topic_slug, subtopic_slug, measure_slug,
                                  version, filename):
    try:
        *_, measure_version = page_service.get_measure_version_hierarchy(
            topic_slug, subtopic_slug, measure_slug, version)
        upload_obj = upload_service.get_upload(measure_version, filename)
        downloaded_file = upload_service.get_measure_download(
            upload_obj, filename, "source")
        content = get_csv_data_for_download(downloaded_file)
        if os.path.exists(downloaded_file):
            os.remove(downloaded_file)
        if content.strip() == "":
            abort(404)

        outfile = NamedTemporaryFile("w",
                                     encoding="windows-1252",
                                     delete=False)
        outfile.write(content)
        outfile.flush()

        return send_file(outfile.name,
                         as_attachment=True,
                         mimetype="text/csv",
                         attachment_filename=filename)

    except (UploadNotFoundException, FileNotFoundError, ClientError):
        abort(404)
Exemplo n.º 2
0
def dimension_file_table_download(topic_slug, subtopic_slug, measure_slug,
                                  version, dimension_guid):
    try:
        *_, dimension = page_service.get_measure_version_hierarchy(
            topic_slug,
            subtopic_slug,
            measure_slug,
            version,
            dimension_guid=dimension_guid)
        dimension_obj = DimensionObjectBuilder.build(dimension)

        data = write_dimension_tabular_csv(dimension=dimension_obj)
        response = make_response(data)

        if dimension_obj["context"][
                "dimension"] and dimension_obj["context"]["dimension"] != "":
            filename = "%s-table.csv" % cleanup_filename(
                dimension_obj["context"]["dimension"].lower())
        else:
            filename = "%s-table.csv" % cleanup_filename(
                dimension_obj["context"]["guid"])

        response.headers["Content-Type"] = "text/csv"
        response.headers[
            "Content-Disposition"] = 'attachment; filename="%s"' % filename
        return response

    except DimensionNotFoundException:
        abort(404)
Exemplo n.º 3
0
def measure_version(topic_slug, subtopic_slug, measure_slug, version):

    measure = page_service.get_measure(topic_slug, subtopic_slug, measure_slug)

    try:
        if version == "latest":

            latest_url = True
            if current_user.can_access_measure(measure):
                measure_version = measure.latest_version
            else:
                measure_version = measure.latest_published_version

        else:
            latest_url = False
            *_, measure_version = page_service.get_measure_version_hierarchy(
                topic_slug, subtopic_slug, measure_slug, version)

            if not (current_user.can_access_measure(measure)
                    or measure_version.status == "APPROVED"):
                abort(403)

    except PageNotFoundException:
        abort(404)

    return render_template(
        "static_site/measure.html",
        topic_slug=topic_slug,
        subtopic_slug=subtopic_slug,
        measure_version=measure_version,
        latest_url=latest_url,
    )
Exemplo n.º 4
0
def measure_version_markdown(topic_slug, subtopic_slug, measure_slug, version):
    try:
        if version == "latest":
            measure_version = page_service.get_measure(
                topic_slug, subtopic_slug, measure_slug).latest_version
        else:
            *_, measure_version = page_service.get_measure_version_hierarchy(
                topic_slug, subtopic_slug, measure_slug, version)
    except PageNotFoundException:
        abort(404)
    if current_user.is_departmental_user():
        if measure_version.status not in ["DEPARTMENT_REVIEW", "APPROVED"]:
            return render_template("static_site/not_ready_for_review.html")

    return render_template(
        "static_site/export/measure_export.html",
        topic_slug=topic_slug,
        subtopic_slug=subtopic_slug,
        measure_version=measure_version,
    )