Changeset 12229 for main


Ignore:
Timestamp:
14 Dec 2014, 15:45:55 (10 years ago)
Author:
Henrik Bettermann
Message:

We do not need the HTMLDisplayWidget. Use simple helper function instead. Tests will follow.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/layout.py

    r11958 r12229  
    201201            if 'address' in widget.name or \
    202202                'comment' in widget.name or \
     203                'description' in widget.name or \
    203204                'notice' in widget.name:
    204                 widget.height = 6
    205         if self.widgets.get('transcript_comment'):
    206             self.widgets['transcript_comment'].height = 12
    207         if self.widgets.get('jamb_subjects'):
    208             self.widgets['jamb_subjects'].height = 6
     205                widget.height = 3
    209206
    210207class IkobaAddFormPage(UtilityView,AddForm):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/browser/pages.py

    r12192 r12229  
    4242from zope.session.interfaces import ISession
    4343from zope.password.interfaces import IPasswordManager
     44from waeup.ikoba.utils.helpers import html2dict
    4445from waeup.ikoba.browser.layout import (
    4546    IkobaPage, IkobaForm, IkobaEditFormPage, IkobaAddFormPage,
     
    6061
    6162from waeup.ikoba.authentication import LocalRoleSetEvent
    62 from waeup.ikoba.widgets.htmlwidget import HTMLDisplayWidget
    6363from waeup.ikoba.utils.helpers import get_user_account, check_csv_charset
    6464from waeup.ikoba.mandates.mandate import PasswordMandate
     
    723723#
    724724
    725 class ConfigurationContainerDisplayFormPage(IkobaDisplayFormPage):
    726     """View page of the configuration container.
    727     """
    728     grok.require('waeup.managePortalConfiguration')
    729     grok.name('view')
    730     grok.context(IConfigurationContainer)
    731     pnav = 0
    732     label = _(u'View portal configuration')
    733     form_fields = grok.AutoFields(IConfigurationContainer)
    734     form_fields['frontpage'].custom_widget = HTMLDisplayWidget
    735 
    736 
    737725class ConfigurationContainerManageFormPage(IkobaEditFormPage):
    738726    """Manage page of the configuration container. We always use the
     
    747735        'frontpage_dict')
    748736
    749     def _frontpage(self):
    750         view = ConfigurationContainerDisplayFormPage(
    751             self.context,self.request)
    752         view.setUpWidgets()
    753         return view.widgets['frontpage']()
    754 
    755737    @action(_('Save'), style='primary')
    756738    def save(self, **data):
    757739        msave(self, **data)
    758         self.context.frontpage_dict = self._frontpage()
     740        frontpage = getattr(self.context, 'frontpage', None)
     741        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     742        self.context.frontpage_dict = html2dict(frontpage, portal_language)
    759743        return
    760744
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser.py

    r12228 r12229  
    3232from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing
    3333from zope.formlib.textwidgets import BytesDisplayWidget
    34 from zope.formlib.widget import renderElement
    3534from zope.security import checkPermission
     35from waeup.ikoba.utils.helpers import html2dict
    3636from waeup.ikoba.interfaces import MessageFactory as _
    3737from waeup.ikoba.interfaces import (
     
    233233    grok.context(IHTMLDocument)
    234234
    235     def _html_dict(self):
    236         value = getattr(self.context, 'html_multilang', None)
    237         if not value:
    238             return {}
    239         parts = value.split('>>')
    240         elements = {}
    241         lang = getUtility(IIkobaUtils).PORTAL_LANGUAGE
    242         for part in parts:
    243             if part[2:4] == u'<<':
    244                 lang = part[0:2].lower()
    245                 text = part[4:]
    246                 elements[lang] = renderElement(u'div id="html"',
    247                     contents=text)
    248             else:
    249                 text = part
    250                 elements[lang] = renderElement(u'div id="html"',
    251                     contents=text)
    252         return elements
    253 
    254235    @action(_('Save'), style='primary')
    255236    def save(self, **data):
    256237        msave(self, **data)
    257         self.context.html_dict = self._html_dict()
     238        html_multilang = getattr(self.context, 'html_multilang', None)
     239        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     240        self.context.html_dict = html2dict(html_multilang, portal_language)
    258241        return
    259242
  • main/waeup.ikoba/trunk/src/waeup/ikoba/utils/helpers.py

    r11949 r12229  
    3939from zope.security.management import getInteraction
    4040from zope.pluggableauth.interfaces import IAuthenticatorPlugin
     41from zope.formlib.widget import renderElement
    4142
    4243BUFSIZE = 8 * 1024
     
    804805        result[key] = value
    805806    return result
     807
     808
     809def html2dict(value=None,portal_language='en'):
     810    """Transforms a localized HTML text string into a dictionary.
     811
     812    Different languages must be separated by `>>xy<<` whereas
     813    xy is the language code. Text parts without correct leading
     814    language separator - usually the first part has no language
     815    descriptor - are interpreted as texts in the portal's language.
     816    The latter can be configured in waeup.srp.utils.utils.IkobaUtils.
     817    """
     818    try:
     819        parts = value.split('>>')
     820    except:
     821        return {}
     822    elements = {}
     823    lang = portal_language
     824    for part in parts:
     825        if part[2:4] == u'<<':
     826            lang = part[0:2].lower()
     827            text = part[4:]
     828            elements[lang] = renderElement(u'div id="html"',
     829                contents=text)
     830        else:
     831            text = part
     832            elements[lang] = renderElement(u'div id="html"',
     833                contents=text)
     834    return elements
Note: See TracChangeset for help on using the changeset viewer.