示例#1
0
 def test_get_hit(self):
     om = self._makeOne()
     si1 = SimpleItem('1')
     om['1'] = si1
     got = om.get('1')
     self.assertTrue(aq_self(got) is si1)
     self.assertTrue(got.__parent__ is om)
示例#2
0
 def test_get_hit(self):
     om = self._makeOne()
     si1 = SimpleItem('1')
     om['1'] = si1
     got = om.get('1')
     self.assertTrue(aq_self(got) is si1)
     self.assertTrue(got.__parent__ is om)
def Listbox_getBrainValue(self, brain, obj, select, can_check_local_property, editable_field=None):
  """
  ListBox.py / getValueList
  """
  tales = False

  # Use a widget, if any.
  if editable_field is not None:
    # XXX we need to take care of whether the editable field is
    # a proxy field or not, because a proxy field may inherit a
    # tales expression from a template field, and the API is not
    # unified.
    get_tales = getattr(editable_field, 'get_recursive_tales',
                        editable_field.get_tales)
    tales = get_tales('default')
    if tales:
      default_field_value = editable_field.__of__(obj).get_value('default',
                                                                 cell=brain)

  # If a tales expression is not defined, get a skin, an accessor or a property.
  if not tales:
    if (can_check_local_property) and (getattr(aq_self(brain), select, None) is not None):
      default_field_value = getattr(brain, select)
    else:
      try:
        # Get the trailing part.
        try:
          property_id = select[select.rindex('.') + 1:]
        except ValueError:
          property_id = select
        try:
          accessor_name = 'get%s' % UpperCase(property_id)
          # Make sure the object have the attribute, and this is not
          # acquired, but still get the attribute on the acquisition wrapper
          getattr(aq_base(obj), accessor_name)
          default_field_value = getattr(obj, accessor_name)
        except AttributeError:
          default_field_value = getattr(obj, property_id, None)
      except (AttributeError, KeyError, Unauthorized):
        default_field_value = None

  # If the value is callable, evaluate it.
  if callable(default_field_value):
    try:
      try:
        default_field_value = default_field_value(brain=brain)
      except TypeError:
        default_field_value = default_field_value()
    except (ConflictError, RuntimeError):
      raise
    except Exception:
      default_field_value = None

  # Listbox.py forces result to be an empty string
  # This is not needed in hal
  # if default_field_value is None:
  #   default_field_value = ''

  return default_field_value
示例#4
0
def Listbox_getBrainValue(self, brain, obj, select, can_check_local_property, editable_field=None):
  """
  ListBox.py / getValueList
  """
  tales = False

  # Use a widget, if any.
  if editable_field is not None:
    # XXX we need to take care of whether the editable field is
    # a proxy field or not, because a proxy field may inherit a
    # tales expression from a template field, and the API is not
    # unified.
    get_tales = getattr(editable_field, 'get_recursive_tales',
                        editable_field.get_tales)
    tales = get_tales('default')
    if tales:
      default_field_value = editable_field.__of__(obj).get_value('default',
                                                                 cell=brain)

  # If a tales expression is not defined, get a skin, an accessor or a property.
  if not tales:
    if (can_check_local_property) and (getattr(aq_self(brain), select, None) is not None):
      default_field_value = getattr(brain, select)
    else:
      try:
        # Get the trailing part.
        try:
          property_id = select[select.rindex('.') + 1:]
        except ValueError:
          property_id = select
        try:
          accessor_name = 'get%s' % UpperCase(property_id)
          # Make sure the object have the attribute, and this is not
          # acquired, but still get the attribute on the acquisition wrapper
          getattr(aq_base(obj), accessor_name)
          default_field_value = getattr(obj, accessor_name)
        except AttributeError:
          default_field_value = getattr(obj, property_id, None)
      except (AttributeError, KeyError, Unauthorized):
        default_field_value = None

  # If the value is callable, evaluate it.
  if callable(default_field_value):
    try:
      try:
        default_field_value = default_field_value(brain=brain)
      except TypeError:
        default_field_value = default_field_value()
    except (ConflictError, RuntimeError):
      raise
    except:
      default_field_value = None

  # Listbox.py forces result to be an empty string
  # This is not needed in hal
  # if default_field_value is None:
  #   default_field_value = ''

  return default_field_value
