コード例 #1
0
    def render(self):
        if self.request.method == 'POST':
            Form.render(self)

            return self.request.response.redirect(self.nextURL())

        return Form.render(self)
コード例 #2
0
    def updateWidgets(self):
        """ Customize form widgets for the example.

        Usually Form.updateWidgets() is proper place to override your widgets to customize them.

        Note that DateWidget (no time) might not support any advanced options.
        """
        print self.getContent()
        
        Form.updateWidgets(self)

        #
        # Example how to set default datetime programmatically to a specific value
        # 
        now = datetime.datetime.now()
        self.fields['datetime'].field.default = now

        #
        # Example how to modify datetimewidget options
        # 
        self.widgets['datetime2'].years = range(2005, 2008)

        #
        # Example how to set widget properties just to ask year and month
        #
        self.widgets['year_month'].components = ["years", "months"]
        self.widgets['year_month'].component_separators={"years":"/"}
        self.widgets['year_month'].show_jquery_picker = False # Disable Javascript picker

        #
        # Example how to set datetime widget to look like american date format
        # 
        self.widgets['american_date'].components = ["months", "days", "years"]
        self.widgets['american_date'].component_separators={"months":"/", "days" : "/"}
        self.widgets['american_date'].show_jquery_picker = False # Disable Javascript picker
コード例 #3
0
    def updateWidgets(self, prefix=None):
        Form.updateWidgets(self, prefix=self.widgetPrefix)
        self.widgets['fragment'].name = self.tileType.__name__ + '.fragment'
        self.widgets['fragment'].update()

        # Ensure fragment value
        if not self.widgets['fragment'].value:
            fragment = getFragmentName(self.request)
            if fragment:
                self.widgets['fragment'].value = [fragment]
コード例 #4
0
    def updateWidgets(self, prefix=None):
        Form.updateWidgets(self, prefix=self.widgetPrefix)
        self.widgets['fragment'].name = self.tileType.__name__ + '.fragment'
        self.widgets['fragment'].update()

        # Ensure fragment value
        if not self.widgets['fragment'].value:
            fragment = getFragmentName(self.request)
            if fragment:
                self.widgets['fragment'].value = [fragment]
コード例 #5
0
ファイル: test_utils.py プロジェクト: chaoflow/plone.autoform
 def test_processFields_permissionChecks_w_prefix(self):
     form = Form(None, None)
     form.groups = ()
     class schema(Interface):
         title = zope.schema.TextLine()
     schema.setTaggedValue(WRITE_PERMISSIONS_KEY, {'title': 'foo'})
     processFields(form, schema, prefix='prefix', permissionChecks=True)
     
     self.assertEqual('foo', self.secman.checks.pop())
     self.assertFalse('prefix.title' in form.fields)
コード例 #6
0
    def test_processFields_permissionChecks_w_prefix(self):
        form = Form(None, None)
        form.groups = ()

        class schema(Interface):
            title = zope.schema.TextLine()
        schema.setTaggedValue(WRITE_PERMISSIONS_KEY, {'title': 'foo'})
        processFields(form, schema, prefix='prefix', permissionChecks=True)

        self.assertEqual('foo', self.secman.checks.pop())
        self.assertFalse('prefix.title' in form.fields)
コード例 #7
0
ファイル: complete.py プロジェクト: pemzurigo/opengever.core
    def updateWidgets(self):
        if self.request.form.get("form.widgets.transition", None) is None:
            self.request.set("form.widgets.transition", self.request.get("transition"))

        # Use text passed from response-add-form.
        if self.request.form.get("form.widgets.text", None) is None:
            dm = getUtility(IWizardDataStorage)
            oguid = ISuccessorTaskController(self.context).get_oguid()
            dmkey = "delegate:%s" % oguid
            text = dm.get(dmkey, "text")
            if text:
                self.request.set("form.widgets.text", text)

        Form.updateWidgets(self)

        self.widgets["transition"].mode = HIDDEN_MODE
コード例 #8
0
    def updateWidgets(self):
        if self.request.form.get('form.widgets.transition', None) is None:
            self.request.set('form.widgets.transition',
                             self.request.get('transition'))

        # Use text passed from response-add-form.
        if self.request.form.get('form.widgets.text', None) is None:
            dm = getUtility(IWizardDataStorage)
            oguid = ISuccessorTaskController(self.context).get_oguid()
            dmkey = 'delegate:%s' % oguid
            text = dm.get(dmkey, 'text')
            if text:
                self.request.set('form.widgets.text', text)

        Form.updateWidgets(self)

        self.widgets['transition'].mode = HIDDEN_MODE
