本文整理汇总了Python中Products.ZCatalog.interfaces.ICatalogBrain.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python ICatalogBrain.providedBy方法的具体用法?Python ICatalogBrain.providedBy怎么用?Python ICatalogBrain.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ZCatalog.interfaces.ICatalogBrain
的用法示例。
在下文中一共展示了ICatalogBrain.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_scaled_img
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def _get_scaled_img(self, item, size):
request = getRequest()
if (
ICatalogBrain.providedBy(item) or
IContentListingObject.providedBy(item)
):
obj = item.getObject()
else:
obj = item
info = {}
if hasattr(obj, 'image'):
scales = getMultiAdapter((obj, request), name='images')
if size == 'small':
scale = scales.scale('image', width=300, height=300)
if size == 'medium':
scale = scales.scale('image', width=600, height=600)
if size == 'large':
scale = scales.scale('image', width=900, height=900)
else:
scale = scales.scale('image', width=1200, height=1200)
if scale is not None:
info['url'] = scale.url
info['width'] = scale.width
info['height'] = scale.height
else:
info['url'] = IMG
info['width'] = '1px'
info['height'] = '1px'
else:
info['url'] = IMG
info['width'] = '1px'
info['height'] = '1px'
return info
示例2: getContentUri
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def getContentUri(self, context):
#1. determine subject uri for context
# FIXME: use property, attribute, context absolute url
from Products.ZCatalog.interfaces import ICatalogBrain
if ICatalogBrain.providedBy(context):
uuid = context.UID
else:
context = aq_base(context)
uuid = IUUID(context, None)
if uuid is None:
# we probably deal with a new contet object that does not have an
# uuid yet let's generate one
from plone.uuid.interfaces import IMutableUUID, IUUIDGenerator
generator = queryUtility(IUUIDGenerator)
if generator is None:
return # TODO: raise error
uuid = generator()
if not uuid:
return # TODO: raise error
IMutableUUID(context).set(uuid)
#url = base_uri + /@@redirect-to-uuid/<uuid>
#uri = context.subjecturi
# FIXME: shouldn't consult config here, IORDF does this.
try:
settings = getConfiguration().product_config.get('gu.plone.rdf', dict())
baseuri = settings['baseuri']
except Exception as e:
# FIXME: be specific about exceptions
baseuri = 'urn:plone:'
LOG.warn("No baseuri configured: using %s (%s)", baseuri, e)
contenturi = "%s%s" % (baseuri, uuid)
return contenturi
示例3: get_all_news_items
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_all_news_items(self):
local_news = list(self.get_local_news_items())
for news in local_news:
news['Date'] = (news['Date'] and DateTime(
news['Date'],
datefmt="international").strftime("%Y/%m/%d %H:%M") or "")
allnews = self.get_remote_news_items() + local_news
items = sorted(
allnews,
key=lambda item: item.__getitem__('Date'),
reverse=True
)
for i in range(0, len(items)):
if ICatalogBrain.providedBy(items[i]):
item = items[i]
obj = item.getObject()
has_image = getattr(obj.image, '_blob', False)
image_url = ''
if has_image:
image_url = obj.absolute_url() + "/@@images/image/preview"
items[i] = {
'Title': item.Title,
'Date': DateTime(item.Date).utcdatetime(),
'getURL': item.getURL(),
'Description': item.Description,
'text': obj.text and obj.text.output or "",
'image_url': image_url,
'image_caption': obj.image_caption if has_image else '',
'obj': obj,
'is_local': True,
}
else:
items[i]['Date'] = DateTime(items[i]['Date']).utcdatetime()
return items
示例4: _get_scaled_img
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def _get_scaled_img(self, item, size):
request = getRequest()
if ICatalogBrain.providedBy(item) or IContentListingObject.providedBy(item):
obj = item.getObject()
else:
obj = item
info = {}
if hasattr(obj, "image"):
scales = getMultiAdapter((obj, request), name="images")
if size == "small":
scale = scales.scale("image", width=300, height=300)
if size == "medium":
scale = scales.scale("image", width=600, height=600)
if size == "large":
scale = scales.scale("image", width=900, height=900)
else:
scale = scales.scale("image", width=1200, height=1200)
if scale is not None:
info["url"] = scale.url
info["width"] = scale.width
info["height"] = scale.height
else:
info["url"] = IMG
info["width"] = "1px"
info["height"] = "1px"
else:
info["url"] = IMG
info["width"] = "1px"
info["height"] = "1px"
return info
示例5: get_email2
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_email2(self, principal):
"""Returns the second email address of a `principal`.
"""
# inbox does not have a email
if isinstance(principal, types.StringTypes) and \
self.is_inbox(principal):
return None
# principal may be a contact brain
elif ICatalogBrain.providedBy(principal) and \
brain_is_contact(principal):
return principal.email2
# principal may be a user object
elif IUser.providedBy(principal) or isinstance(principal, UserDict):
return principal.email2
# principal may ba a string contact principal
elif self.is_contact(principal):
return self.get_contact(principal).email2
# principal may be a string user principal
elif self.is_user(principal):
return self.get_user(principal).email2
else:
raise ValueError('Unknown principal type: %s' %
str(principal))
示例6: linked
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def linked(item, value, with_tooltip=True):
"""Takes an item (object or brain) and returns a HTML snippet that
contains a link to the item, it's icon and breadcrumbs in the tooltip.
"""
if isinstance(value, unicode):
value = value.encode('utf-8')
# Determine URL and UID
url = get_url(item)
if ICatalogBrain.providedBy(item) or isinstance(item, SolrDocument):
uid = item.UID
else:
uid = IUUID(item)
# Construct CSS class
css_class = get_css_class(item)
# Make sure all data used in the HTML snippet is properly escaped
value = escape_html(value)
if with_tooltip:
css_class = "rollover-breadcrumb " + css_class
link = '<a class="%s" href="%s" data-uid="%s"><span>%s</span></a>' % (
css_class, url, uid, value)
wrapper = '<span class="linkWrapper">%s</span>' % link
return wrapper
示例7: get_uid
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_uid(value):
"""Takes a brain or object and returns a valid UID.
In this case, the object may come from portal_archivist, so we will
need to do a catalog query to get the UID of the current version
"""
if not value:
return ''
# Is value a brain?
if ICatalogBrain.providedBy(value):
value = value.getObject()
# validate UID
uid = value.UID()
uc = get_tool('uid_catalog')
if uc(UID=uid):
# The object is valid
return uid
# Otherwise the object is an old version
brains = uc(portal_type=value.portal_type, Title=value.Title())
if not brains:
# Cannot find UID
raise RuntimeError('The UID for %s/%s cannot be found!' %
(value.portal_type, value.Title()))
if len(brains) > 1:
# Found multiple objects, this is a failure
raise RuntimeError('Searching for %s/%s returned multiple objects.' %
(value.portal_type, value.Title()))
return brains[0].UID
示例8: get_uid
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_uid(obj):
""" get the UID of the brain/object
"""
if ICatalogBrain.providedBy(obj):
return obj.UID
if ISiteRoot.providedBy(obj):
return "siteroot"
return obj.UID()
示例9: get_type
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_type(self, item):
"""differ the object typ and return the type as string"""
if isinstance(item, dict):
return 'dict'
elif ICatalogBrain.providedBy(item):
return 'brain'
else:
return 'sqlalchemy_object'
示例10: construct_icalendar
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def construct_icalendar(context, events):
"""Returns an icalendar.Calendar object.
:param context: A content object, which is used for calendar details like
Title and Description. Usually a container, collection or
the event itself.
:param events: The list of event objects, which are included in this
calendar.
"""
cal = icalendar.Calendar()
cal.add('prodid', PRODID)
cal.add('version', VERSION)
cal_tz = default_timezone(context)
if cal_tz:
cal.add('x-wr-timezone', cal_tz)
tzmap = {}
if not hasattr(events, '__getslice__'): # LazyMap doesn't have __iter__
events = [events]
for event in events:
if ICatalogBrain.providedBy(event) or\
IContentListingObject.providedBy(event):
event = event.getObject()
acc = IEventAccessor(event)
tz = acc.timezone
# TODO: the standard wants each recurrence to have a valid timezone
# definition. sounds decent, but not realizable.
if not acc.whole_day: # whole day events are exported as dates without
# timezone information
tzmap = add_to_zones_map(tzmap, tz, acc.start)
tzmap = add_to_zones_map(tzmap, tz, acc.end)
cal.add_component(IICalendarEventComponent(event).to_ical())
for (tzid, transitions) in tzmap.items():
cal_tz = icalendar.Timezone()
cal_tz.add('tzid', tzid)
cal_tz.add('x-lic-location', tzid)
for (transition, tzinfo) in transitions.items():
if tzinfo['dst']:
cal_tz_sub = icalendar.TimezoneDaylight()
else:
cal_tz_sub = icalendar.TimezoneStandard()
cal_tz_sub.add('tzname', tzinfo['name'])
cal_tz_sub.add('dtstart', transition)
cal_tz_sub.add('tzoffsetfrom', tzinfo['tzoffsetfrom'])
cal_tz_sub.add('tzoffsetto', tzinfo['tzoffsetto'])
# TODO: add rrule
# tzi.add('rrule',
# {'freq': 'yearly', 'bymonth': 10, 'byday': '-1su'})
cal_tz.add_component(cal_tz_sub)
cal.add_component(cal_tz)
return cal
示例11: is_brain
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def is_brain(brain_or_object):
"""Checks if the passed in object is a portal catalog brain
:param brain_or_object: A single catalog brain or content object
:type brain_or_object: ATContentType/DexterityContentType/CatalogBrain
:returns: True if the object is a catalog brain
:rtype: bool
"""
return ICatalogBrain.providedBy(brain_or_object)
示例12: renderCell
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def renderCell(self, card):
if ICatalogBrain.providedBy(card):
searchview = self.table.context
categories_display = searchview.getCategoryDisplay(card)
categories_display = u','.join([cat.decode('utf-8') for cat in categories_display])
else:
categories_display = ''
return categories_display
示例13: get_container_of_original
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_container_of_original(self, obj, manual=False):
""" If the obj is a working copy, return the container of the
original"""
if IHomeFolder.providedBy(self.context) or manual:
if ICatalogBrain.providedBy(obj):
obj = obj.getObject()
iterate_control = getMultiAdapter(
(obj, self.request), name='iterate_control')
original = iterate_control.get_original(obj)
if original:
return safe_unicode(Acquisition.aq_parent(original).Title())
return ""
示例14: get_parent
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def get_parent(obj, catalog_id='portal_catalog'):
""" Gets the parent of the obj or brain. The result is of the same type
as the parameter given.
"""
if ICatalogBrain.providedBy(obj):
catalog = api.portal.get_tool(catalog_id)
brains = catalog(
path={'query': '/'.join(obj.getPath().split('/')[:-1])}
)
return brains[0]
else:
return obj.aq_inner.aq_parent
示例15: __call__
# 需要导入模块: from Products.ZCatalog.interfaces import ICatalogBrain [as 别名]
# 或者: from Products.ZCatalog.interfaces.ICatalogBrain import providedBy [as 别名]
def __call__(self, context, field, options):
img = getattr(context, field)
if img:
if ICatalogBrain.providedBy(context):
baseurl = context.getURL()
else:
baseurl = context.absolute_url()
size = options.by(field).get('image_size', 'thumb')
url = '/'.join((baseurl, '@@images', field, size))
return self.template.substitute(url=url)
else:
return u''