'Finds X_FRAME_OPTION from tree if inherited'

def get_xframe_options(self):

    xframe_options = get_xframe_cache(self)
    if (xframe_options is None):
        xframe_options = self.xframe_options
        if ((not xframe_options) or (xframe_options == self.X_FRAME_OPTIONS_INHERIT)):
            ancestors = self.get_ancestors()
            ancestors = ancestors.exclude(xframe_options=self.X_FRAME_OPTIONS_INHERIT)
            xframe_options = list(reversed(ancestors.values_list('xframe_options', flat=True)))
            if (self.xframe_options != self.X_FRAME_OPTIONS_INHERIT):
                xframe_options.append(self.xframe_options)
            if (len(xframe_options) <= 0):
                return None
            xframe_options = xframe_options[0]
        set_xframe_cache(self, xframe_options)
    return xframe_options
