Beispiel #1
0
def CMFCoreSkinnableSkinnableObjectManager___getattr__(self, name):
  '''
    Looks for the name in an object with wrappers that only reach
    up to the root skins folder.
    This should be fast, flexible, and predictable.
  '''
  if name[:1] != '_' and name[:3] != 'aq_':
    skin_info = SKINDATA.get(get_ident())
    if skin_info is not None:
      skin_selection_name, ignore, resolve = skin_info
      try:
        return resolve[name]
      except KeyError:
        if name not in ignore:
          try:
            portal_skins = aq_base(self.portal_skins)
          except AttributeError:
            raise AttributeError, name
          try:
            skin_selection_mapping = portal_skins._v_skin_location_list
          except AttributeError:
            LOG('Skinnable Monkeypatch __getattr__', DEBUG, 'Initial skin cache fill. This should not happen often. Current thread id:%X' % (get_ident(), ))
            skin_selection_mapping = self.initializeCache()
          try:
            skin_folder_id = skin_selection_mapping[skin_selection_name][name]
          except KeyError:
            pass
          else:
            object = getattr(getattr(portal_skins, skin_folder_id), name, None)
            if object is not None:
              resolve[name] = object.aq_base
              return resolve[name]
            else:
              # We cannot find a document referenced in the cache.
              # Try to find if there is any other candidate in another
              # skin folder of lower priority.
              selection_dict = portal_skins._getSelections()
              candidate_folder_id_list = selection_dict[skin_selection_name].split(',')
              previous_skin_folder_id = skin_selection_mapping[skin_selection_name][name]
              del skin_selection_mapping[skin_selection_name][name]
              if previous_skin_folder_id in candidate_folder_id_list:
                previous_skin_index = candidate_folder_id_list.index(previous_skin_folder_id)
                candidate_folder_id_list = candidate_folder_id_list[previous_skin_index + 1:]
              for candidate_folder_id in candidate_folder_id_list:
                candidate_folder = getattr(portal_skins, candidate_folder_id, None)
                if candidate_folder is not None:
                  object = getattr(candidate_folder, name, None)
                  if object is not None:
                    skin_selection_mapping[skin_selection_name][name] = candidate_folder_id
                    resolve[name] = object.aq_base
                    return resolve[name]
                else:
                  LOG('__getattr__', WARNING, 'Skin folder %s is in selection list '\
                      'but does not exist.' % (candidate_folder_id, ))
          ignore[name] = None
  if superGetAttr is None:
    raise AttributeError, name
  return superGetAttr(self, name)
Beispiel #2
0
 def __del__(self):
   tid = self.tid
   if SKINDATA is None:
     return
   skindata = SKINDATA.get(tid)
   if skindata is not None:
     if self.hashSkinData(skindata) == self.skindata_id:
       try:
         # Entry might have already disapeared. Ignore.
         del SKINDATA[tid]
       except KeyError:
         pass
def skinnable_getattr(self, name):
    """ """
    sd = SKINDATA.get(get_ident())
    if sd is not None:
        ob, skinname, ignore, resolve = sd
        if not name in ignore:
            if name in resolve:
                return resolve[name]
            subob = getattr(ob, name, _MARKER)
            if subob is not _MARKER:
                retval = aq_base(subob)
                resolve[name] = retval
                return retval
            else:
                ignore[name] = 1
    raise AttributeError, name
Beispiel #4
0
def CMFCoreSkinnableSkinnableObjectManager___getattr__(self, name):
  '''
    Looks for the name in an object with wrappers that only reach
    up to the root skins folder.
    This should be fast, flexible, and predictable.
  '''
  if name[:1] != '_' and name[:3] != 'aq_':
    skin_info = SKINDATA.get(get_ident())
    if skin_info is not None:
      _, skin_selection_name, ignore, resolve = skin_info
      try:
        return resolve[name]
      except KeyError:
        if name not in ignore:
          object = skinResolve(self, skin_selection_name, name)
          if object is not None:
            resolve[name] = object
            return object
          ignore[name] = None
  raise AttributeError(name)
