'Re-render the options list for a field if there is a
filterby-restriction.
@param fieldname: the name of the field'

def _filterby_options(self, fieldname):

    component = self.resource.components[self.selector]
    table = component.table
    if (fieldname not in table.fields):
        return None
    field = table[fieldname]
    filterby = self.options['filterby']
    if (not isinstance(filterby, (list, tuple))):
        filterby = [filterby]
    filter_fields = dict(((f['field'], f) for f in filterby))
    if (fieldname not in filter_fields):
        return None
    filterby = filter_fields[fieldname]
    if ('options' not in filterby):
        return None
    requires = field.requires
    if (not isinstance(requires, (list, tuple))):
        requires = [requires]
    if requires:
        r = requires[0]
        if isinstance(r, IS_EMPTY_OR):
            r = r.other
        if (not isinstance(r, IS_IN_SET)):
            return None
    else:
        return None
    r_opts = r.options()
    options = filterby['options']
    if (not isinstance(options, (list, tuple))):
        options = [options]
    subset = []
    if ('invert' in filterby):
        invert = filterby['invert']
    else:
        invert = False
    for o in r_opts:
        if invert:
            if isinstance(o, (list, tuple)):
                if (o[0] not in options):
                    subset.append(o)
            elif isinstance(r_opts, dict):
                if (o not in options):
                    subset.append((o, r_opts[o]))
            elif (o not in options):
                subset.append(o)
        elif isinstance(o, (list, tuple)):
            if (o[0] in options):
                subset.append(o)
        elif isinstance(r_opts, dict):
            if (o in options):
                subset.append((o, r_opts[o]))
        elif (o in options):
            subset.append(o)
    return subset
