'Constructor'

def __init__(self):

    T = current.T
    s3db = current.s3db
    settings = current.deployment_settings
    formlist = []
    formdict = {}
    forms = settings.get_mobile_forms()
    if forms:
        keys = set()
        for item in forms:
            options = {}
            if isinstance(item, (tuple, list)):
                if (len(item) == 2):
                    (title, tablename) = item
                    if isinstance(tablename, dict):
                        (tablename, options) = (title, tablename)
                        title = None
                elif (len(item) == 3):
                    (title, tablename, options) = item
                else:
                    continue
            else:
                (title, tablename) = (None, item)
            table = s3db.table(tablename)
            if (not table):
                current.log.warning(('Mobile    forms:    non-existent    resource    %s' % tablename))
                continue
            (c, f) = tablename.split('_', 1)
            c = (options.get('c') or c)
            f = (options.get('f') or f)
            if (not settings.has_module(c)):
                continue
            name = options.get('name')
            if (not name):
                name = ('%s_%s' % (c, f))
            url_vars = options.get('vars')
            if url_vars:
                items = []
                for k in url_vars:
                    v = s3_str(url_vars[k])
                    url_vars[k] = v
                    items.append(('%s=%s' % (k, v)))
                query = '&'.join(sorted(items))
            else:
                query = ''
            key = (c, f, query)
            if (key in keys):
                continue
            keys.add(key)
            if (title is None):
                title = '    '.join((w.capitalize() for w in f.split('_')))
            if isinstance(title, basestring):
                title = T(title)
            data = (True if options.get('data') else False)
            url = {'c': c, 'f': f}
            if url_vars:
                url['v'] = url_vars
            mform = {'n': name, 'l': s3_str(title), 't': tablename, 'r': url, 'd': data}
            formlist.append(mform)
            formdict[name] = mform
    dynamic_tables = settings.get_mobile_dynamic_tables()
    if dynamic_tables:
        ttable = s3db.s3_table
        query = ((ttable.mobile_form == True) & (ttable.deleted != True))
        rows = current.db(query).select(ttable.name, ttable.title, ttable.mobile_data)
        for row in rows:
            tablename = row.name
            suffix = tablename.split('_', 1)[(-1)]
            title = row.title
            if (not title):
                title = '    '.join((s.capitalize() for s in suffix.split('_')))
            url = {'c': 'default', 'f': ('table/%s' % suffix)}
            mform = {'n': tablename, 'l': title, 't': tablename, 'r': url, 'd': row.mobile_data}
            formlist.append(mform)
            formdict[name] = mform
    self.formlist = formlist
    self.forms = formdict