Beispiel #5
0
    def getTemplateField(self, cache=True):
        """
    Return template field of the proxy field.
    """
        if cache is True:
            tales = self.tales
            if self._p_oid is None or tales['field_id'] or tales['form_id']:
                cache = False
            else:
                try:
                    return self._getTemplateFieldCache()
                except KeyError:
                    pass

        portal = self.getPortalObject()
        portal_skins = portal.portal_skins
        form = self.aq_parent
        object = form.aq_parent

        form_id = self.get_value('form_id')
        proxy_field = None
        form_id_with_skin_folder_name_flag = False
        if '/' in form_id:
            # If a / is in the form_id, it means that skin_folder is explicitly
            # defined. If so, prevent acquisition to get the form.
            form_id_with_skin_folder_name_flag = True
            proxy_form = aq_base(portal_skins).unrestrictedTraverse(
                form_id, None)
            if proxy_form is not None:
                proxy_form = portal_skins.unrestrictedTraverse(form_id)
        else:
            proxy_form = getattr(object, form_id, None)

        if (proxy_form is not None):
            field_id = self.get_value('field_id')
            proxy_field = proxy_form._getOb(field_id, None)
            if proxy_field is None:
                if form_id_with_skin_folder_name_flag is False:
                    # Try to get the field from another field library with a lower
                    # priority.
                    # This should return no field if the skin folder name is defined in
                    # form_id.
                    skin_info = SKINDATA.get(get_ident())

                    if skin_info is not None:
                        skin_selection_name, ignore, resolve = skin_info

                        selection_dict = portal_skins._getSelections()
                        candidate_folder_id_list = selection_dict[
                            skin_selection_name].split(',')

                        for candidate_folder_id in candidate_folder_id_list:
                            candidate_folder = portal_skins._getOb(
                                candidate_folder_id, None)
                            if candidate_folder is not None:
                                proxy_form = candidate_folder._getOb(
                                    form_id, None)
                                if proxy_form is not None:
                                    proxy_field = proxy_form._getOb(
                                        field_id, None)
                                    if proxy_field is not None:
                                        break

        if proxy_field is None:
            LOG('ProxyField', WARNING,
                'Could not get a field from a proxy field %s in %s' % \
                    (self.id, object.id))
        if cache is True:
            self._setTemplateFieldCache(proxy_field)
        return proxy_field
Beispiel #6
0
 def tearDown(self):
     from Products.CMFCore.Skinnable import SKINDATA
     SKINDATA.clear()
     cleanUp()
Beispiel #7
0
 def tearDown(self):
     from Products.CMFCore.Skinnable import SKINDATA
     SKINDATA.clear()
     cleanUp()