示例#5
0
def _fix_content(site):
    """ Fix the tags in all objects in the site
    """
    # TODO: rename this function, needs better name

    catalog = site.portal_catalog

    searchTypes = [
        'eea.climateadapt.aceproject',
        'eea.climateadapt.adaptationoption',
        'eea.climateadapt.casestudy',
        'eea.climateadapt.guidancedocument',
        'eea.climateadapt.indicator',
        'eea.climateadapt.informationportal',
        'eea.climateadapt.mapgraphdataset',
        'eea.climateadapt.organisation',
        'eea.climateadapt.publicationreport',
        'eea.climateadapt.researchproject',
        'eea.climateadapt.tool',
    ]
    results = catalog.searchResults({'portal_type': searchTypes})

    for brain in results:
        obj = aq_self(brain.getObject())

        if not (hasattr(obj, 'special_tags')
                or hasattr(obj, 'specialtagging')):
            continue

        tags = []

        for attr in ['special_tags', 'specialtagging']:
            st = getattr(obj, attr, []) or []

            if isinstance(st, basestring):
                tags.append(st)
            else:
                tags.extend(st)

        tags = _fix_tags(tags)

        if tags:
            logger.info("Fixing tags on %s", brain.getURL())
            obj.special_tags = tags
            obj.reindexObject()
示例#6
0
def _fix_content(site):
    """ Fix the tags in all objects in the site
    """
    # TODO: rename this function, needs better name

    catalog = site.portal_catalog

    searchTypes = [
        'eea.climateadapt.aceproject',
        'eea.climateadapt.adaptationoption',
        'eea.climateadapt.casestudy',
        'eea.climateadapt.guidancedocument',
        'eea.climateadapt.indicator',
        'eea.climateadapt.informationportal',
        'eea.climateadapt.mapgraphdataset',
        'eea.climateadapt.organisation',
        'eea.climateadapt.publicationreport',
        'eea.climateadapt.researchproject',
        'eea.climateadapt.tool',
    ]
    results = catalog.searchResults({'portal_type': searchTypes})

    for brain in results:
        obj = aq_self(brain.getObject())

        if not (hasattr(obj, 'special_tags') or hasattr(obj, 'specialtagging')):
            continue

        tags = []
        for attr in ['special_tags', 'specialtagging']:
            st = getattr(obj, attr, []) or []
            if isinstance(st, basestring):
                tags.append(st)
            else:
                tags.extend(st)

        tags = _fix_tags(tags)

        if tags:
            logger.info("Fixing tags on %s", brain.getURL())
            obj.special_tags = tags
            obj.reindexObject()
示例#7
0
文件: metadata.py 项目: goschtl/zope
 def allow_discussion(self):
     context = aq_self(self.context)
     allow_discussion = getattr(context, 'allow_discussion', None)
     if allow_discussion is not None:
         allow_discussion = bool(allow_discussion)
     return allow_discussion
示例#8
0
    def getSite( self ):

        """ See ISetupContext.
        """
        return aq_self(self._site)
示例#9
0
    def getSite( self ):

        """ See ISetupContext.
        """
        return aq_self(self._site)
示例#10
0
 def allow_discussion(self):
     context = aq_self(self.context)
     allow_discussion = getattr(context, 'allow_discussion', None)
     if allow_discussion is not None:
         allow_discussion = bool(allow_discussion)
     return allow_discussion
示例#11
0
 def _getAllowDiscussion(self):
     context = aq_self(self.context)
     return getattr(context, 'allow_discussion', None)
示例#12
0
def Base_aqSelf(self):
    return aq_self(self)
示例#13
0
 def __init__(self, context):
     # De-wrap context when a Dexterity object is added
     # (taken from collective.geo.behaviour).
     if isinstance(context, ImplicitAcquisitionWrapper):
         context = aq_self(context)
     self.context = context
示例#14
0
 def __init__(self, context):
     # dewrap context when a Dexterity object is added
     if isinstance(context, ImplicitAcquisitionWrapper):
         context = aq_self(context)
     self.context = context
示例#15
0
 def __init__(self, context):
     # De-wrap context when a Dexterity object is added
     # (taken from collective.geo.behaviour).
     if isinstance(context, ImplicitAcquisitionWrapper):
         context = aq_self(context)
     self.context = context
示例#16
0
def Base_aqSelf(self):
  return aq_self(self)