Package s3 :: Module s3widgets :: Class S3LocationSelector
[frames] | no frames]

Class S3LocationSelector

source code

??-278 --+    
         |    
S3Selector --+
             |
            S3LocationSelector


Form widget to select a location_id that can also
create/update the location

Differences to the original S3LocationSelectorWidget:
* Allows selection of either an Lx or creation of a new Point
  within the lowest Lx level
* Uses dropdowns not autocompletes
* Selection of lower Lx levels only happens when higher-level
  have been done

Implementation Notes:
* Performance: Create JSON for the hierarchy, along with bboxes for
               the map zoom - loaded progressively rather than all as
               one big download
h = {id : {'n' : name,
           'l' : level,
           'f' : parent
           }}

Limitations (@todo):
* Doesn't allow creation of new Lx Locations
* Doesn't support manual entry of LatLons
* Doesn't allow selection of existing specific Locations
* Doesn't support variable Levels by Country
* Use in an InlineComponent with multiple=False needs completing:
    - Validation errors cause issues
    - Needs more testing
* Should support use in an InlineComponent with multiple=True
* Should support multiple on a page

Instance Methods
 
__init__(self, levels=None, required_levels=None, hide_lx=True, reverse_lx=False, show_address=False, show_postcode=None, show_latlon=None, latlon_mode="decimal", latlon_mode_toggle=True, show_map=None, open_map_on_load=False, feature_required=False, lines=False, points=True, polygons=False, circles=False, color_picker=False, catalog_layers=False, min_bbox=None, labels=True, placeholders=False, error_message=None, represent=None, prevent_duplicate_addresses=False)
Constructor
source code
 
levels(self)
Lx-levels to expose as dropdowns
source code
 
required_levels(self)
Lx-levels to treat as required
source code
 
load_levels(self)
Lx-levels to load from the database = all levels down to the lowest exposed level (L0=highest, L5=lowest)
source code
 
mobile(self)
Mobile widget settings
source code
 
__call__(self, field, value, **attributes)
Widget renderer
source code
 
extract(self, record_id, values=None)
Load record data from database and update the values dict
source code
 
represent(self, value)
Representation of a new/updated location row (before DB commit).
source code
 
validate(self, value, requires=None)
Parse and validate the input value, but don't create or update any location data
source code
 
postprocess(self, value)
Takes the JSON from the real input and returns a location ID for it.
source code

Inherited from S3Selector: inputfield, parse, serialize

Class Variables
  keys = "L0", "L1", "L2", "L3", "L4", "L5", "address", "postcod...
Method Details

__init__(self, levels=None, required_levels=None, hide_lx=True, reverse_lx=False, show_address=False, show_postcode=None, show_latlon=None, latlon_mode="decimal", latlon_mode_toggle=True, show_map=None, open_map_on_load=False, feature_required=False, lines=False, points=True, polygons=False, circles=False, color_picker=False, catalog_layers=False, min_bbox=None, labels=True, placeholders=False, error_message=None, represent=None, prevent_duplicate_addresses=False)
(Constructor)

source code 

Constructor

Parameters:
  • levels - list or tuple of hierarchy levels (names) to expose, in order (e.g. ("L0", "L1", "L2")) or False to disable completely
  • required_levels - list or tuple of required hierarchy levels (if empty, only the highest selectable Lx will be required)
  • hide_lx - hide Lx selectors until higher level has been selected
  • reverse_lx - render Lx selectors in the order usually used by street Addresses (lowest level first), and below the address line
  • show_address - show a field for street address. If the parameter is set to a string then this is used as the label.
  • show_postcode - show a field for postcode
  • show_latlon - show fields for manual Lat/Lon input
  • latlon_mode - (initial) lat/lon input mode ("decimal" or "dms")
  • latlon_mode_toggle - allow user to toggle lat/lon input mode
  • show_map - show a map to select specific points
  • open_map_on_load - show map on load
  • feature_required - map feature is required
  • lines - use a line draw tool
  • points - use a point draw tool
  • polygons - use a polygon draw tool
  • circles - use a circle draw tool
  • color_picker - display a color-picker to set per-feature styling (also need to enable in the feature layer to show on map)
  • catalog_layers - display catalogue layers or just the default base layer
  • min_bbox - minimum BBOX in map selector, used to determine automatic zoom level for single-point locations
  • labels - show labels on inputs
  • placeholders - show placeholder text in inputs
  • error_message - default error message for server-side validation
  • represent - an S3Represent instance that can represent non-DB rows
  • prevent_duplicate_addresses - do a check for duplicate addresses & prevent creation of record if a dupe is found

levels(self)

source code 

Lx-levels to expose as dropdowns

Decorators:
  • @property

required_levels(self)

source code 

Lx-levels to treat as required

Decorators:
  • @property

load_levels(self)

source code 

Lx-levels to load from the database = all levels down to the lowest exposed level (L0=highest, L5=lowest)

Decorators:
  • @property

mobile(self)

source code 

Mobile widget settings

Decorators:
  • @property

To Do: Expose configuration options

__call__(self, field, value, **attributes)
(Call operator)

source code 

Widget renderer

Parameters:
  • field - the Field
  • value - the current value(s)
  • attr - additional HTML attributes for the widget
Returns:
the widget HTML
Overrides: S3Selector.__call__

extract(self, record_id, values=None)

source code 

Load record data from database and update the values dict

Parameters:
  • record_id - the location record ID
  • values - the values dict
Returns:
the (updated) values dict
Overrides: S3Selector.extract

represent(self, value)

source code 

Representation of a new/updated location row (before DB commit).

NB: Using a fake path here in order to prevent
    gis_LocationRepresent.represent_row() from running
    update_location_tree as that would change DB status which
    is an invalid action at this point (row not committed yet).

This method is called during S3CRUD.validate for inline components

@param values: the values dict

@return: string representation for the values dict

Overrides: S3Selector.represent

validate(self, value, requires=None)

source code 

Parse and validate the input value, but don't create or update any location data

Parameters:
  • value - the value from the form
  • requires - the field validator
Returns:
tuple (values, error) with values being the parsed value dict, and error any validation errors
Overrides: S3Selector.validate

postprocess(self, value)

source code 

Takes the JSON from the real input and returns a location ID for it. Creates or updates the location if necessary.

Parameters:
  • value - the JSON from the real input
Returns:
tuple (location_id, error)
Overrides: S3Selector.postprocess

To Do: Audit


Class Variable Details

keys

Value:
"L0", "L1", "L2", "L3", "L4", "L5", "address", "postcode", "lat", "lon\
", "wkt", "specific", "id", "radius"