'Create the code from the name'

@staticmethod
def org_site_onaccept(form):

    name = form.vars.name
    if (not name):
        return
    code_len = current.deployment_settings.get_org_site_code_len()
    temp_code = name[:code_len].upper()
    db = current.db
    site_table = db.org_site
    query = (site_table.code == temp_code)
    row = db(query).select(site_table.id, limitby=(0, 1)).first()
    if row:
        code = temp_code
        temp_code = None
        wildcard_bit = 1
        length = len(code)
        max_wc_bit = pow(2, length)
        while ((not temp_code) and (wildcard_bit < max_wc_bit)):
            wildcard_posn = []
            for w in range(length):
                if (wildcard_bit & pow(2, w)):
                    wildcard_posn.append((length - (1 + w)))
            wildcard_bit += 1
            code_list = S3SiteModel.getCodeList(code, wildcard_posn)
            temp_code = S3SiteModel.returnUniqueCode(code, wildcard_posn, code_list)
    if temp_code:
        db((site_table.site_id == form.vars.site_id)).update(code=temp_code)
