'Set the pe_type'

@staticmethod
def gis_config_onvalidation(form):

    form_vars = form.vars
    if (form_vars.uuid == 'SITE_DEFAULT'):
        form_vars.pe_type = 9
    elif ('pe_id' in form_vars):
        pe_id = form_vars.pe_id
        if pe_id:
            db = current.db
            s3db = current.s3db
            table = s3db.pr_pentity
            query = (table.pe_id == pe_id)
            pe = db(query).select(table.instance_type, limitby=(0, 1)).first()
            if pe:
                pe_type = pe.instance_type
                if (pe_type == 'pr_person'):
                    form_vars.pe_type = 1
                elif (pe_type == 'pr_group'):
                    form_vars.pe_type = 2
                elif (pe_type == 'org_office'):
                    form_vars.pe_type = 4
                elif (pe_type == 'org_group'):
                    form_vars.pe_type = 8
                elif (pe_type == 'org_organisation'):
                    if current.deployment_settings.get_org_branches():
                        otable = s3db.org_organisation
                        btable = s3db.org_organisation_branch
                        query = ((otable.pe_id == pe_id) & (btable.branch_id == otable.id))
                        branch = db(query).select(btable.id, limitby=(0, 1)).first()
                        if branch:
                            form_vars.pe_type = 6
                        else:
                            form_vars.pe_type = 7
                    else:
                        form_vars.pe_type = 7
    elif ('config' in current.request.args):
        form_vars.pe_type = 1
