def __call__(self,recurrence='',base_url=''): """ to use this call you may use this forms: http://<url_plone>/MailGenerator?base_url=<someurl> or http://<url_plone>/MailGenerator?base_url=<someurl>&recurrence=<recurrence> where <recurrence> is a key in RECURRENCE dictionary; base_url is the base for urls in mails In the first case, all mails are generated checking if recurrence is verified. In second case only for that recurrence """ self._log('Start with generation email') start_at=DateTime() pu=getToolByName(self.context,'portal_url') plone_site= pu.getPortalObject() #replace security manager to avoid any problem current_sm = getSecurityManager() owner = plone_site.getWrappedOwner() newSecurityManager(None, owner) #get catalog catalog=getToolByName(self.context,'portal_catalog') #get valid recurrences valid_values=RECURRENCE.keys() if recurrence in valid_values: valid_values=[recurrence] else: valid_values=filter_recurrence_by_date(DateTime()) #get all aggregators aggregators=catalog(portal_type='Aggregator') counter=0 for aggr in aggregators: obj=aggr.getObject() #try to get recurrence of aggregator (default is weekly) if getattr(obj,'recurrence','weekly') in valid_values: #get send method from aggregator send_method=getMultiAdapter((obj,self.request),name=u'sendMail') #send mail and make log result=send_method(base_url) if len(result): self._log(result) counter+=1 #end time stop_at=DateTime() diff=stop_at-start_at setSecurityManager(current_sm) #print reports in log self._log('Taked: %s'%diff) self._log('Generated mails: %d/%d'%(counter,len(aggregators))) self._log('End with generation email.') return "."