'Get the options for the widget
@return: dict {value: representation} of options'

def get_options(self):

    resource = self.resource
    (component, link) = self.get_link()
    rkey = link.table[component.rkey]
    opts = []
    requires = rkey.requires
    if (not isinstance(requires, (list, tuple))):
        requires = [requires]
    if requires:
        validator = requires[0]
        if isinstance(validator, IS_EMPTY_OR):
            validator = validator.other
        try:
            opts = validator.options()
        except:
            pass
    widget_opts = self.options
    filterby = widget_opts.get('filterby')
    filteropts = widget_opts.get('options')
    filterexpr = widget_opts.get('match')
    if (filterby and ((filteropts is not None) or (filterexpr and resource._rows))):
        filter_selector = FS(filterby)
        filter_query = None
        if (filteropts is not None):
            if isinstance(filteropts, (list, tuple, set)):
                filter_query = filter_selector.belongs(list(filteropts))
            else:
                filter_query = (filter_selector == filteropts)
        elif filterexpr:
            rfield = resource.resolve_selector(filterexpr)
            colname = rfield.colname
            rows = resource.select([filterexpr], as_rows=True)
            values = set((row[colname] for row in rows))
            values.discard(None)
            if values:
                filter_query = (filter_selector.belongs(values) | (filter_selector == None))
        filter_resource = current.s3db.resource(component.tablename, filter=filter_query)
        rows = filter_resource.select(['id'], as_rows=True)
        filtered_opts = []
        values = set((str(row[component.table._id]) for row in rows))
        for opt in opts:
            if (str(opt[0]) in values):
                filtered_opts.append(opt)
        opts = filtered_opts
    return dict(opts)
