'Resolve a context filter
@param context: the context (as a string)
@param id: the record_id'

@staticmethod
def _resolve_context(r, tablename, context):

    record_id = r.id
    if (not record_id):
        return None
    if (not context):
        query = None
    elif (type(context) is tuple):
        (context, field) = context
        query = (FS(context) == r.record[field])
    elif (context == 'location'):
        s = '(location)$path'
        m = ('%(id)s,%(id)s/*,*/%(id)s/*,*/%(id)s' % dict(id=record_id)).split(',')
        m = [f.replace('*', '%') for f in m]
        query = FS(s).like(m)
    else:
        s = ('(%s)' % context)
        query = (FS(s) == record_id)
    resource = current.s3db.resource(tablename, filter=query)
    r.customise_resource(tablename)
    return (resource, query)
