def _evaluate(self, object): aqType = self.AcquisitionType orgObj = object name = self.Name or self.id # determine value if not hasattr(object, "aq_acquire"): aqType = "implicit" # not wrapped elif hasattr(object.aq_base, name + "__index_aqType__"): aqType = getattr(object, name + "__index_aqType__") if aqType == "explicit": # work around bug in "aq_acquire" (has 'default' argument but ignores it) try: value = object.aq_explicit.aq_acquire(name, default=None) except AttributeError: value = None else: if aqType == "none": object = object.aq_base value = getattr(object, name, None) # allow acquisition for objets that explicitly called for it if value is Acquired: value = getattr(orgObj, name, None) # handle calls if safe_callable(value): callType = self.CallType if callType == "call": value = value() elif callType == "ignore": value = None return value
def _evaluate(self, object): aqType = self.AcquisitionType orgObj = object name = self.getName() # determine value if not hasattr(object, 'aq_acquire'): aqType = 'implicit' # not wrapped elif hasattr(object.aq_base, name + '__index_aqType__'): aqType = getattr(object, name + '__index_aqType__') if aqType == 'explicit': # work around bug in "aq_acquire" (has 'default' argument but ignores it) try: value = object.aq_explicit.aq_acquire(name, default=None) except AttributeError: value = None else: if aqType == 'none': object = object.aq_base value = getattr(object, name, None) # allow acquisition for objets that explicitly called for it if value is Acquired: value = getattr(orgObj, name, None) # handle calls if safe_callable(value): callType = self.CallType if callType == 'call': value = value() elif callType == 'ignore': value = None return value
def renderToList(self, allow_add): """Renders the items to a list. """ res = [] composite = aq_parent(aq_inner(aq_parent(aq_inner(self)))) editing = composite.isEditing() items = self.objectItems() if editing: mypath = escape('/'.join(self.getPhysicalPath())) for index in range(len(items)): name, obj = items[index] if editing and allow_add: tag = ('<div class="slot_target" target_path="%s" ' 'target_index="%d"></div>' % (mypath, index)) res.append(tag) try: if safe_callable(obj): text = obj() else: text = str(obj) except ConflictError: # Ugly ZODB requirement: don't catch ConflictErrors raise except: t, v = sys.exc_info()[:2] t = getattr(t, '__name__', t) text = "<code>%s</code>" % ( escape(('%s: %s' % (t, v))[:80])) if editing: path = escape('/'.join(obj.getPhysicalPath())) tag = '<div class="slot_element" source_path="%s">' % path else: # Output a <div> just to ensure that the element # is rendered as an HTML block in both editing mode # and rendering mode. tag = "<div>" res.append("%s\n%s\n</div>" % (tag, text)) if editing and allow_add: index = len(items) tag = ('<div class="slot_target" target_path="%s" ' 'target_index="%d"></div>' % (mypath, index)) res.append(tag) return res
def renderToList(self, allow_add): """Renders the items to a list. """ res = [] composite = aq_parent(aq_inner(aq_parent(aq_inner(self)))) editing = composite.isEditing() items = self.objectItems() if editing: mypath = escape('/'.join(self.getPhysicalPath())) for index in range(len(items)): name, obj = items[index] if editing and allow_add: tag = ('<div class="slot_target" target_path="%s" ' 'target_index="%d"></div>' % (mypath, index)) res.append(tag) try: if safe_callable(obj): text = obj() else: text = str(obj) except ConflictError: # Ugly ZODB requirement: don't catch ConflictErrors raise except: t, v = sys.exc_info()[:2] t = getattr(t, '__name__', t) text = "<code>%s</code>" % (escape(('%s: %s' % (t, v))[:80])) if editing: path = escape('/'.join(obj.getPhysicalPath())) tag = '<div class="slot_element" source_path="%s">' % path else: # Output a <div> just to ensure that the element # is rendered as an HTML block in both editing mode # and rendering mode. tag = "<div>" res.append("%s\n%s\n</div>" % (tag, text)) if editing and allow_add: index = len(items) tag = ('<div class="slot_target" target_path="%s" ' 'target_index="%d"></div>' % (mypath, index)) res.append(tag) return res
def renderInline(self): """Returns a representation of this object as a string. """ obj = self.dereference() name = self.template_name if not name: # Default to the first allowable inline template. names = self.listAllowableInlineTemplates() if names: name = names[0] if name and name != "call": template = obj.restrictedTraverse(str(name)) return template() # Special template name "call" means to call the object. if safe_callable(obj): return obj() return unicode(obj)
def renderInline(self): """Returns a representation of this object as a string. """ obj = self.dereference() name = self.template_name if not name: # Default to the first allowable inline template. names = self.listAllowableInlineTemplates() if names: name = names[0] if name and name != "call": template = obj.restrictedTraverse(str(name)) return template() # Special template name "call" means to call the object. if safe_callable(obj): return obj() return str(obj)
def renderInline(self): """Returns a representation of this object as a string. """ obj = self.dereference() template = self.template() if template is not None: if obj is not None: # Rewrap the template to give it the right context template = aq_base(template).__of__(obj) slot = aq_parent(aq_inner(self)) slots = aq_parent(aq_inner(slot)) composite = aq_parent(aq_inner(slots)) viewlet = self.getCurrentViewlet() return template(composite=composite, slots=slots, slot=slot, viewlet=viewlet) # No viewlet, try to call the object if safe_callable(obj): return obj() return str(obj)
def _evaluate(self,object): aqType= self.AcquisitionType; orgObj = object name= self.getName() # determine value if not hasattr(object,'aq_acquire'): aqType= 'implicit' # not wrapped elif hasattr(object.aq_base, name+'__index_aqType__'): aqType = getattr(object, name+'__index_aqType__') if aqType == 'explicit': # work around bug in "aq_acquire" (has 'default' argument but ignores it) try: value= object.aq_explicit.aq_acquire(name,default=None) except AttributeError: value= None else: if aqType == 'none': object= object.aq_base value= getattr(object,name,None) # allow acquisition for objets that explicitly called for it if value is Acquired: value = getattr(orgObj, name, None) # handle calls if safe_callable(value): callType= self.CallType if callType == 'call': value= value() elif callType == 'ignore': value= None return value
def renderInline(self): """Returns a representation of this object as a string. """ obj = self.dereference() # First we check if the current user has View permission of this # object. If not we return an empty string. mtool = getToolByName(self, 'portal_membership') if not mtool.checkPermission('View', obj): return '' template = self.template() if template is not None: if obj is not None: # Rewrap the template to give it the right context template = aq_base(template).__of__(obj) slot = aq_parent(aq_inner(self)) slots = aq_parent(aq_inner(slot)) composite = aq_parent(aq_inner(slots)) viewlet = self.getCurrentViewlet() return template(composite=composite, slots=slots, slot=slot, viewlet=viewlet) # No viewlet, try to call the object if safe_callable(obj): return obj() return str(obj)
def _evaluate(self, value, object): v = EvalAndCall.inheritedAttribute('_evaluate')(self, value, object) if safe_callable(v): v = v(value) return v
def _evaluate(self,value,object): v= EvalAndCall.inheritedAttribute('_evaluate')(self,value,object) if safe_callable(v): v= v(value) return v