我有一个plone的4.0实例。我想列出文件夹中从今天开始或日期范围(开始日期和结束日期)包含今天日期的事件。我还需要向一个群发送电子邮件,邮件中列出了这些事件。我在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)
您可以使用集合来获取日期范围内包含今天的所有事件,对于邮件发送,您可以使用colective.contentures.mailtogroup。它还可以发送正文字段。如果这就是你想要的。