[table sort] should eval cubicweb:sortvalue to make it works properly
# copyright 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/>."""property sheets allowing configuration of the web ui"""__docformat__="restructuredtext en"importreimportosimportos.pathasospTYPE_CHECKS=[('STYLESHEETS',list),('JAVASCRIPTS',list),('STYLESHEETS_IE',list),('STYLESHEETS_PRINT',list),]classlazystr(object):def__init__(self,string,context):self.string=stringself.context=contextdef__str__(self):returnself.string%self.contextclassPropertySheet(dict):def__init__(self,cache_directory,**context):self._cache_directory=cache_directoryself.context=contextself.reset()context['sheet']=selfcontext['lazystr']=self.lazystrself._percent_rgx=re.compile('%(?!\()')deflazystr(self,str):returnlazystr(str,self)defreset(self):self.clear()self._ordered_propfiles=[]self._propfile_mtime={}self._sourcefile_mtime={}self._cache={}defload(self,fpath):scriptglobals=self.context.copy()scriptglobals['__file__']=fpathexecfile(fpath,scriptglobals,self)forname,typeinTYPE_CHECKS:ifnameinself:ifnotisinstance(self[name],type):msg="Configuration error: %s.%s should be a %s"%(fpath,name,type)raiseException(msg)self._propfile_mtime[fpath]=os.stat(fpath)[-2]self._ordered_propfiles.append(fpath)defneed_reload(self):forrid,(adirectory,rdirectory,mtime)inself._cache.items():ifos.stat(osp.join(rdirectory,rid))[-2]>mtime:delself._cache[rid]forfpath,mtimeinself._propfile_mtime.iteritems():ifos.stat(fpath)[-2]>mtime:returnTruereturnFalsedefreload(self):ordered_files=self._ordered_propfilesself.reset()forfpathinordered_files:self.load(fpath)defreload_if_needed(self):ifself.need_reload():self.reload()defprocess_resource(self,rdirectory,rid):try:returnself._cache[rid][0]exceptKeyError:cachefile=osp.join(self._cache_directory,rid)self.debug('caching processed %s/%s into %s',rdirectory,rid,cachefile)rcachedir=osp.dirname(cachefile)ifnotosp.exists(rcachedir):os.makedirs(rcachedir)sourcefile=osp.join(rdirectory,rid)content=file(sourcefile).read()# XXX replace % not followed by a paren by %% to avoid having to do# this in the source css file ?try:content=self.compile(content)exceptValueError,ex:self.error("can't process %s/%s: %s",rdirectory,rid,ex)adirectory=rdirectoryelse:stream=file(cachefile,'w')stream.write(content)stream.close()adirectory=self._cache_directoryself._cache[rid]=(adirectory,rdirectory,os.stat(sourcefile)[-2])returnadirectorydefcompile(self,content):returnself._percent_rgx.sub('%%',content)%self# these are overridden by set_log_methods below# only defining here to prevent pylint from complaininginfo=warning=error=critical=exception=debug=lambdamsg,*a,**kw:Nonefromcubicweb.webimportLOGGERfromlogilab.common.logging_extimportset_log_methodsset_log_methods(PropertySheet,LOGGER)