Exemplo n.º 1
0
class Article_w(ObjectWidget):
    """This is the 'medium' class which inherits ObjectWidget
    and in which ObjectWidgets are defined."""

    __used_for__ = IArticle

    author_widget = CustomWidgetFactory(ObjectWidget, Person)
    # (Note that you don't have do define a custom widget for the simple TextLine 'title'!)
    pages_widget = CustomWidgetFactory(ObjectWidget, Pages)
Exemplo n.º 2
0
class NonsensEditView(EditView):
    """This is the customized EditView class."""

    __used_for__ = INonsens

    #Give the 'medium' class Article_w as an argument to the contructor of CustomWidgetFactory.
    article_widget = CustomWidgetFactory(Article_w, Article)
Exemplo n.º 3
0
class PersonEditView(formbase.EditFormBase):
    form_fields = form.Fields(IPersonTable)
    form_fields = form_fields.omit('person_id', 'address_id')
    form_fields['address'].custom_widget = CustomWidgetFactory(
        AddressWidget, Address)
    template = ZopeTwoPageTemplateFile('person_edit.pt')
    prefix = 'edit'

    @form.action("Apply", condition=form.haveInputWidgets)
    def handle_edit_action(self, action, data):
        if applyChanges(self.context, self.form_fields, data, self.adapters):
            zope.event.notify(
                zope.app.event.objectevent.ObjectModifiedEvent(self.context))
            formatter = self.request.locale.dates.getFormatter(
                'dateTime', 'medium')

            try:
                time_zone = idatetime.ITZInfo(self.request)
            except TypeError:
                time_zone = pytz.UTC

            status = _("Updated on ${date_time}",
                       mapping={
                           'date_time':
                           formatter.format(datetime.datetime.now(time_zone))
                       })
            self.status = status
        else:
            self.status = _('No changes')

    def update(self, *args, **kw):
        super(PersonEditView, self).update(*args, **kw)
        self.request.set('portal_status_message', self.status)
Exemplo n.º 4
0
class PersonView(formbase.DisplayForm):
    form_fields = form.Fields(IPersonTable,
                              for_display=True,
                              render_context=True)
    form_fields = form_fields.omit('person_id')
    form_fields['address'].custom_widget = CustomWidgetFactory(
        AddressDisplayWidget, Address)
    template = ZopeTwoPageTemplateFile('person_view.pt')
    prefix = 'view'
Exemplo n.º 5
0
class PersonAddingView(formbase.AddFormBase):
    form_fields = form.Fields(IPersonTable, for_input=True)
    form_fields = form_fields.omit('person_id', 'address_id')
    form_fields['address'].custom_widget = CustomWidgetFactory(
        AddressWidget, Address)
    template = ZopeTwoPageTemplateFile('person_add.pt')
    prefix = 'add'

    def createAndAdd(self, data):
        person = self.context.domain_model(**data)
        self._finished_add = True
        return person

    def nextURL(self):
        return self.context.absolute_url()
Exemplo n.º 6
0
    def test_customWidgetFactory(self):
        """Verify that the widget can be constructed via the CustomWidgetFactory
        (Issue #293)
        """

        value_type = TextLine(__name__=u'bar')
        self.field = List(__name__=u'foo', value_type=value_type)
        request = TestRequest()

        # set up the custom widget factory and verify that it works
        sw = CustomWidgetFactory(self._WidgetFactory)
        widget = sw(self.field, request)
        assert widget.subwidget is None
        assert widget.context.value_type is value_type

        # set up a variant that specifies the subwidget to use and verify it
        class PollOption(object):
            pass

        ow = CustomWidgetFactory(ObjectWidget, PollOption)
        sw = CustomWidgetFactory(self._WidgetFactory, subwidget=ow)
        widget = sw(self.field, request)
        assert widget.subwidget is ow
        assert widget.context.value_type is value_type
Exemplo n.º 7
0
    def test_subwidget(self):
        """This test verifies that the specified subwidget is not ignored.
        (Issue #293)
        """
        self.field = List(__name__=u'foo',
                          value_type=TextLine(__name__=u'bar'))
        request = TestRequest()

        class PollOption(object):
            pass

        ow = CustomWidgetFactory(ObjectWidget, PollOption)
        widget = self._WidgetFactory(self.field,
                                     self.field.value_type,
                                     request,
                                     subwidget=ow)
        assert widget.subwidget is ow
