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)
def feature_get_relationship(oauth_request, storage, feature_id, relationship, extension, is_public): Feature_ = Feature() Feature_.current_user = oauth_request.user feature = Feature_.feature_get_relationship(storage, feature_id, relationship) if type(feature) is tuple: return feature arguments = {"the_content": feature, "list_name": "features", "extension": extension, "code": 200} if extension == "csv": return status_.status_415("We do not support exporting a single item or it's relationships as a CSV file."), 415 return Feature_.endpoint_response(**arguments)
def feature_get(oauth_request, storage, feature_id, extension, is_public): if extension == "csv": return status_.status_415("We do not support exporting a single item as a CSV file."), 415 Feature_ = Feature() Feature_.current_user = oauth_request.user feature = Feature_.feature_get(storage, feature_id) if type(feature) is tuple: return feature arguments = {"the_content": feature, "extension": extension, "code": 200} return Feature_.endpoint_response(**arguments)
def endpoint_response( self, the_content, extension="json", list_name="", exclude_fields=[], code=200, last_modified="", **extras ): """ Make sure the content is ready to be served """ if type(the_content) is list: the_content = {list_name: self.serialize_list(the_content)} else: the_content = self.serialize_object(the_content, single=True) """ If the user is properly authenticated, then proceed to see if they have requests a type of content we serve """ if extension == "json": this_data = JSON(the_content, list_name=list_name, exclude_fields=exclude_fields, **extras) return this_data.create(), code elif extension == "geojson": this_data = GeoJSON(the_content, list_name=list_name, exclude_fields=exclude_fields, **extras) return this_data.create(), code elif extension == "csv": this_data = CSV(the_content, exclude_fields=exclude_fields) return this_data.create(), code """ If the user hasn't requested a specific content type then we should tell them that, by directing them to an "Unsupported Media Type" """ return status_.status_415(), 415