我有一个 4.0 的 plone 实例。我想列出从今天开始或日期范围(开始日期和结束日期)包含今天日期的文件夹中的事件。我还需要向组发送电子邮件,并在邮件中列出这些事件。我在 ZMI 添加了一个 Python 脚本,效果很好。唯一的问题是,当我发送邮件时,邮件中只列出了一个事件详细信息。我不知道如何迭代以便获得完整列表。请指导。
import datetime
folder_path = '/'.join(context.getPhysicalPath()) + '/events'
# Convert Date yyyy/mm/dd to dd month yyyy
now = DateTime().Date()
nowd = DateTime(now)
#dateList = [nowd10 - nowd10+margin]
#print dateList
#return printed
dt = nowd.strftime('%b %d,%Y')
now_date = DateTime(now)
query=context.portal_catalog(portal_type='Event',
start={'query': (nowd-10,nowd+1),
'range': 'min:max'})
results = context.portal_catalog(path={'query': folder_path, 'depth': 1})
folder_dict={}
for ev in results:
if ev.portal_type == 'Event':
loc = ev.location
stdt = ev.start.Date()
stdt = DateTime(stdt)
endt = ev.end.Date()
endt = DateTime(endt)
if nowd - 10 <= stdt <= nowd:
evobj = ev.getObject()
mydict = {}
mydict['absolute_url'] = evobj.absolute_url()
mydict['StartDate'] = stdt
mydict['EndDate'] = endt
mydict['Location'] = loc
msgbody = ""
for y, z in evobj.getMetadataHeaders():
mydict[y] = z
msgbody = """
Title: %(Title)s
Start: %(StartDate)s
End: %(EndDate)s
Event Location: %(Location)s
Link to Event page: %(absolute_url)s
""" % mydict
msgbody = msgbody + msgbody
# Send email
mFrom = "fromemail"
mTo = "to email"
mMsg = "Events for Today:"
mMsg += msgbody
mSubj = "Events " + dt
context.MailHost.send(mMsg, mTo, mFrom, mSubj)