Skip to content

Commit

Permalink
- Add dexterity support. The field choice is achieved by looking for an
Browse files Browse the repository at this point in the history
  IRichText field in the schema. [toutpt]
  • Loading branch information
toutpt committed Apr 29, 2013
1 parent 0e3c86b commit 953f260
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion collective/etherpad/archetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def save(self):

class EtherpadEditView(FormWrapper):
"""Implement etherpad for Archetypes content types"""
form_instance_class = EtherpadSyncForm

def __init__(self, context, request):
super(EtherpadEditView, self).__init__(context, request)
Expand Down Expand Up @@ -178,7 +179,7 @@ def update(self):
self.etherpad_iframe_url = url

if self.form_instance is None:
self.form_instance = EtherpadSyncForm(
self.form_instance = self.form_instance_class(
aq_inner(self.context), self.request
)
self.form_instance.__name__ = self.__name__
Expand Down
26 changes: 19 additions & 7 deletions collective/etherpad/dexterity.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
# there are no import of archetypes in .archetypes just the way fields are
# retrieved
from z3c.form import button
from zope import schema
from collective.etherpad import archetypes
from plone.dexterity.schema import SCHEMA_CACHE
from plone.app.textfield.interfaces import IRichText


class EtherpadSyncForm(archetypes.EtherpadSyncForm):

def save(self):
#get the content from etherpad
import pdb;pdb.set_trace()
field = self.context.getField(self.archetypes_fieldname)
context_schema = SCHEMA_CACHE.get(self.context.portal_type)
fields = schema.getFields(context_schema)
for name in fields:
field = fields[name]
if IRichText.providedBy(field):
break

html = self.etherpad.getHTML(padID=self.padID)
if html and 'html' in html:
field.set(self.context, html['html'], mimetype='text/html')


class EtherpadEditView(archetypes.EtherpadEditView):
"""Implement etherpad for Archetypes content types"""
form_instance_class = EtherpadSyncForm

def getEtherpadFieldName(self):
import pdb;pdb.set_trace()
primary = self.context.getPrimaryField()
if primary:
return primary.getName()
context_schema = SCHEMA_CACHE.get(self.context.portal_type)
fields = schema.getFields(context_schema)
for name in fields:
field = fields[name]
if IRichText.providedBy(field):
break
return name
3 changes: 3 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.1 (unreleased)
----------------

- Add dexterity support. The field choice is achieved by looking for an
IRichText field in the schema. [toutpt]

- Set logs to DEBUG.
[thomasdesvenain]

Expand Down

0 comments on commit 953f260

Please sign in to comment.