コード例 #9
0
    def test_processFields_fieldsets_as_form_groups(self):
        form = Form(None, None)
        form.groups = []

        class schema(Interface):
            title = zope.schema.TextLine()

        fieldset = Fieldset('custom', label=u'Custom', fields=['title'])
        schema.setTaggedValue(FIELDSETS_KEY, [fieldset])

        class subschema(schema):
            subtitle = zope.schema.TextLine()

        fieldset = Fieldset('custom', label=u'Custom', fields=['subtitle'])
        subschema.setTaggedValue(FIELDSETS_KEY, [fieldset])

        processFields(form, subschema, prefix='prefix', permissionChecks=True)

        self.assertEqual(len(form.groups), 1)
        self.assertEqual(len(form.groups[0].fields), 2)
        self.assertEqual([g.__name__ for g in form.groups], ['custom'])
コード例 #10
0
    def test_fieldset_configuration(self):
        """Test, if fieldsets can be orderd via fieldset configuration on a
        schema without fields. This schema should also not be included in form
        groups.
        """
        form = Form(None, None)
        form.groups = []

        class schema1(Interface):
            title = zope.schema.TextLine()

        fs1 = Fieldset('fs1', label=u'fs1', fields=['title'])
        schema1.setTaggedValue(FIELDSETS_KEY, [fs1])

        class schema2(Interface):
            subtitle = zope.schema.TextLine()

        fs2 = Fieldset('fs2', label=u'fs2', fields=['subtitle'])
        schema2.setTaggedValue(FIELDSETS_KEY, [fs2])

        class schema3(Interface):
            pass

        fs3 = Fieldset('fs1', order=2)
        fs4 = Fieldset('fs2', order=1)
        schema3.setTaggedValue(FIELDSETS_KEY, [fs3, fs4])

        processFields(form, schema1, prefix='prefix', permissionChecks=True)
        processFields(form, schema2, prefix='prefix', permissionChecks=True)
        processFields(form, schema3, prefix='prefix', permissionChecks=True)

        self.assertEqual(len(form.groups), 2)

        self.assertEqual(form.groups[0].__name__, 'fs1')
        self.assertEqual(form.groups[0].order, 2)

        self.assertEqual(form.groups[1].__name__, 'fs2')
        self.assertEqual(form.groups[1].order, 1)
コード例 #11
0
    def test_processFields_fieldsets_as_form_groups(self):
        form = Form(None, None)
        form.groups = []

        class schema(Interface):
            title = zope.schema.TextLine()

        fieldset = Fieldset('custom', label=u'Custom',
                            fields=['title'])
        schema.setTaggedValue(FIELDSETS_KEY, [fieldset])

        class subschema(schema):
            subtitle = zope.schema.TextLine()

        fieldset = Fieldset('custom', label=u'Custom',
                            fields=['subtitle'])
        subschema.setTaggedValue(FIELDSETS_KEY, [fieldset])

        processFields(form, subschema,
                      prefix='prefix', permissionChecks=True)

        self.assertEqual(len(form.groups), 1)
        self.assertEqual(len(form.groups[0].fields), 2)
        self.assertEqual([g.__name__ for g in form.groups], ['custom'])
コード例 #12
0
    def extractData(self):
        """ Override to be able to provide defaults
        """
        data, errors = Form.extractData(self)

        for k, v in data.items():
            if not v:
                default = getattr(self, 'default_' + k, None)

                if default:
                    value = data[k] = default()

                    if not value:
                        continue
                    widget = self.widgets[k]
                    widget.value = value
                    field = widget.field.bind(self.context)
                    field.default = value
                    widget.field = field
                    widget.ignoreRequest = True
                    widget.update()

        return data, errors
コード例 #13
0
ファイル: reportdata.py プロジェクト: laszlocseh/wise.msfd
 def update(self):
     if not self._updated:
         Form.update(self)
         self._updated = True
コード例 #14
0
    def updateWidgets(self):
        Form.updateWidgets(self)
        now = datetime.datetime.now()
#        self.fields['date'].field.default = now
        self.fields['datetime'].field.default = now
コード例 #15
0
 def updateWidgets(self):
     Form.updateWidgets(self)
     now = datetime.datetime.now()
     #        self.fields['date'].field.default = now
     self.fields['datetime'].field.default = now
コード例 #16
0
 def __init__(self, context, request):
     Form.__init__(self, context, request)
コード例 #17
0
 def __init__(self, context, request):
     Form.__init__(self, context, request)
     self.__parent__ = self.context
     self.data = {}
コード例 #18
0
 def render(self):
     if self._finishedAdd:
         self.ignoreRequest = True
         self.updateWidgets()
         return Form.render(self)
     return super(BookingBarForm, self).render()