Exemplo n.º 8
0
    fields = schema.List(
        title=u"Fields",
        description=u"The Mars Categories Fields.",
        required=True,
        default=[],
        value_type=schema.TextLine(title=u"Field Mapping"),
    )


class MarscatSettings(Persistent):
    implements(IMarscatSettings)

    fields = []


fieldmapping_widget = CustomWidgetFactory(ObjectWidget, FieldMapping)
fields_widget = CustomWidgetFactory(ListSequenceWidget,
                                    subwidget=fieldmapping_widget)


class MarscatSettingsControlPanelAdapter(SchemaAdapterBase):
    adapts(IPloneSiteRoot)
    implements(IMarscatSettings)

    def __init__(self, context):
        super(MarscatSettingsControlPanelAdapter, self).__init__(context)
        self.context = getUtility(IMarscatSettings)

    @apply
    def fields():
        def get(self):
Exemplo n.º 9
0
def YesNoDisplayWidget(*attrs, **kw):
    return CustomWidgetFactory(YesNoDisplayWidgetBase, *attrs, **kw)
Exemplo n.º 10
0
def AutoCompleteWidget(*attrs, **kw):
    return CustomWidgetFactory(_AutoCompleteWidget, *attrs, **kw)

logoset = FormFieldsets(ILogoSchema)
logoset.id = 'logo'
logoset.label = _(u'Logo')

emailset = FormFieldsets(IEmailSchema)
emailset.id = 'email'
emailset.label = _(u'Email')

sloganset = FormFieldsets(ISloganSchema)
sloganset.id = 'slogan'
sloganset.label = _(u'Slogan')

parametersset = FormFieldsets(IParametersSchema)
parametersset.id = 'parameters'
parametersset.label = _(u'Parameters')

title_widget = CustomWidgetFactory(ObjectWidget, TitleLanguagePair)
slogan_widget = CustomWidgetFactory(ListSequenceWidget, subwidget=title_widget)


class PropertiesControlPanel(ControlPanelForm):

    form_fields = FormFieldsets(logoset, emailset, sloganset, parametersset)
    form_fields['site_slogan'].custom_widget = slogan_widget

    label = _("Site Properties")
    description = _("Configuration of site specific settings")
    form_name = _("Site Properties")
Exemplo n.º 12
0
class PersonAddingView(formlib.RecordAddForm):
    form_fields = form.Fields(IPersonTable, for_input=True)
    form_fields['address'].custom_widget = CustomWidgetFactory(
        objectwidget.RecordWidget, Address)
Exemplo n.º 13
0
class PersonEditView(formlib.RecordEditForm):
    form_fields = form.Fields(IPersonTable)
    form_fields['address'].custom_widget = CustomWidgetFactory(
        objectwidget.RecordWidget, Address)
Exemplo n.º 14
0
class PersonView(formlib.RecordDisplayForm):
    form_fields = form.Fields(IPersonTable,
                              for_display=True,
                              render_context=True)
    form_fields['address'].custom_widget = CustomWidgetFactory(
        objectwidget.RecordDisplayWidget, Address)
Exemplo n.º 15
0
        sf = self.get_press_subfolder('photos')
        path = '/'.join(sf.getPhysicalPath())
        q = {'path': path}
        keywords = annotations.get(KEYWORDS_KEY)
        if keywords:
            q['Subject'] = keywords
        return cat(q)


class KeywordWidget(TextWidget):
    """ Override TextWidget to increate the width
    """
    displayWidth = 80


kw_widget = CustomWidgetFactory(KeywordWidget)


class DynamicPressRoomConfigurationForm(formbase.PageForm):
    """ """
    form_fields = form.FormFields(IPressRoomConfiguration)
    form_fields['keyword_list'].custom_widget = kw_widget
    label = _(u"Configure this Press Room")

    def setUpWidgets(self, ignore_request=False):
        request = self.request
        if 'form.actions.save' in request:
            # Add annotated values to the request so that we see the saved
            # values on a freshly opened form.
            context = Acquisition.aq_inner(self.context).getCanonical()
            annotations = IAnnotations(context)
Exemplo n.º 16
0
class ComplexSchemaView:
    """Needs a docstring"""

    fish_widget = CustomWidgetFactory(ObjectWidget, FieldContent)
