geonode.utils
Attributes
Exceptions
Common base class for all non-exit exceptions. |
Classes
OGC Server object. |
|
OGC Server Settings Convenience dict. |
|
Python3 class temporarily disabling django signals on model creation. |
|
Functions
|
|
|
Unzips a zipfile into a temporary directory and returns the full path of the .shp file inside (if any) |
|
Extracts a tarfile into a temporary directory and returns the full path of the .shp file inside (if any) |
|
Get the workspace where the input layer belongs |
|
Get the workspace where the input layer belongs |
|
|
|
grab basic auth info |
|
|
|
split and strip keywords, preserve space |
|
|
|
|
|
|
|
native_bbox must be in the form |
|
|
|
|
|
|
|
Given geographic coordinates, return a x,y tuple in spherical mercator. |
|
Given coordinates in spherical mercator, return a lon,lat tuple. |
|
Resolve an object using the provided query and check the optional |
|
Create a proper JSON response. If body is provided, this is the response. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Check if shapefile for a given layer has valid column names. |
|
Clone an existing ogr.FieldDefn with a new name |
|
Rename columns in a layer to those specified in the given mapping |
|
Try to fix column names and warn the user |
|
|
|
|
|
|
|
|
|
Execute raw query |
|
|
|
|
|
Check that geonode use a particular OGC Backend integration |
Returns the name of a folder with the 'now' time as suffix |
|
|
|
|
|
|
|
|
|
|
Make a slug from the given text, which is simplified from slugify. |
|
|
|
|
|
Add GET params to provided URL being aware of existing. |
|
|
|
|
|
Returns an object if the id matches in any list of objects |
|
|
|
|
|
|
|
A view that is not vulnerable to malicious file access. |
Module Contents
- geonode.utils.signalnames = ['class_prepared', 'm2m_changed', 'post_delete', 'post_init', 'post_save', 'post_syncdb',...[source]
- exception geonode.utils.ServerDoesNotExist[source]
Bases:
ExceptionCommon base class for all non-exit exceptions.
- class geonode.utils.OGC_Servers_Handler(ogc_server_dict)[source]
OGC Server Settings Convenience dict.
- geonode.utils.unzip_file(upload_file, extension='.shp', tempdir=None)[source]
Unzips a zipfile into a temporary directory and returns the full path of the .shp file inside (if any)
- geonode.utils.extract_tarfile(upload_file, extension='.shp', tempdir=None)[source]
Extracts a tarfile into a temporary directory and returns the full path of the .shp file inside (if any)
- geonode.utils.get_dataset_workspace(dataset)[source]
Get the workspace where the input layer belongs
- geonode.utils._split_query(query)[source]
split and strip keywords, preserve space separated quoted blocks.
- geonode.utils.bbox_to_projection(native_bbox, target_srid=4326)[source]
- native_bbox must be in the form
(‘-81.3962935’, ‘-81.3490249’, ‘13.3202891’, ‘13.3859614’, ‘EPSG:4326’)
- geonode.utils.forward_mercator(lonlat)[source]
Given geographic coordinates, return a x,y tuple in spherical mercator.
If the lat value is out of range, -inf will be returned as the y value
- geonode.utils.inverse_mercator(xy)[source]
Given coordinates in spherical mercator, return a lon,lat tuple.
- geonode.utils.resolve_object(request, model, query, permission='base.view_resourcebase', user=None, permission_required=True, permission_msg=None)[source]
Resolve an object using the provided query and check the optional permission. Model views should wrap this function as a shortcut.
query - a dict to use for querying the model permission - an optional permission to check permission_required - if False, allow get methods to proceed permission_msg - optional message to use in 403
- geonode.utils.json_response(body=None, errors=None, url=None, redirect_to=None, exception=None, content_type=None, status=None)[source]
Create a proper JSON response. If body is provided, this is the response. If errors is not None, the response is a success/errors json object. If redirect_to is not None, the response is a success=True, redirect_to object If the exception is provided, it will be logged. If body is a string, the exception message will be used as a format option to that string and the result will be a success=False, errors = body % exception
- geonode.utils.check_shp_columnnames(layer)[source]
Check if shapefile for a given layer has valid column names. If not, try to fix column names and warn the user
- geonode.utils.clone_shp_field_defn(srcFieldDefn, name)[source]
Clone an existing ogr.FieldDefn with a new name
- geonode.utils.rename_shp_columnnames(inLayer, fieldnames)[source]
Rename columns in a layer to those specified in the given mapping
- geonode.utils.fixup_shp_columnnames(inShapefile, charset, tempdir=None)[source]
Try to fix column names and warn the user
- class geonode.utils.DisableDjangoSignals(disabled_signals=None, skip=False)[source]
Python3 class temporarily disabling django signals on model creation.
usage: with DisableDjangoSignals():
- geonode.utils.raw_sql(query, params=None, ret=True)[source]
Execute raw query param ret=True returns data from cursor as iterator
- geonode.utils.check_ogc_backend(backend_package)[source]
Check that geonode use a particular OGC Backend integration
- Parameters:
backend_package (str) – django app of backend to use
- Returns:
bool
- Return type:
bool
- class geonode.utils.HttpClient[source]
- geonode.utils.get_dir_time_suffix()[source]
Returns the name of a folder with the ‘now’ time as suffix
- geonode.utils.slugify_zh(text, separator='_')[source]
Make a slug from the given text, which is simplified from slugify. It remove the other args and do not convert Chinese into Pinyin :param text (str): initial text :param separator (str): separator between words :return (str):
- geonode.utils.get_legend_url(instance, style_name, /, service_url=None, dataset_name=None, version='1.3.0', sld_version='1.1.0', width=20, height=20, params=None)[source]
- geonode.utils.add_url_params(url, params)[source]
Add GET params to provided URL being aware of existing.
- Parameters:
url – string of target URL
params – dict containing requested params to be added
- Returns:
string with updated URL
>> url = ‘http://stackoverflow.com/test?answers=true’ >> new_params = {‘answers’: False, ‘data’: [‘some’,’values’]} >> add_url_params(url, new_params) ‘http://stackoverflow.com/test?data=some&data=values&answers=false’
- geonode.utils.json_serializer_producer(dictionary)[source]
- usage:
- serialized_obj =
json_serializer_producer(model_to_dict(instance))
- dump to file:
- with open(‘data.json’, ‘w’) as outfile:
json.dump(serialized_obj, outfile)
- read from file:
- with open(‘data.json’, ‘r’) as infile:
serialized_obj = json.load(infile)
- geonode.utils.find_by_attr(lst, val, attr='id')[source]
Returns an object if the id matches in any list of objects