Beispiel #8
0
  def getTemplateField(self, cache=True):
    """
    Return template field of the proxy field.
    """
    if cache is True:
      tales = self.tales
      if self._p_oid is None or tales['field_id'] or tales['form_id']:
        cache = False
      else:
        try:
          return self._getTemplateFieldCache()
        except KeyError:
          pass

    portal = self.getPortalObject()
    portal_skins = portal.portal_skins
    form = self.aq_parent
    object = form.aq_parent

    form_id = self.get_value('form_id')
    proxy_field = None
    form_id_with_skin_folder_name_flag = False
    if '/' in form_id:
      # If a / is in the form_id, it means that skin_folder is explicitly
      # defined. If so, prevent acquisition to get the form.
      form_id_with_skin_folder_name_flag = True
      proxy_form = aq_base(portal_skins).unrestrictedTraverse(form_id, None)
      if proxy_form is not None:
        proxy_form = portal_skins.unrestrictedTraverse(form_id)
    else:
      proxy_form = getattr(object, form_id, None)

    if (proxy_form is not None):
      field_id = self.get_value('field_id')
      proxy_field = proxy_form._getOb(field_id, None)
      if proxy_field is None:
        if form_id_with_skin_folder_name_flag is False:
          # Try to get the field from another field library with a lower
          # priority.
          # This should return no field if the skin folder name is defined in
          # form_id.
          skin_info = SKINDATA.get(get_ident())

          if skin_info is not None:
            skin_selection_name, ignore, resolve = skin_info

            selection_dict = portal_skins._getSelections()
            candidate_folder_id_list = selection_dict[skin_selection_name].split(',')

            for candidate_folder_id in candidate_folder_id_list:
              candidate_folder = portal_skins._getOb(candidate_folder_id, None)
              if candidate_folder is not None:
                proxy_form = candidate_folder._getOb(form_id, None)
                if proxy_form is not None:
                  proxy_field = proxy_form._getOb(field_id, None)
                  if proxy_field is not None:
                    break

    if proxy_field is None:
      LOG('ProxyField', WARNING, 
          'Could not get a field from a proxy field %s in %s' % \
              (self.id, object.id))
    if cache is True:
      self._setTemplateFieldCache(proxy_field)
    return proxy_field
Beispiel #9
0
    def getTemplateField(self, cache=True):
        """
    Return template field of the proxy field.
    """
        if cache:
            tales = self.tales
            if self._p_oid is None or tales['field_id'] or tales['form_id']:
                cache = False
            else:
                try:
                    return self._getTemplateFieldCache()
                except KeyError:
                    pass

        portal = self.getPortalObject()
        portal_skins = portal.portal_skins
        form = self.aq_parent
        object = form.aq_parent

        form_id = self.get_value('form_id')
        proxy_field = None
        form_id_with_skin_folder_name_flag = False
        if '/' in form_id:
            # If a / is in the form_id, it means that skin_folder is explicitly
            # defined. If so, prevent acquisition to get the form.
            form_id_with_skin_folder_name_flag = True
            proxy_form = aq_base(portal_skins).unrestrictedTraverse(
                form_id, None)
            if proxy_form is not None:
                proxy_form = portal_skins.unrestrictedTraverse(form_id)
        else:
            proxy_form = getattr(object, form_id, None)

        if (proxy_form is not None):
            field_id = self.get_value('field_id')
            proxy_field = proxy_form._getOb(field_id, None)
            if proxy_field is None:
                if form_id_with_skin_folder_name_flag is False:
                    # Try to get the field from another field library with a lower
                    # priority.
                    # This should return no field if the skin folder name is defined in
                    # form_id.
                    skin_info = SKINDATA.get(get_ident())

                    if skin_info is not None:
                        _, skin_selection_name, ignore, resolve = skin_info

                        selection_dict = portal_skins._getSelections()
                        candidate_folder_id_list = selection_dict[
                            skin_selection_name].split(',')

                        for candidate_folder_id in candidate_folder_id_list:
                            candidate_folder = portal_skins._getOb(
                                candidate_folder_id, None)
                            if candidate_folder is not None:
                                proxy_form = candidate_folder._getOb(
                                    form_id, None)
                                if proxy_form is not None:
                                    # proxy_form was retrieved outside of skin magic, fake the
                                    # acquisition context skin magic would have produced so it
                                    # works the same (ex: for acquired permissions).
                                    # The drawback is that the form the field is actually comming
                                    # from will be harder to identify, but that's just how skins
                                    # work.
                                    proxy_field = aq_base(proxy_form).__of__(
                                        portal)._getOb(
                                            field_id,
                                            None,
                                        )
                                    if proxy_field is not None:
                                        break

        if proxy_field is None:
            LOG('ProxyField', WARNING,
                'Could not get a field from a proxy field %s in %s' % \
                    (self.id, object.id))
        if cache:
            self._setTemplateFieldCache(proxy_field)
        return proxy_field