'Takes the JSON from the real input and returns a location ID
for it. Creates or updates the location if necessary.
@param value: the JSON from the real input
@return: tuple (location_id, error)
@ToDo: Audit'

def postprocess(self, value):

    (values, error) = self.validate(value)
    if values:
        location_id = values.get('id')
    else:
        location_id = None
    if error:
        return (None, error)
    if (location_id is None):
        return (location_id, None)
    db = current.db
    table = current.s3db.gis_location
    lat = values.get('lat')
    lon = values.get('lon')
    lat_min = values.get('lat_min')
    lon_min = values.get('lon_min')
    lat_max = values.get('lat_max')
    lon_max = values.get('lon_max')
    wkt = values.get('wkt')
    radius = values.get('radius')
    the_geom = values.get('the_geom')
    address = values.get('address')
    postcode = values.get('postcode')
    parent = values.get('parent')
    gis_feature_type = values.get('gis_feature_type')
    if (location_id == 0):
        if ((wkt is not None) or ((lat is not None) and (lon is not None))):
            inherited = False
        else:
            inherited = True
        feature = Storage(lat=lat, lon=lon, lat_min=lat_min, lon_min=lon_min, lat_max=lat_max, lon_max=lon_max, wkt=wkt, radius=radius, inherited=inherited, addr_street=address, addr_postcode=postcode, parent=parent)
        if gis_feature_type:
            feature.gis_feature_type = gis_feature_type
        if the_geom:
            feature.the_geom = the_geom
        location_id = table.insert(**feature)
        feature.id = location_id
        current.gis.update_location_tree(feature)
    else:
        specific = values.get('specific')
        if (specific and (specific == location_id)):
            feature = Storage(addr_street=address, addr_postcode=postcode, parent=parent)
            if any(((detail is not None) for detail in (lat, lon, wkt, radius))):
                feature.lat = lat
                feature.lon = lon
                feature.lat_min = lat_min
                feature.lon_min = lon_min
                feature.lat_max = lat_max
                feature.lon_max = lon_max
                feature.wkt = wkt
                feature.radius = radius
                feature.inherited = False
            if gis_feature_type:
                feature.gis_feature_type = gis_feature_type
            if the_geom:
                feature.the_geom = the_geom
            db((table.id == location_id)).update(**feature)
            feature.id = location_id
            current.gis.update_location_tree(feature)
    return (location_id, None)
