Changeset 28:4692e23155a3 in ralphm-patches for pubsub-forms.patch


Ignore:
Timestamp:
Jan 2, 2010, 10:50:14 PM (11 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Add PubSubClient?.getOptions, allow form type checking without field defs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pubsub-forms.patch

    r27 r28  
    33diff -r ba58db23e8b9 wokkel/data_form.py
    44--- a/wokkel/data_form.py       Fri Jan 01 15:54:26 2010 +0100
    5 +++ b/wokkel/data_form.py       Sat Jan 02 13:53:24 2010 +0100
     5+++ b/wokkel/data_form.py       Sat Jan 02 22:49:40 2010 +0100
    66@@ -76,6 +76,7 @@
    77             option['label'] = self.label
     
    155155         form['type'] = self.formType
    156156 
    157 @@ -516,3 +604,58 @@
     157@@ -516,3 +604,65 @@
    158158             values[name] = value
    159159 
     
    161161+
    162162+
    163 +    def typeCheck(self, fieldDefs, filterUnknown=False):
     163+    def typeCheck(self, fieldDefs=None, filterUnknown=False):
    164164+        """
    165165+        Check values of fields according to the field definition.
     
    176176+        that is not set.
    177177+
     178+        If C{fieldDefs} is None, an empty dictionary is assumed. This is
     179+        useful for coercing boolean and JID values on forms with type
     180+        C{'form'}.
     181+
    178182+        @param fieldDefs: Field definitions as a dictionary. See
    179183+            L{wokkel.iwokkel.IPubSubService.getConfigurationOptions}
     
    184188+        @type filterUnknown: C{bool}
    185189+        """
     190+
     191+        if fieldDefs is None:
     192+            fieldDefs = {}
    186193+
    187194+        filtered = []
     
    216223diff -r ba58db23e8b9 wokkel/pubsub.py
    217224--- a/wokkel/pubsub.py  Fri Jan 01 15:54:26 2010 +0100
    218 +++ b/wokkel/pubsub.py  Sat Jan 02 13:53:24 2010 +0100
     225+++ b/wokkel/pubsub.py  Sat Jan 02 22:49:40 2010 +0100
    219226@@ -1,6 +1,6 @@
    220227 # -*- test-case-name: wokkel.test.test_pubsub -*-
     
    260267diff -r ba58db23e8b9 wokkel/test/test_data_form.py
    261268--- a/wokkel/test/test_data_form.py     Fri Jan 01 15:54:26 2010 +0100
    262 +++ b/wokkel/test/test_data_form.py     Sat Jan 02 13:53:24 2010 +0100
     269+++ b/wokkel/test/test_data_form.py     Sat Jan 02 22:49:40 2010 +0100
    263270@@ -787,6 +787,128 @@
    264271         self.assertRaises(data_form.Error, form.addField, field2)
     
    390397         """
    391398         Each named field is represented in the values, keyed by name.
    392 @@ -834,3 +956,126 @@
     399@@ -834,3 +956,142 @@
    393400         form = data_form.Form('submit', fields=fields)
    394401         values = form.getValues()
     
    517524+        self.assertNotIn('pubsub#description', form.fields)
    518525+        self.assertEqual([], checked)
     526+
     527+
     528+    def test_typeCheckNoFieldDefs(self):
     529+        """
     530+        If there are no field defs, an empty dictionary is assumed.
     531+        """
     532+        checked = []
     533+        form = data_form.Form('submit')
     534+        form.addField(data_form.Field('list-single', var='pubsub#description',
     535+                                                     value='a node'))
     536+        field = form.fields['pubsub#description']
     537+        field.typeCheck = lambda : checked.append(None)
     538+        form.typeCheck()
     539+
     540+        self.assertIn('pubsub#description', form.fields)
     541+        self.assertEqual([None], checked)
Note: See TracChangeset for help on using the changeset viewer.