~ubuntu-branches/debian/squeeze/openerp-server/squeeze

« back to all changes in this revision

Viewing changes to bin/report/render/html2html/html2html.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-08-24 20:16:55 UTC
  • mfrom: (8.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090824201655-vxt26g90x7geu29t
* Merging upstream version 5.0.3-0.
* Removing xmlrpc.patch, went upstream.
* Using dedicated storage directory in /var/lib/openerp-server, that
  way the addons directory can stay read-only for the unprivileged
  user.
* Commenting out db_name in config (Closes: #542391).
* Commenting out port in config (Closes: #542406).
* Renaming logfile to openerp-server.log for consistency.
* Commenting out pidfile in config (Closes: #542427).
* Removing debconf handling in postrm, not possible to do that.
* Removing local storage directory on purge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from reportlab.lib.utils import ImageReader
31
31
 
32
32
_regex = re.compile('\[\[(.+?)\]\]')
33
 
 
 
33
utils._regex = re.compile('\[\[\s*(.+?)\s*\]\]',re.DOTALL)
34
34
class html2html(object):
35
35
    def __init__(self, html, localcontext):
36
36
        self.localcontext = localcontext
47
47
                new_node.append(new_child)
48
48
                if len(child):
49
49
                    for n in new_child:
 
50
                        new_child.text  = utils._process_text(self, child.text)
 
51
                        new_child.tail  = utils._process_text(self, child.tail)
50
52
                        new_child.remove(n)
51
53
                    process_text(child, new_child)
52
54
                else:
58
60
                                output = cStringIO.StringIO(base64.decodestring(src))
59
61
                                img = ImageReader(output)
60
62
                                (width,height) = img.getSize()
61
 
                                new_child.set('width',str(width))
62
 
                                new_child.set('height',str(height))
 
63
                                if not new_child.get('width'):
 
64
                                    new_child.set('width',str(width))
 
65
                                if not new_child.get('height') :
 
66
                                    new_child.set('height',str(height))
63
67
                            else :
64
68
                                new_child.getparent().remove(new_child)
65
69
                    new_child.text  = utils._process_text(self, child.text)
 
70
                    new_child.tail  = utils._process_text(self, child.tail)
66
71
        self._node = copy.deepcopy(self.etree)
67
72
        for n in self._node:
68
73
            self._node.remove(n)
69
74
        process_text(self.etree, self._node)
70
75
        return self._node
 
76
        
 
77
    def url_modify(self,root):
 
78
        for n in root.getchildren():
 
79
            if (n.text.find('<a ')>=0 or n.text.find('&lt;a')>=0) and n.text.find('href')>=0 and n.text.find('style')<=0 :
 
80
                node = (n.tag=='span' and n.getparent().tag=='u') and n.getparent().getparent() or ((n.tag=='span') and n.getparent()) or n
 
81
                style = node.get('color') and "style='color:%s; text-decoration: none;'"%node.get('color') or ''
 
82
                if n.text.find('&lt;a')>=0:
 
83
                    t = '&lt;a '
 
84
                else :
 
85
                    t = '<a '
 
86
                href = n.text.split(t)[-1]
 
87
                n.text = ' '.join([t,style,href])
 
88
            self.url_modify(n)
 
89
        return root
71
90
 
72
91
def parseString(node, localcontext = {}):
73
92
    r = html2html(node, localcontext)
74
 
    return r.render()
 
93
    root = r.render()
 
94
    root = r.url_modify(root)
 
95
    return root
75
96