Exemplo n.º 17
0
 def __init__(self, context, request):
     super(StartTopic, self).__init__(context, request)
     self.__message = None
     cw = CustomWidgetFactory(MyFileWidget)
     self.form_fields['uploadedFile'].custom_widget = cw
Exemplo n.º 18
0
# See also LICENSE.txt
# $Id$

from plone.app.form.widgets.wysiwygwidget import WYSIWYGWidget
from plone.app.form.base import AddForm, EditForm
from plone.app.content.interfaces import INameFromTitle
from zope.formlib.form import applyChanges, Fields
from zope.component import createObject
from collective.cmisquery.content.cmisquery import ICMISQuery

from infrae.plone.relations.form import PloneRelationEditWidget
from infrae.plone.relations.form import PloneRelationSearchAddWidget
from zope.app.form import CustomWidgetFactory

widget_factory = CustomWidgetFactory(
    PloneRelationEditWidget,
    add_widget=PloneRelationSearchAddWidget,
    add_widget_args=dict(content_type='CMIS Browser'))


class CMISQueryAddForm(AddForm):
    label = u'Add a CMIS Query'
    form_fields = Fields(INameFromTitle, ICMISQuery)
    form_fields['browser'].custom_widget = widget_factory
    form_fields['text'].custom_widget = WYSIWYGWidget

    def create(self, data):
        query = createObject(u"collective.cmisquery.CMISQuery")
        content = self.context.add(query)
        # We need to add the content before editing it, in order to
        # have a working reference: we would get not yet overwise.
        applyChanges(content, self.form_fields, data)
Exemplo n.º 19
0
            else:
                self.modify(c)

    local_categories = property(_get_local_categories, _set_categories)
    acquired_categories = property(_get_acquired_categories)


class ObjectDisplayWidget(ObjectWidget):
    """an object widget which hide all readonly attributes """

    template = ViewPageTemplateFile('display_object.pt')

    def __call__(self):
        return self.template()


class HiddenReadonlyObjectWidget(ObjectWidget):
    """an object widget which hide all readonly attributes """

    template = ViewPageTemplateFile('hidden_readonly_object.pt')

    def __call__(self):
        return self.template()

hr_category_widget = CustomWidgetFactory(HiddenReadonlyObjectWidget, RatingsCategoryFactory)
hr_categories_widget = CustomWidgetFactory(ListSequenceWidget, hr_category_widget)


display_category_widget = CustomWidgetFactory(ObjectDisplayWidget, RatingsCategoryFactory)
display_categories_widget = CustomWidgetFactory(SequenceDisplayWidget, display_category_widget)
Exemplo n.º 20
0
from zope.app.form import CustomWidgetFactory
from zope.app.form.browser import ObjectWidget
from zope.app.form.browser import ListSequenceWidget, SequenceWidget
from zope.formlib import form
from app import Person, IAddressBook, AddressBook

person_widget = CustomWidgetFactory(ObjectWidget, Person)
persons_widget = CustomWidgetFactory(ListSequenceWidget,
                                     subwidget=person_widget)


class EditFormView(form.EditForm):
    form_fields = form.Fields(IAddressBook, render_context=True)
    form_fields['persons'].custom_widget = persons_widget
Exemplo n.º 21
0
        self.context = context
        self.request = request

    def __call__(self):
        return self.template()


class _DbxrefPatternWidget(ObjectWidget):
    def __init__(self, context, request, factory, **kw):
        super(_DbxrefPatternWidget, self).__init__(context, request, factory,
                                                   **kw)
        self.view = DbxrefPatternWidgetView(self, request)


DbxrefPatternsWidget = CustomWidgetFactory(ListSequenceWidget,
                                           subwidget=CustomWidgetFactory(
                                               _DbxrefPatternWidget,
                                               DbxrefPattern))


class ControlPanelAdapter(SchemaAdapterBase):
    adapts(IPloneSiteRoot)
    implements(IPlone4BioConfigurationSchema)

    def __init__(self, context):
        super(ControlPanelAdapter, self).__init__(context)
        self.context = getToolByName(context, 'plone4bio_dbxrefpatterns')

    dbxref_patterns = ProxyFieldProperty(
        IPlone4BioConfigurationSchema['dbxref_patterns'])