'Extract the style from a LocationSelectorWidget2
& create/update the style record'

@staticmethod
def gis_style_postprocess(form):

    colour = current.request.post_vars.colour
    if (not colour):
        return
    def rgb2hex(r, g, b):
        '\n                                                                Given    an    rgb    or    rgba    sequence    of    0-1    floats,    return    the    hex    string\n                                                '
        return ('%02x%02x%02x' % (r, g, b))
    try:
        parts = colour.split('(', 1)[1][:(-1)].split(',')
    except:
        current.log.error(('invalid    colour:    %s' % colour))
        return
    fill = rgb2hex(int(parts[0]), int(parts[1]), int(parts[2]))
    style = dict(fill=fill)
    if (len(parts) == 4):
        opacity = float(parts[3])
        style['fillOpacity'] = opacity
    else:
        opacity = 1
    db = current.db
    s3db = current.s3db
    (c, f) = str(form.table).split('_', 1)
    ftable = s3db.gis_layer_feature
    query = ((((ftable.deleted != True) & (ftable.controller == c)) & (ftable.function == f)) & (ftable.individual == True))
    rows = db(query).select(ftable.layer_id)
    stable = s3db.gis_style
    record_id = form.vars.id
    for row in rows:
        layer_id = row.layer_id
        query = ((stable.layer_id == layer_id) & (stable.record_id == record_id))
        exists = db(query).select(stable.id, limitby=(0, 1)).first()
        if exists:
            exists.update_record(opacity=opacity, style=style)
        else:
            stable.insert(layer_id=layer_id, record_id=record_id, opacity=opacity, style=style)
