def feature_import(oauth_request, storage, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user import_features = Feature_.feature_import(request, storage) return status_.status_200(), 200
def features_users_delete(oauth_request, storage, feature_id, user_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user user_permissions = Feature_.permission_delete(storage, feature_id, user_id) if type(user_permissions) is tuple: return user_permissions return status_.status_204(), 204
def feature_batch(storage, extension): Feature_ = Feature() # Feature_.current_user = oauth_request.user import_features = Feature_.feature_batch(request, storage) if type(import_features) is tuple: return import_features return status_.status_200(), 200
def attachment_delete(oauth_request, storage, feature_id, attachment_storage, attachment_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user Feature_.attachment_delete(storage, feature_id, "attachment_" + attachment_storage, attachment_id) try: return status_.status_204(), 204 except Exception as e: return status_.status_500(e), 500
def feature_get_excel_template(oauth_request, storage, is_public): Feature_ = Feature() Feature_.current_user = oauth_request.user excel_template = Feature_.feature_get_excel_template(storage) logger.warning("excel_template %s", excel_template) # return status_.status_200(), 200 return send_from_directory(excel_template.get("directory"), excel_template.get("filename"), as_attachment=True)
def features_users_update(oauth_request, storage, feature_id, user_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user user_permissions = Feature_.permission_update(storage, feature_id, user_id, request) if type(user_permissions) is tuple: return user_permissions arguments = {"the_content": user_permissions, "extension": extension} return Feature_.endpoint_response(**arguments)
def features_users(oauth_request, storage, feature_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user feature_user_list = Feature_.feature_users(storage, feature_id) if type(feature_user_list) is tuple: return feature_user_list arguments = {"the_content": feature_user_list, "list_name": "users", "extension": extension} return Feature_.endpoint_response(**arguments)
def feature_func(oauth_request, storage, extension, is_public): Feature_ = Feature() Feature_.current_user = oauth_request.user function_return = Feature_.feature_evaluate_function(storage) if type(function_return) is tuple: return function_return arguments = {"the_content": function_return, "extension": extension} return Feature_.endpoint_response(**arguments)
def feature_delete(oauth_request, storage, feature_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user deleted_feature = Feature_.feature_delete(storage, feature_id) if type(deleted_feature) is tuple: return deleted_feature try: return status_.status_204(), 204 except Exception as e: return status_.status_500(e), 500
def feature_create(oauth_request, storage, extension, is_crowdsourced): Feature_ = Feature() Feature_.current_user = oauth_request.user new_feature = Feature_.feature_create(request, storage) if type(new_feature) is tuple: return new_feature try: return status_.status_201(new_feature.id), 201 except Exception as e: return status_.status_500(e), 500
def feature_region(oauth_request, storage, extension, is_public): geometry = request.args.get("geometry") results_per_page = request.args.get("results_per_page") Feature_ = Feature() Feature_.current_user = oauth_request.user feature_list = Feature_.feature_get_content_for_region(storage, geometry) if type(feature_list) is tuple: return feature_list arguments = {"the_content": feature_list, "list_name": "features", "extension": extension} return Feature_.endpoint_response(**arguments)
def feature_update(oauth_request, storage, feature_id, extension): Feature_ = Feature() Feature_.current_user = oauth_request.user updated_feature = Feature_.feature_update(request, storage, feature_id) if type(updated_feature) is tuple: return updated_feature arguments = {"the_content": updated_feature, "extension": extension} try: return Feature_.endpoint_response(**arguments) except Exception as e: return status_.status_500(e), 500
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 fetch_dynamic_recipients(feature, **options): from CommonsCloudAPI.models.feature import Feature if 'geometry_intersects' in options.get('conditions', None): # logger.debug('Geometry %s', feature.geometry) if feature.geometry is None: return abort(400) Feature_ = Feature() intersection_options = { "storage_": options.get('from_storage', None), "geometry": feature.geometry } features = Feature_.feature_get_intersection(**intersection_options) # logger.debug('features from get intersects %s', features) """ Create the recipients list """ email_addresses = [] if features: field = options.get('field', None) # logger.debug('features %s', dir(features)) for feature in features: # logger.debug('Adding recipient %s', getattr(feature, field)) email_addresses.append(getattr(feature, field)) if not len(email_addresses): email_addresses.append('*****@*****.**') # logger.debug('email_addresses %s, %s', len(email_addresses), email_addresses) # logger.debug('Dynamic recipient list %s', email_addresses) return { "recipients": features, "email_addresses": email_addresses }
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)