@staticmethod
    def _resolve_context(r, tablename, context):
        """
            Resolve a context filter

            @param context: the context (as a string)
            @param id: the record_id
        """

        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":
            # Show records linked to this Location & all it's Child Locations
            s = "(location)$path"
            # This version doesn't serialize_url
            #m = ("%(id)s/*,*/%(id)s/*" % dict(id=id)).split(",")
            #filter = (FS(s).like(m)) | (FS(s) == id)
            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))
        # @ToDo:
        #elif context == "organisation":
        #    # Show records linked to this Organisation and all it's Branches
        #    s = "(%s)" % context
        #    query = (FS(s) == id)
        else:
            # Normal: show just records linked directly to this master resource
            s = "(%s)" % context
            query = (FS(s) == record_id)

        # Define target resource
        resource = current.s3db.resource(tablename, filter=query)
        r.customise_resource(tablename)
        return resource, query

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3/s3profile.py/S3Profile._resolve_context/original