'If this is the cached config, clear the cache.
If this is this user\'s personal config, clear the config
Check that there is only 1 default for each PE
If this is an OU config, then add to GIS menu
If this has a region location, protect that location from accidental
editing (e.g. if it is used as a default location for any resources in
the region) but making it only editable by a MapAdmin.'

@staticmethod
def gis_config_onaccept(form):

    db = current.db
    auth = current.auth
    form_vars = form.vars
    config_id = form_vars.id
    pe_id = form_vars.get('pe_id', None)
    if pe_id:
        user = auth.user
        if (user and (user.pe_id == pe_id)):
            current.response.s3.gis.config = None
        if form_vars.pe_default:
            table = db.gis_config
            query = ((table.pe_id == pe_id) & (table.id != config_id))
            db(query).update(pe_default=False)
        db.gis_menu.update_or_insert(config_id=config_id, pe_id=pe_id)
    else:
        config = current.response.s3.gis.config
        if (config and (config.id == config_id)):
            config = None
    if auth.override:
        db((db.gis_config.id == config_id)).update(owned_by_group=current.session.s3.system_roles.MAP_ADMIN)
    if form_vars.region_location_id:
        db((db.gis_location.id == form_vars.region_location_id)).update(owned_by_group=current.session.s3.system_roles.MAP_ADMIN)
    if ((not form_vars.get('temp', None)) and (not auth.override)):
        settings = current.deployment_settings
        screenshot = settings.get_gis_config_screenshot()
        if (screenshot is not None):
            width = screenshot[0]
            height = screenshot[1]
            filename = current.gis.get_screenshot(config_id, False, height, width)
            db((db.gis_config.id == config_id)).update(image=filename)
