Back to index

plone3  3.1.7
wysiwygwidget.py
Go to the documentation of this file.
00001 from zope.app.form.browser.textwidgets import TextWidget
00002 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
00003 
00004 from Acquisition import aq_parent
00005 from Products.CMFCore.interfaces import ISiteRoot
00006 from zope.app.component.hooks import getSite
00007 
00008 class WYSIWYGWidget(TextWidget):
00009     """ A widget using Plone's wysiwyg_support.
00010     """
00011 
00012     template = ViewPageTemplateFile('wysiwygwidget.pt')
00013 
00014     def __init__(self, field, request):
00015         super(TextWidget, self).__init__(field, request)
00016 
00017     def __call__(self):
00018         value = self._getFormValue()
00019         if value is None or value == self.context.missing_value:
00020             value = ''
00021 
00022         # Evil acquisition majik to find the site root. This is made tricky
00023         # by the fact that the widget doesn't have a direct path to its
00024         # context (you can go self.context.context, but this may be an
00025         # adapter on the context, not the context itself.). We can find
00026         # the root using getUtility(ISiteRoot), but this isn't wrapped
00027         # in the request container. We can use getSite(), but there may be
00028         # other sites in-between, not at least the KSS site-in-a-view. Sigh.
00029 
00030         site = getSite()
00031         while site is not None and not ISiteRoot.providedBy(site):
00032             site = aq_parent(site)
00033         
00034         return self.template(form_context=site,
00035                              value=value)