是否可以在portal_catalog中查询将来的事件和当前正在运行的事件?
例如:
start >= now <= end or
start <= now <= end或者还有其他可能的查询?
Plone 4
plone.app.event
发布于 2016-05-25 22:08:13
plone目录的查询选项非常有限,KeywordIndex是唯一支持or运算符的索引
一种可能的解决方案是将其分成两个查询。
from DateTime import DateTime
query_current = {}
query_current['start'] = {'query': DateTime(),
'range': 'min'}
query_current['end'] = {'query': DateTime(),
'range': 'max'}
query_future = {}
query_future['start'] = {'query': DateTime(),
'range': 'min'}
query_future['end'] = {'query': DateTime(),
'range': 'min'}
items = list(portal_catalog(**query_current)) + list(portal_catalog(**query_future))这一点有很好的文档记录:http://docs.plone.org/4/en/develop/plone/searching_and_indexing/query.html#querying-by-date
另一种可能是Products.AdvancedQuery,但老实说,我从来没有用过它,因为我猜它不知何故死了--> http://www.dieter.handshake.de/pyprojects/zope/AdvancedQuery.html你可能无法安装它。
发布于 2016-05-26 05:19:30
谢谢,过几天我会试一试。
现在,这对我来说是可行的
now = localized_now(self.context)
now_timestamp = time.mktime(now.timetuple())
# get all events out of catalog
allEvents = portal_catalog(
portal_type="Event",
review_state="published",
sort_on='start',
path={'query': nav_root_path}
)
items = []
for i in allEvents:
obj = i.getObject()
start_timestamp = time.mktime(obj.start.timetuple())
end_timestamp = time.mktime(obj.end.timetuple())
if start_timestamp >= now_timestamp <= end_timestamp or\
start_timestamp <= now_timestamp <= end_timestamp:
items.append((i, i.start))https://stackoverflow.com/questions/37438746
复制相似问题