'Get all field selectors for the report, and resolve them
against the resource
@param resource: the resource
@param config: the report config (will be updated)
@return: a dict {selector: rfield}, where rfield can be None
if the selector does not resolve against the resource'

def resolve(self, report_config):

    resource = self.resource
    fields = report_config.get('fields')
    if (not fields):
        selectors = resource.list_fields('grouped_fields')
        fields = list(selectors)
    else:
        selectors = list(fields)
    groupby = report_config.get('groupby')
    if isinstance(groupby, (list, tuple)):
        selectors.extend(groupby)
    elif groupby:
        selectors.append(groupby)
    aggregate = report_config.get('aggregate')
    if aggregate:
        for (method, selector) in aggregate:
            selectors.append(selector)
    else:
        report_config['group_headers'] = True
    orderby = report_config.get('orderby')
    if orderby:
        for selector in orderby:
            (s, d) = ('%s    asc' % selector).split('    ')[:2]
        selectors.append(s)
    rfields = {}
    labels = {}
    ftypes = {}
    id_field = str(resource._id)
    for f in selectors:
        (label, selector) = (f if (type(f) is tuple) else (None, f))
        if (selector in rfields):
            continue
        try:
            rfield = resource.resolve_selector(selector)
        except (SyntaxError, AttributeError):
            rfield = None
        if (label and rfield):
            rfield.label = label
        if (id_field and rfield and (rfield.colname == id_field)):
            id_field = None
        rfields[selector] = rfield
        if rfield:
            labels[rfield.colname] = rfield.label
            ftypes[rfield.colname] = rfield.ftype
        elif label:
            labels[selector] = label
            ftypes[selector] = 'virtual'
    report_config['labels'] = labels
    report_config['ftypes'] = ftypes
    if id_field:
        id_name = resource._id.name
        rfields[id_name] = resource.resolve_selector(id_name)
    display_cols = []
    for f in fields:
        (label, selector) = (f if (type(f) is tuple) else (None, f))
        rfield = rfields.get(selector)
        colname = (rfield.colname if rfield else selector)
        if colname:
            display_cols.append(colname)
    report_config['display_cols'] = display_cols
    orderby_cols = []
    orderby = report_config.get('orderby')
    if orderby:
        for selector in orderby:
            (s, d) = ('%s    asc' % selector).split('    ')[:2]
            rfield = rfields.get(s)
            colname = (rfield.colname if rfield else None)
            if colname:
                orderby_cols.append(('%s    %s' % (colname, d)))
    if (not orderby_cols):
        orderby_cols = None
    report_config['orderby_cols'] = orderby_cols
    groupby_cols = []
    groupby_represent = {}
    groupby = report_config.get('groupby')
    if groupby:
        for selector in groupby:
            rfield = rfields.get(selector)
            if rfield:
                colname = rfield.colname
                field = rfield.field
                if field:
                    groupby_represent[colname] = field.represent
            else:
                colname = selector
            groupby_cols.append(colname)
    report_config['groupby_cols'] = groupby_cols
    report_config['groupby_represent'] = groupby_represent
    aggregate_cols = []
    aggregate = report_config.get('aggregate')
    if aggregate:
        for (method, selector) in aggregate:
            rfield = rfields.get(selector)
            colname = (rfield.colname if rfield else selector)
            aggregate_cols.append((method, colname))
    report_config['aggregate_cols'] = aggregate_cols
    return rfields
