示例#1
0
 def get(self, instance, mimetype=None, raw=False, forceInline=False, **kwargs):
     data = TextField.get(self, instance)
     if(raw or (not forceInline)):
         return data
     if(isinstance(data, str) or isinstance(data, unicode)):
         try:
             doc = parseString( '<x>%s</x>' % data.strip() )
             root = doc.documentElement
             for child in root.childNodes:
                 if( (child.nodeType == child.TEXT_NODE) and 
                     child.data.strip() ):
                     break
                 elif( child.nodeType == child.ELEMENT_NODE ):
                     style = child.getAttribute('style')
                     child.setAttribute('style', u'display:inline;' + style)
                     ## IE hack start ##
                     child.appendChild( doc.createTextNode(' ') )
                     ## IE hack end ##
                     break
             tmp = ''
             for child in root.childNodes:
                 tmp += child.toxml()
             doc.unlink()                
             data = tmp
         except:
             pass
     return data
示例#2
0
 def colorise(self, instance, value, **kwargs):
     value = TextField.get(self, instance, mimetype='text/html', raw=1)
     if shasattr(value, 'transform'):
         data = value.transform(instance, 'text/plain')
     else:
         data = value
     colored_text = htmlHighlight(
         instance, decode(str(value), instance, **kwargs))
     setattr(instance, 'colored_%s' % self.getName(), colored_text)
示例#3
0
 def get(self, instance, mimetype=None, raw=False, **kwargs):
     name = 'colored_%s' % self.getName()
     if kwargs.has_key('schema') and not raw and hasattr(
             instance, name):
         colored_text = getattr(instance, name)
         return encode(colored_text, instance, **kwargs)
     return TextField.get(self,
                          instance,
                          mimetype=mimetype,
                          raw=raw,
                          **kwargs)
示例#4
0
文件: remotetext.py 项目: a25kk/stv2
 def get(self, instance, **kw):
     if self._isexpired(instance):
         self.set(instance)
     return TextField.get(self, instance, **kw)
示例#5
0
 def get(self, instance, **kw):
     if self._isexpired(instance):
         self.set(instance)
     return TextField.get(self, instance, **kw)