source: main/waeup.kofa/branches/0.2/src/waeup/kofa/widgets/htmlwidget.py @ 17240

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

Add HTMLDisplayWidget which is now used for the frontpage by default.

Add frontpage.html default content.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1## $Id: htmlwidget.py 8361 2012-05-05 05:00:39Z henrik $
2##
3## Copyright (C) 2012 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.
8##
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.
13##
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 localized html.
19"""
20from zope.component import getUtility
21from zope.formlib.widget import renderElement, DisplayWidget
22from waeup.kofa.interfaces import IKofaUtils
23
24
25class HTMLDisplayWidget(DisplayWidget):
26    """Restructured Text widget.
27    """
28
29    def __call__(self):
30        """The HTMLDisplayWidget transforms an localizez HTML text string into
31        a dictionary.
32
33        Different languages must be separated by `>>xy<<` whereas
34        xy is the language code. Text parts without correct leading
35        language separator - usually the first part has no language
36        descriptor - are interpreted as texts in the portal's language.
37        The latter can be configured in waeup.srp.utils.utils.KofaUtils.
38        """
39        if self._renderedValueSet():
40            value = self._data
41        else:
42            value = self.context.default
43        if value == self.context.missing_value:
44            return {}
45        parts = value.split('>>')
46        elements = {}
47        lang = getUtility(IKofaUtils).PORTAL_LANGUAGE
48        for part in parts:
49            if part[2:4] == u'<<':
50                lang = part[0:2].lower()
51                text = part[4:]
52                elements[lang] = renderElement(u'div id="html"',
53                    contents=text)
54            else:
55                text = part
56                elements[lang] = renderElement(u'div id="html"',
57                    contents=text)
58        return elements
Note: See TracBrowser for help on using the repository browser.