reldefsecurity branch :
* follow yams default branch api changes
* now consider permissions on relation definitions, not relation types.
This is still experimental.
"""Specific views for email addresses entities:organization: Logilab:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"fromlogilab.mtconverterimportxml_escapefromcubicweb.schemaimportdisplay_namefromcubicweb.selectorsimportimplementsfromcubicweb.commonimportUnauthorizedfromcubicweb.web.viewsimportbaseviews,primaryclassEmailAddressPrimaryView(primary.PrimaryView):__select__=implements('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.req,'primary_email','object'),emailof.view('oneline'))pemaileid=emailof.eidelse:pemaileid=Nonetry:emailof='use_email'inself.schemaandentity.reverse_use_emailor()emailof=[eforeinemailofifnote.eid==pemaileid]exceptUnauthorized:emailof=[]ifemailof:emailofstr=', '.join(e.view('oneline')foreinemailof)self.field(display_name(self.req,'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__=implements('EmailAddress')id='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__=implements('EmailAddress')defcell_call(self,row,col,**kwargs):entity=self.rset.get_entity(row,col)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:'"""id='mailto'__select__=implements('EmailAddress')defcell_call(self,row,col,**kwargs):entity=self.rset.get_entity(row,col)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>')classEmailAddressTextView(baseviews.TextView):__select__=implements('EmailAddress')defcell_call(self,row,col,**kwargs):self.w(self.rset.get_entity(row,col).display_address())