[view, plot] deprecate flot and encourage usage of the jqplot cube (closes #1625218)
# copyright 2003-2011 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 entities adapting to IDownloadable====================================================="""__docformat__="restructuredtext en"_=unicodefromlogilab.mtconverterimportBINARY_ENCODINGS,TransformError,xml_escapefromlogilab.common.deprecationimportclass_renamed,deprecatedfromcubicwebimporttagsfromcubicweb.viewimportEntityViewfromcubicweb.selectorsimport(one_line_rset,is_instance,match_context_prop,adaptable,has_mimetype)fromcubicweb.mttransformsimportENGINEfromcubicweb.webimportcomponent,httpcachefromcubicweb.web.viewsimportprimary,baseviews@deprecated('[3.10] use a custom IDownloadable adapter instead')defdownload_box(w,entity,title=None,label=None,footer=u''):req=entity._cww(u'<div class="sideBox">')iftitleisNone:title=req._('download')w(u'<div class="sideBoxTitle downloadBoxTitle"><span>%s</span></div>'%xml_escape(title))w(u'<div class="sideBox downloadBox"><div class="sideBoxBody">')w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'%(xml_escape(entity.cw_adapt_to('IDownloadable').download_url()),req.uiprops['DOWNLOAD_ICON'],req._('download icon'),xml_escape(labelorentity.dc_title())))w(u'%s</div>'%footer)w(u'</div></div>\n')classDownloadBox(component.EntityCtxComponent):"""add download box"""__regid__='download_box'# no download box for images__select__=(component.EntityCtxComponent.__select__&adaptable('IDownloadable')&~has_mimetype('image/'))order=10title=_('download')definit_rendering(self):self.items=[self.entity]defrender_body(self,w):foriteminself.items:idownloadable=item.cw_adapt_to('IDownloadable')w(u'<a href="%s"><img src="%s" alt="%s"/> %s</a>'%(xml_escape(idownloadable.download_url()),self._cw.uiprops['DOWNLOAD_ICON'],self._cw._('download icon'),xml_escape(idownloadable.download_file_name())))classDownloadView(EntityView):"""download view this view is replacing the deprecated 'download' controller and allow downloading of entities providing the necessary interface """__regid__='download'__select__=one_line_rset()&adaptable('IDownloadable')templatable=Falsecontent_type='application/octet-stream'binary=Truehttp_cache_manager=httpcache.EntityHTTPCacheManageradd_to_breadcrumbs=Falsedefset_request_content_type(self):"""overriden to set the correct filetype and filename"""entity=self.cw_rset.complete_entity(self.cw_rowor0,self.cw_color0)adapter=entity.cw_adapt_to('IDownloadable')encoding=adapter.download_encoding()ifencodinginBINARY_ENCODINGS:contenttype='application/%s'%encodingencoding=Noneelse:contenttype=adapter.download_content_type()self._cw.set_content_type(contenttypeorself.content_type,filename=adapter.download_file_name(),encoding=encoding)defcall(self):entity=self.cw_rset.complete_entity(self.cw_rowor0,self.cw_color0)adapter=entity.cw_adapt_to('IDownloadable')self.w(adapter.download_data())deflast_modified(self):returnself.cw_rset.get_entity(self.cw_rowor0,self.cw_color0).modification_dateclassDownloadLinkView(EntityView):"""view displaying a link to download the file"""__regid__='downloadlink'__select__=adaptable('IDownloadable')title=None# should not be listed in possible viewsdefcell_call(self,row,col,title=None,**kwargs):entity=self.cw_rset.get_entity(row,col)url=xml_escape(entity.cw_adapt_to('IDownloadable').download_url())self.w(u'<a href="%s">%s</a>'%(url,xml_escape(titleorentity.dc_title())))classIDownloadablePrimaryView(primary.PrimaryView):__select__=adaptable('IDownloadable')defrender_entity_attributes(self,entity):self.w(u'<div class="content">')adapter=entity.cw_adapt_to('IDownloadable')contenttype=adapter.download_content_type()ifcontenttype.startswith('image/'):self._cw.add_js('cubicweb.image.js')self.wview('image',entity.cw_rset,row=entity.cw_row,col=entity.cw_col,link=True,klass='contentimage')super(IDownloadablePrimaryView,self).render_entity_attributes(entity)elifcontenttype.endswith('html'):self.wview('downloadlink',entity.cw_rset,title=self._cw._('download'),row=entity.cw_row)self.wview('ehtml',entity.cw_rset,row=entity.cw_row,col=entity.cw_col,height='600px',width='100%')else:super(IDownloadablePrimaryView,self).render_entity_attributes(entity)self.wview('downloadlink',entity.cw_rset,title=self._cw._('download'),row=entity.cw_row)self.render_data(entity,contenttype,'text/html')self.w(u'</div>')defrender_data(self,entity,sourcemt,targetmt):adapter=entity.cw_adapt_to('IDownloadable')ifENGINE.find_path(sourcemt,targetmt):try:self.w(entity._cw_mtc_transform(adapter.download_data(),sourcemt,targetmt,adapter.download_encoding()))exceptException,ex:self.exception('while rendering data for %s',entity)msg=self._cw._("can't display data, unexpected error: %s") \%xml_escape(unicode(ex))self.w('<div class="error">%s</div>'%msg)returnTruereturnFalseclassIDownloadableOneLineView(baseviews.OneLineView):__select__=adaptable('IDownloadable')defcell_call(self,row,col,title=None,**kwargs):"""the oneline view is a link to download the file"""entity=self.cw_rset.get_entity(row,col)url=xml_escape(entity.absolute_url())adapter=entity.cw_adapt_to('IDownloadable')name=xml_escape(titleorentity.dc_title())durl=xml_escape(adapter.download_url())self.w(u'<a href="%s">%s</a> [<a href="%s">%s</a>]'%(url,name,durl,self._cw._('download')))IDownloadableLineView=class_renamed('IDownloadableLineView',IDownloadableOneLineView,'[3.10] IDownloadableLineView is deprecated, use IDownloadableOneLineView')classAbstractEmbeddedView(EntityView):__abstract__=True_embedding_tag=Nonedefcall(self,**kwargs):rset=self.cw_rsetforiinxrange(len(rset)):self.w(u'<div class="efile">')self.wview(self.__regid__,rset,row=i,col=0,**kwargs)self.w(u'</div>')defcell_call(self,row,col,link=False,**kwargs):entity=self.cw_rset.get_entity(row,col)adapter=entity.cw_adapt_to('IDownloadable')tag=self._embedding_tag(src=adapter.download_url(),# pylint: disable=E1102alt=(self._cw._('download %s')%adapter.download_file_name()),**kwargs)iflink:self.w(u'<a href="%s">%s</a>'%(adapter.download_url(),tag))else:self.w(tag)classImageView(AbstractEmbeddedView):"""image embedded view"""__regid__='image'__select__=has_mimetype('image/')title=_('image')_embedding_tag=tags.imgclassEHTMLView(AbstractEmbeddedView):"""html embedded view"""__regid__='ehtml'__select__=has_mimetype('text/html')title=_('embedded html')_embedding_tag=tags.iframe