source: main/waeup.sirp/trunk/src/waeup/sirp/widgets/restwidget.py @ 11105

Last change on this file since 11105 was 7705, checked in by Henrik Bettermann, 13 years ago

Backup translation work in progress.

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[7196]1## $Id: restwidget.py 7705 2012-02-26 16:34:10Z henrik $
[6063]2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
[7196]8##
[6063]9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
[7196]13##
[6063]14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""A widget that renders restructured text.
19"""
[7702]20from zope.component import getUtility
[6063]21from zope.formlib.widget import renderElement, DisplayWidget
22from waeup.sirp.utils.helpers import ReST2HTML
[7702]23from waeup.sirp.interfaces import ISIRPUtils
[6063]24
25
[6084]26class ReSTDisplayWidget(DisplayWidget):
[6063]27    """Restructured Text widget.
28    """
29
30    def __call__(self):
[7702]31        """The ReSTDisplayWidget transforms a ReST text string into
32        a dictionary.
33
[7705]34        Different languages must be separated by `>>xy<<` whereas
[7702]35        xy is the language code. Text parts without correct leading
36        language separator - usually the first part has no language
37        descriptor - are interpreted as texts in the portal's language.
38        The latter can be configured in waeup.srp.utils.utils.SIRPUtils.
39        """
[6063]40        if self._renderedValueSet():
41            value = self._data
42        else:
43            value = self.context.default
44        if value == self.context.missing_value:
[7703]45            return {}
[7702]46        parts = value.split('>>')
47        elements = {}
48        lang = getUtility(ISIRPUtils).PORTAL_LANGUAGE
49        for part in parts:
50            if part[2:4] == u'<<':
51                lang = part[0:2].lower()
52                text = part[4:]
53                elements[lang] = renderElement(u'div id="rest"',
54                    contents=ReST2HTML(text))
55            else:
56                text = part
57                elements[lang] = renderElement(u'div id="rest"',
58                    contents=ReST2HTML(text))
59        return elements
Note: See TracBrowser for help on using the repository browser.