Skip to content

Commit

Permalink
Merge pull request #120 from plone/richtext-behavior
Browse files Browse the repository at this point in the history
backport richtext behavior from Plone5 branch
  • Loading branch information
pbauer committed Feb 13, 2014
2 parents c3093b5 + cef8758 commit a76ffc3
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 52 deletions.
11 changes: 10 additions & 1 deletion plone/app/contenttypes/behaviors/configure.zcml
Expand Up @@ -42,11 +42,20 @@
marker=".collection.ISyndicatableCollection"
/>

<plone:behavior
title="RichText"
description="Adds richtext behavior"
provides=".richtext.IRichText"
factory=".richtext.RichText"
for="plone.dexterity.interfaces.IDexterityContent"
marker=".richtext.IRichText"
/>

<utility
component=".collection.MetaDataFieldsVocabularyFactory"
name="plone.app.contenttypes.metadatafields" />

<adapter factory=".collection.CollectionFeed"
for=".collection.ISyndicatableCollection" />

</configure>
</configure>
30 changes: 30 additions & 0 deletions plone/app/contenttypes/behaviors/richtext.py
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from plone.autoform.interfaces import IFormFieldProvider
from plone.dexterity.interfaces import IDexterityContent
from plone.app.textfield import RichText as RichTextField
from plone.supermodel import model
from zope.component import adapts
from zope.interface import alsoProvides, implements

from plone.app.contenttypes import _


class IRichText(model.Schema):

text = RichTextField(
title=_(u'Text', default=u'Text'),
description=u"",
required=False,
)
model.primary('text')


alsoProvides(IRichText, IFormFieldProvider)


class RichText(object):
implements(IRichText)
adapts(IDexterityContent)

def __init__(self, context):
self.context = context
Expand Up @@ -19,6 +19,7 @@
<element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/>
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/>
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.contenttypes.behaviors.richtext.IRichText"/>
<element value="plone.app.relationfield.behavior.IRelatedItems"/>
</property>

Expand Down
4 changes: 1 addition & 3 deletions plone/app/contenttypes/profiles/default/types/Document.xml
Expand Up @@ -24,13 +24,11 @@
<element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/>
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/>
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.contenttypes.behaviors.richtext.IRichText"/>
<element value="plone.app.relationfield.behavior.IRelatedItems"/>
<element value="plone.app.versioningbehavior.behaviors.IVersionable" />
<element value="plone.app.contenttypes.behaviors.tableofcontents.ITableOfContents"/>
</property>
<property name="schema"></property>
<property name="model_source"></property>
<property name="model_file">plone.app.contenttypes.schema:document.xml</property>
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
Expand Down
3 changes: 1 addition & 2 deletions plone/app/contenttypes/profiles/default/types/Event.xml
Expand Up @@ -20,8 +20,6 @@
<!-- Schema, class and security -->
<property name="klass">plone.app.contenttypes.content.Event</property>
<property name="schema"></property>
<property name="model_source"></property>
<property name="model_file">plone.app.contenttypes.schema:event.xml</property>
<property name="add_permission">plone.app.contenttypes.addEvent</property>

<!-- Enabled behaviors -->
Expand All @@ -34,6 +32,7 @@
<element value="plone.app.event.dx.behaviors.IEventSummary"/>
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="plone.app.contenttypes.behaviors.richtext.IRichText"/>
<element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/>
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/>
<element value="plone.app.relationfield.behavior.IRelatedItems"/>
Expand Down
4 changes: 1 addition & 3 deletions plone/app/contenttypes/profiles/default/types/News_Item.xml
Expand Up @@ -21,16 +21,14 @@
<property name="klass">plone.app.contenttypes.content.NewsItem</property>
<property name="behaviors">
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="plone.app.contenttypes.behaviors.richtext.IRichText"/>
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/>
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/>
<element value="plone.app.relationfield.behavior.IRelatedItems"/>
<element value="plone.app.contenttypes.behaviors.leadimage.ILeadImage"/>
<element value="plone.app.versioningbehavior.behaviors.IVersionable" />
</property>
<property name="schema"></property>
<property name="model_source"></property>
<property name="model_file">plone.app.contenttypes.schema:news_item.xml</property>
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
Expand Down
13 changes: 0 additions & 13 deletions plone/app/contenttypes/schema/document.xml

This file was deleted.

4 changes: 0 additions & 4 deletions plone/app/contenttypes/schema/event.xml

This file was deleted.

24 changes: 0 additions & 24 deletions plone/app/contenttypes/schema/news_item.xml

This file was deleted.

61 changes: 61 additions & 0 deletions plone/app/contenttypes/tests/test_behaviors_richtext.py
@@ -0,0 +1,61 @@
import unittest2 as unittest

from Products.CMFCore.utils import getToolByName
from plone.app.dexterity.testing import DEXTERITY_INTEGRATION_TESTING
from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.testing.z2 import Browser
from plone.dexterity.fti import DexterityFTI

from plone.app.contenttypes.behaviors.richtext import IRichText


class RichTextBase:
# subclass here
_behaviors = None
_portal_type = None

def _setupFTI(self):
fti = DexterityFTI(self._portal_type)
self.portal.portal_types._setObject(self._portal_type, fti)
fti.klass = 'plone.dexterity.content.Item'
fti.behaviors = self._behaviors


class RichTextBehaviorTests(RichTextBase, unittest.TestCase):
""" basic use cases and tests for richtext behavior"""

layer = DEXTERITY_INTEGRATION_TESTING

_behaviors = (
'plone.app.contenttypes.behaviors.richtext.IRichText',)
_portal_type = 'SomeDocument'

def setUp(self):
app = self.layer['app']
self.portal = self.layer['portal']
self.wf = getToolByName(self.portal, "portal_workflow")
self.portal.acl_users._doAddUser('user_std', 'secret', ['Member'], [])
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self._setupFTI()
self.portal.invokeFactory(self._portal_type, 'doc1')
setRoles(self.portal, TEST_USER_ID, ['Member'])
import transaction
transaction.commit()
# Set up browser
self.browser = Browser(app)
self.browser.handleErrors = False
self.browser.addHeader(
'Authorization',
'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,)
)

def test_richtext_behavior(self):
IRichText.providedBy(self.portal.doc1)


def test_suite():
from unittest import defaultTestLoader
return defaultTestLoader.loadTestsFromName(__name__)
2 changes: 1 addition & 1 deletion plone/app/contenttypes/tests/test_document.py
Expand Up @@ -109,7 +109,7 @@ def test_add_document(self):
.value = "My document"
self.browser.getControl(name='form.widgets.IDublinCore.description')\
.value = "This is my document."
self.browser.getControl(name='form.widgets.text')\
self.browser.getControl(name='form.widgets.IRichText.text')\
.value = "Lorem Ipsum"
self.browser.getControl('Save').click()
self.assertTrue(self.browser.url.endswith('my-document/view'))
Expand Down
2 changes: 1 addition & 1 deletion plone/app/contenttypes/tests/test_news_item.py
Expand Up @@ -136,7 +136,7 @@ def test_add_news_item(self):
.value = "My news item"
self.browser.getControl(name='form.widgets.IDublinCore.description')\
.value = "This is my news item."
self.browser.getControl(name='form.widgets.text')\
self.browser.getControl(name='form.widgets.IRichText.text')\
.value = "Lorem Ipsum"
self.browser.getControl('Save').click()

Expand Down

0 comments on commit a76ffc3

Please sign in to comment.