Exemplo n.º 1
0
def feature_list(oauth_request, storage, extension, is_public):

    # if (extension == 'csv'):
    #     return status_.status_415('We do not support exporting a feature list as a CSV file yet, but we\'re working on it.'), 415
    if extension == "shp":
        return (
            status_.status_415(
                "We do not support exporting a feature list as a SHP file yet, but we're working on it."
            ),
            415,
        )

    results_per_page = request.args.get("results_per_page")
    if not results_per_page:
        results_per_page = 25
    else:
        results_per_page = int(request.args.get("results_per_page"))

    if "false" == request.args.get("statistics"):
        show_statistics = False
    else:
        show_statistics = True

    if "false" == request.args.get("relationship"):
        show_relationship = False
    else:
        show_relationship = True

    Feature_ = Feature()
    Feature_.current_user = oauth_request.user
    feature_list = Feature_.feature_list(storage, results_per_page, show_statistics, show_relationship)

    if type(feature_list) is tuple:
        return feature_list

    feature_results = feature_list.get("results")
    features_last_modified = Feature_.features_last_modified(feature_list.get("model"))

    """
    Get Statistics for this Feature set if they are requested by setting statistics to True
    """
    feature_statistics = None
    if show_statistics:
        feature_statistics = Feature_.feature_statistic(feature_list.get("model"), feature_list.get("template"))

    arguments = {
        "the_content": feature_results.get("objects"),
        "list_name": "features",
        "extension": extension,
        "current_page": feature_results.get("page"),
        "total_pages": feature_results.get("total_pages"),
        "total_features": feature_results.get("num_results"),
        "features_per_page": results_per_page,
        "statistics": feature_statistics,
        "last_modified": features_last_modified,
    }

    return Feature_.endpoint_response(**arguments)