def __call__(self): plone_view = self.context.restrictedTraverse('@@plone') portal_url = getToolByName(self.context, 'portal_url')() context_path = plone_view.getCurrentFolderUrl() return utils.relative_to_absolute_url_transform( compactify(self.index(), media=(u'screen',u'print',)), context_path, portal_url)
def _render_output_html(self): """ Return rendered newsletter with header+body+footer (raw html). """ enl = self.getNewsletter() # get out_template from ENL object and render it in context of issue out_template_pt_field = enl.getField('out_template_pt') ObjectField.set(out_template_pt_field, self, ZopePageTemplate( out_template_pt_field.getName(), enl.getRawOut_template_pt())) output_html = safe_portal_encoding(self.out_template_pt.pt_render()) output_html = compactify(output_html, filter_tags=False) return output_html
def _render_output_html(self): """ Return rendered newsletter with header+body+footer (raw html). """ enl = self.getNewsletter() # get out_template from ENL object and render it in context of issue out_template_pt_field = enl.getField('out_template_pt') ObjectField.set( out_template_pt_field, self, ZopePageTemplate(out_template_pt_field.getName(), enl.getRawOut_template_pt())) output_html = safe_portal_encoding(self.out_template_pt.pt_render()) output_html = compactify(output_html, filter_tags=False) return output_html
def compactify(html): """Make the html compact. We use stoneagehtml for this. We catch at least one error that can occur with some css code, that stoneagehtml tries to clean up using cssutils. See https://bugs.launchpad.net/singing-dancing/+bug/410238 We also return utf-8. """ try: html = stoneagehtml.compactify(html, filter_tags=False) except IndexError: logger.warn("Exception while compacting html with stoneagehtml; " "using original instead.") pass return html.decode('utf-8')
def getBody(self,base_url=''): """ Body of mail """ #default values diff=-1 body=None #acquire aggregator utility from collective.plone.reader aggregator=self.context aggr_util=getMultiAdapter((self.context, self.request), name=u'aggregator_utility_view') #get recurrence from aggregator field=aggregator.getField('recurrence') if field: recurrence=field.get(aggregator) diff=RECURRENCE.get(recurrence,-1) #get contents from aggregator filtered date and limit date_limit=DateTime()-diff list_of_contents=aggr_util.getFavoritesByAggregator_not_merged(aggregator,'all',date_limit=date_limit,size_limit=10) #list_of_contents is a dictionary <section>: <list of contents> #and I want to know how many children there are childern=sum([len(folder['childs']) for folder in list_of_contents.values()]) #if there's no children we have no mail if childern>0: template=self.context.restrictedTraverse('mail_template') html=template(self, list_of_contents=list_of_contents, recurrence=LABEL_CONVERTER.get(recurrence), aggregator_url=aggregator.absolute_url(),) #if base_url is sets we replace the url of the template if len(base_url)>0: fake_portal_path='http://foo%s'%'/'.join(self.plone_site.getPhysicalPath()) html=html.replace(fake_portal_path,base_url) body = stoneagehtml.compactify(html).decode('utf-8') return body
def _html(self, variables, **kwargs): html = self.template(**variables) return stoneagehtml.compactify(html, **kwargs).decode('utf-8')