Changeset 12227 for main


Ignore:
Timestamp:
14 Dec 2014, 14:59:41 (10 years ago)
Author:
Henrik Bettermann
Message:

Setup html documents. This technique replaces the usage of the HTMLDisplayWidget.

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

Legend:

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

    r12225 r12227  
    3232from zope.schema.interfaces import ConstraintNotSatisfied, RequiredMissing
    3333from zope.formlib.textwidgets import BytesDisplayWidget
     34from zope.formlib.widget import renderElement
    3435from zope.security import checkPermission
    3536from waeup.ikoba.interfaces import MessageFactory as _
     
    4849
    4950from waeup.ikoba.documents.interfaces import (
    50     IDocumentsContainer, IPublicDocument, IDocumentsUtils)
     51    IDocumentsContainer, IPublicDocument, IHTMLDocument, IDocumentsUtils)
    5152
    5253grok.context(IIkobaObject) # Make IKofaObject the default context
     
    165166
    166167
     168class HTMLDocumentDisplayFormPage(DocumentDisplayFormPage):
     169    """ Page to display html document data
     170    """
     171    grok.context(IHTMLDocument)
     172    grok.template('htmldocumentpage')
     173
     174    @property
     175    def form_fields(self):
     176        return grok.AutoFields(self.context.form_fields_interface).omit(
     177            'html_dict', 'html_multilang')
     178
     179    @property
     180    def html(self):
     181        lang = self.request.cookies.get('ikoba.language')
     182        html = self.context.html_dict.get(lang,'')
     183        if html =='':
     184            portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     185            html = self.context.html_dict.get(portal_language,'')
     186        return html
     187
     188
    167189class DocumentManageFormPage(IkobaEditFormPage,
    168190                            LocalRoleAssignmentUtilityView):
     
    176198
    177199    taboneactions = [_('Save'),_('Cancel')]
    178     tabtwoactions1 = [_('Remove selected local roles')]
    179     tabtwoactions2 = [_('Add local role')]
     200    tabthreeactions1 = [_('Remove selected local roles')]
     201    tabthreeactions2 = [_('Add local role')]
    180202
    181203    deletion_warning = _('Are you sure?')
     
    204226    def delLocalRoles(self, **data):
    205227        return del_local_roles(self,2,**data)
     228
     229
     230class HTMLDocumentManageFormPage(DocumentManageFormPage):
     231    """ View to manage htmldocument data
     232    """
     233    grok.context(IHTMLDocument)
     234
     235    def _html_dict(self):
     236        value = getattr(self.context, 'html_multilang', '')
     237        parts = value.split('>>')
     238        elements = {}
     239        lang = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     240        for part in parts:
     241            if part[2:4] == u'<<':
     242                lang = part[0:2].lower()
     243                text = part[4:]
     244                elements[lang] = renderElement(u'div id="html"',
     245                    contents=text)
     246            else:
     247                text = part
     248                elements[lang] = renderElement(u'div id="html"',
     249                    contents=text)
     250        return elements
     251
     252    @action(_('Save'), style='primary')
     253    def save(self, **data):
     254        msave(self, **data)
     255        self.context.html_dict = self._html_dict()
     256        return
    206257
    207258
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/browser_templates/documentmanagepage.pt

    r12225 r12227  
    44  <ul class="tabs nav nav-tabs" data-tabs="tabs">
    55    <li class="active">
    6       <a href="#tab1" data-toggle="tab" i18n:translate="">Settings</a>
     6      <a href="#tab1" data-toggle="tab" i18n:translate="">Metadata</a>
    77    </li>
    88    <li>
     
    6464      <div tal:condition="view/availableActions">
    6565        <span tal:repeat="action view/actions" tal:omit-tag="">
    66           <input tal:condition="python:action.label in view.tabtwoactions1"
     66          <input tal:condition="python:action.label in view.tabthreeactions1"
    6767                 tal:replace="structure action/render"/>
    6868        </span>
     
    9191          <div tal:condition="view/availableActions">
    9292                <span tal:repeat="action view/actions" tal:omit-tag="">
    93                   <input tal:condition="python:action.label in view.tabtwoactions2"
     93                  <input tal:condition="python:action.label in view.tabthreeactions2"
    9494                         tal:replace="structure action/render"/>
    9595                </span>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/document.py

    r12225 r12227  
    153153    form_fields_interface = IHTMLDocument
    154154
     155    def __init__(self, *args, **kw):
     156        super(HTMLDocument, self).__init__(*args, **kw)
     157        self.html_dict = None
     158
    155159HTMLDocument = attrs_to_fields(HTMLDocument)
    156160
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12225 r12227  
    7070        """
    7171
     72    description = schema.Text(
     73        title = _(u'Description'),
     74        required = False,
     75        )
    7276
    7377
     
    8387    """
    8488
     89    html_dict = Attribute('Content as language dictionary with values in html format')
     90
     91    html_multilang = schema.Text(
     92        title = _(u'Content in HTML format'),
     93        required = False,
     94        )
     95
    8596
    8697class IDocumentsUtils(Interface):
Note: See TracChangeset for help on using the changeset viewer.