'Get all values for the given S3ResourceFields (axes) which
match the resource query, used in pivot tables to filter out
additional values where dimensions can have multiple values
per record
@param axes: the axis fields as list/tuple of S3ResourceFields
@return: a dict with values per axis, only containes those
axes which are affected by the resource filter'

def axisfilter(self, axes):

    axisfilter = {}
    qdict = self.get_query().as_dict(flat=True)
    for rfield in axes:
        field = rfield.field
        if (field is None):
            continue
        left_joins = S3Joins(self.tablename)
        left_joins.extend(rfield.left)
        tablenames = left_joins.joins.keys()
        tablenames.append(self.tablename)
        af = S3AxisFilter(qdict, tablenames)
        if (af.op is not None):
            query = af.query()
            left = left_joins.as_list()
            rows = current.db(query).select(field, left=left, groupby=field)
            colname = rfield.colname
            if (rfield.ftype[:5] == 'list:'):
                values = []
                vappend = values.append
                for row in rows:
                    v = row[colname]
                    vappend((v if v else [None]))
                values = set(chain.from_iterable(values))
                (include, exclude) = af.values(rfield)
                fdict = {}
                if include:
                    for v in values:
                        vstr = (s3_unicode(v) if (v is not None) else v)
                        if ((vstr in include) and (vstr not in exclude)):
                            fdict[v] = None
                else:
                    fdict = dict(((v, None) for v in values))
                axisfilter[colname] = fdict
            else:
                axisfilter[colname] = dict(((row[colname], None) for row in rows))
    return axisfilter
