[web/views] Move massmailing to its own cube (closes #2788086)
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""Specific views for email addresses entities"""__docformat__="restructuredtext en"fromlogilab.mtconverterimportxml_escapefromcubicweb.schemaimportdisplay_namefromcubicweb.predicatesimportis_instancefromcubicwebimportUnauthorizedfromcubicweb.web.viewsimportuicfg,baseviews,primary,ibreadcrumbs_pvs=uicfg.primaryview_section_pvs.tag_subject_of(('*','use_email','*'),'attributes')_pvs.tag_subject_of(('*','primary_email','*'),'hidden')classEmailAddressPrimaryView(primary.PrimaryView):__select__=is_instance('EmailAddress')defcell_call(self,row,col,skipeids=None):self.skipeids=skipeidssuper(EmailAddressPrimaryView,self).cell_call(row,col)defrender_entity_attributes(self,entity):self.w(u'<h3>')entity.view('oneline',w=self.w)ifentity.prefered:self.w(u' (<i>%s</i>)'%entity.prefered.view('oneline'))self.w(u'</h3>')try:persons=entity.reverse_primary_emailexceptUnauthorized:persons=[]ifpersons:emailof=persons[0]self.field(display_name(self._cw,'primary_email','object'),emailof.view('oneline'))pemaileid=emailof.eidelse:pemaileid=Nonetry:emailof='use_email'inself._cw.vreg.schemaandentity.reverse_use_emailor()emailof=[eforeinemailofifnote.eid==pemaileid]exceptUnauthorized:emailof=[]ifemailof:emailofstr=', '.join(e.view('oneline')foreinemailof)self.field(display_name(self._cw,'use_email','object'),emailofstr)defrender_entity_relations(self,entity):fori,emailinenumerate(entity.related_emails(self.skipeids)):self.w(u'<div class="%s">'%(i%2and'even'or'odd'))email.view('oneline',w=self.w,contexteid=entity.eid)self.w(u'</div>')classEmailAddressShortPrimaryView(EmailAddressPrimaryView):__select__=is_instance('EmailAddress')__regid__='shortprimary'title=None# hidden viewdefrender_entity_attributes(self,entity):self.w(u'<h5>')entity.view('oneline',w=self.w)self.w(u'</h5>')classEmailAddressOneLineView(baseviews.OneLineView):__select__=is_instance('EmailAddress')defentity_call(self,entity,**kwargs):ifentity.reverse_primary_email:self.w(u'<b>')ifentity.alias:self.w(u'%s <'%xml_escape(entity.alias))self.w('<a href="%s">%s</a>'%(xml_escape(entity.absolute_url()),xml_escape(entity.display_address())))ifentity.alias:self.w(u'>\n')ifentity.reverse_primary_email:self.w(u'</b>')classEmailAddressMailToView(baseviews.OneLineView):"""A one line view that builds a user clickable URL for an email with 'mailto:'"""__regid__='mailto'__select__=is_instance('EmailAddress')defentity_call(self,entity,**kwargs):ifentity.reverse_primary_email:self.w(u'<b>')ifentity.alias:alias=entity.aliaselifentity.reverse_use_email:alias=entity.reverse_use_email[0].dc_title()else:alias=Noneifalias:mailto="mailto:%s <%s>"%(alias,entity.display_address())else:mailto="mailto:%s"%entity.display_address()self.w(u'<a href="%s">%s</a>'%(xml_escape(mailto),xml_escape(entity.display_address())))ifentity.reverse_primary_email:self.w(u'</b>')classEmailAddressInContextView(baseviews.InContextView):__select__=is_instance('EmailAddress')defcell_call(self,row,col,**kwargs):ifself._cw.vreg.config['mangle-emails']:self.wview('oneline',self.cw_rset,row=row,col=col,**kwargs)else:self.wview('mailto',self.cw_rset,row=row,col=col,**kwargs)classEmailAddressTextView(baseviews.TextView):__select__=is_instance('EmailAddress')defcell_call(self,row,col,**kwargs):self.w(self.cw_rset.get_entity(row,col).display_address())classEmailAddressIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):__select__=is_instance('EmailAddress')defparent_entity(self):returnself.entity.email_of