~anybox/aeroo/openerp6

« back to all changes in this revision

Viewing changes to report_aeroo/ExtraFunctions.py

  • Committer: root
  • Date: 2013-05-16 15:46:46 UTC
  • Revision ID: root@erp.kndati.lv-20130516154646-5lesr8tyzl1vdc0k
1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
2
##############################################################################
3
3
#
4
 
# Copyright (c) 2009-2012 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
 
4
# Copyright (c) 2009-2013 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
5
5
#                    General contacts <info@alistek.com>
6
6
#
7
7
# WARNING: This program as such is intended to be used by professional
32
32
 
33
33
from barcode import barcode
34
34
from tools import translate
35
 
from currency_to_text import currency_to_text
 
35
#from currency_to_text import currency_to_text
 
36
from ctt_objects import supported_language
36
37
import base64
37
38
import StringIO
38
39
from PIL import Image
45
46
from tools.safe_eval import safe_eval as eval
46
47
from aeroolib.plugins.opendocument import _filter
47
48
 
 
49
try:
 
50
    from docutils.examples import html_parts # use python-docutils library
 
51
except ImportError, e:
 
52
    rest_ok = False
 
53
else:
 
54
    rest_ok = True
 
55
try:
 
56
    import markdown
 
57
    from markdown import Markdown # use python-markdown library
 
58
    from markdown.inlinepatterns import AutomailPattern
 
59
    
 
60
    class AutomailPattern_mod (AutomailPattern, object):
 
61
        def __init__(self, *args, **kwargs):
 
62
            super(AutomailPattern_mod, self).__init__(*args, **kwargs)
 
63
 
 
64
        def handleMatch(self, m):
 
65
            el = super(AutomailPattern_mod, self).handleMatch(m)
 
66
            href = ''.join([chr(int(a.replace(markdown.AMP_SUBSTITUTE+'#', ''))) for a in el.get('href').split(';') if a])
 
67
            el.set('href', href)
 
68
            return el
 
69
    
 
70
    markdown.inlinepatterns.AutomailPattern = AutomailPattern_mod # easy hack for correct displaying in Joomla
 
71
 
 
72
except ImportError, e:
 
73
    markdown_ok = False
 
74
else:
 
75
    markdown_ok = True
 
76
try:
 
77
    from mediawiki import wiki2html # use python-mediawiki library
 
78
except ImportError, e:
 
79
    wikitext_ok = False
 
80
else:
 
81
    wikitext_ok = True
 
82
 
48
83
def domain2statement(domain):
49
84
    statement=''
50
85
    operator=False
113
148
            'html_escape': self._html_escape,
114
149
            'http_prettyuri': self._http_prettyuri,
115
150
            'http_builduri': self._http_builduri,
 
151
            'text_markdown': markdown_ok and self._text_markdown or \
 
152
                self._text_plain('"markdown" format is not supported! Need to be installed "python-markdown" package.'),
 
153
            'text_restruct': rest_ok and self._text_restruct or \
 
154
                self._text_plain('"reStructuredText" format is not supported! Need to be installed "python-docutils" package.'),
 
155
            'text_wiki': wikitext_ok and self._text_wiki or \
 
156
                self._text_plain('"wikimarkup" format is not supported! Need to be installed "python-mediawiki" package.'),
 
157
            'text_markup': self._text_markup,
116
158
            '__filter': self.__filter, # Don't use in the report template!
117
159
        }
118
160
 
172
214
 
173
215
    def _currency2text(self, currency):
174
216
        def c_to_text(sum, currency=currency, language=None):
175
 
            return unicode(currency_to_text(sum, currency, language or self._get_lang()), "UTF-8")
 
217
            #return unicode(currency_to_text(sum, currency, language or self._get_lang()), "UTF-8")
 
218
            return unicode(supported_language.get(language or self._get_lang()).currency_to_text(sum, currency), "UTF-8")
176
219
        return c_to_text
177
220
 
178
221
    def _translate_text(self, source):
516
559
            result += '&%s=%s' % pair
517
560
        return result
518
561
 
 
562
    def _text_restruct(self, text):
 
563
        output = html_parts(unicode(text), doctitle=False)
 
564
        return output['body']
 
565
 
 
566
    def _text_markdown(self, text):
 
567
        md = Markdown()
 
568
        return md.convert(text)
 
569
 
 
570
    def _text_wiki(self, text):
 
571
        return wiki2html(text, True)
 
572
 
 
573
    def _text_plain(self, msg):
 
574
        def text_plain(text):
 
575
            netsvc.Logger().notifyChannel('report_aeroo', netsvc.LOG_INFO, msg)
 
576
            return text
 
577
        return text_plain
 
578
 
 
579
    def _text_markup(self, text):
 
580
        lines = text.splitlines()
 
581
        first_line = lines.pop(0)
 
582
        if first_line=='text/x-markdown':
 
583
            return self._text_markdown('\n'.join(lines))
 
584
        elif first_line=='text/x-wiki':
 
585
            return self._text_wiki('\n'.join(lines))
 
586
        elif first_line=='text/x-rst':
 
587
            return self._text_rest('\n'.join(lines))
 
588
        return text
 
589