[Zope3-checkins] SVN: Zope3/branches/Zope-3.1/src/zope/app/ port r37684 (fix to source widget hasInput and assiciated changes) from trunk

Gary Poster gary at zope.com
Wed Aug 3 15:30:13 EDT 2005


Log message for revision 37685:
  port r37684 (fix to source widget hasInput and assiciated changes) from trunk
  

Changed:
  U   Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/group_searching_with_empty_string.txt
  U   Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/pau_prefix_and_searching.txt
  U   Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.py
  U   Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.txt
  U   Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting.py
  U   Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting_ftest.txt

-=-
Modified: Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/group_searching_with_empty_string.txt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/group_searching_with_empty_string.txt	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/group_searching_with_empty_string.txt	2005-08-03 19:30:13 UTC (rev 37685)
@@ -231,7 +231,10 @@
   ... Content-Type: application/x-www-form-urlencoded
   ... Referer: http://localhost:8081/@@grant.html
   ... 
-  ... field.principal.displayed=y&field.principal.MC5ncm91cHM_.field.search=&field.principal.MC5ncm91cHM_.search=Search&field.principal.MQ__.searchstring=""")
+  ... field.principal.displayed=y&"""
+  ... "field.principal.MC5ncm91cHM_.field.search=&"
+  ... "field.principal.MC5ncm91cHM_.search=Search&"
+  ... "field.principal.MQ__.searchstring=")
   HTTP/1.1 200 Ok
   ...Test1...Test2...
 

Modified: Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/pau_prefix_and_searching.txt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/pau_prefix_and_searching.txt	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/authentication/browser/pau_prefix_and_searching.txt	2005-08-03 19:30:13 UTC (rev 37685)
@@ -301,7 +301,11 @@
   ... Content-Length: 191
   ... Content-Type: application/x-www-form-urlencoded
   ... 
-  ... field.principal.displayed=y&field.principal.MC5Hcm91cHM_.field.search=&field.principal.MC5Hcm91cHM_.search=Search&field.principal.MC5Vc2Vycw__.field.search=&field.principal.MQ__.searchstring=""")
+  ... field.principal.displayed=y&"""
+  ... "field.principal.MC5Hcm91cHM_.field.search=&"
+  ... "field.principal.MC5Hcm91cHM_.search=Search&"
+  ... "field.principal.MC5Vc2Vycw__.field.search=&"
+  ... "field.principal.MQ__.searchstring=")
   HTTP/1.1 200 Ok
   ...
   <select name="field.principal.MC5Hcm91cHM_.selection">
@@ -321,7 +325,12 @@
   ... Content-Length: 255
   ... Content-Type: application/x-www-form-urlencoded
   ... 
-  ... field.principal.displayed=y&field.principal.MC5Hcm91cHM_.field.search=&field.principal.MC5Hcm91cHM_.selection=cGF1MV9ncm91cHNfbmljZQ__&field.principal.MC5Vc2Vycw__.field.search=&field.principal.MC5Vc2Vycw__.search=Search&field.principal.MQ__.searchstring=""")
+  ... field.principal.displayed=y&"""
+  ... "field.principal.MC5Hcm91cHM_.field.search=&"
+  ... "field.principal.MC5Hcm91cHM_.selection=cGF1MV9ncm91cHNfbmljZQ__&"
+  ... "field.principal.MC5Vc2Vycw__.field.search=&"
+  ... "field.principal.MC5Vc2Vycw__.search=Search&"
+  ... "field.principal.MQ__.searchstring=")
   HTTP/1.1 200 Ok
   ...
   <select name="field.principal.MC5Vc2Vycw__.selection">

Modified: Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.py	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.py	2005-08-03 19:30:13 UTC (rev 37685)
@@ -318,11 +318,8 @@
         return value
 
     def hasInput(self):
-        if self.name in self.request:
+        if self.name in self.request or self.name+'.displayed' in self.request:
             return True
-        if (not self.context.required and
-            self.name+'.displayed' in self.request):
-            return True
 
         for name, queryview in self.queryviews:
             if name+'.apply' in self.request:

Modified: Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.txt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.txt	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/form/browser/source.txt	2005-08-03 19:30:13 UTC (rev 37685)
@@ -155,36 +155,30 @@
   >>> request.form['field.dog.query.string'] = u'o'
   >>> request.form['field.dog.query'] = u'Search'
 
-Because the field is required, a non-selection is not valid. Thus, the widget
-does not have an input value.
+Because the field is required, a non-selection is not valid. Thus, while the
+widget still hasInput, it will raise an error when you getInputValue.
 
   >>> widget.hasInput()
-  False
+  True
+  >>> widget.getInputValue()
+  Traceback (most recent call last):
+  ...
+  MissingInputError: ('dog', u'Dogs', None)
 
 If the field is not required:
 
   >>> dog.required = False
 
-then as long as the field is displayed, the widget says it has input.
+then as long as the field is displayed, the widget still has input but returns
+the field's missing value.
 
   >>> widget.hasInput()
   True
+  >>> widget.getInputValue() # None
 
-  >>> dog.required = True
-
-If we actually provide some input:
-
-  >>> request.form['field.dog'] = 'foo'
-
-then we have input:
-
-  >>> widget.hasInput()
-  True
-
-  >>> del request.form['field.dog']
-
 Now if we render the widget, we'll see the search results:
 
+  >>> dog.required = True
   >>> print widget()
   <div class="value">
     <div class="row">

Modified: Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting.py	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting.py	2005-08-03 19:30:13 UTC (rev 37685)
@@ -24,6 +24,7 @@
 from zope.app.form.utility import setUpWidget
 from zope.app.form.browser import RadioWidget
 from zope.app.form.browser.widget import renderElement
+from zope.app.form.interfaces import MissingInputError
 from zope.app.i18n import ZopeMessageIDFactory as _
 
 from zope.app.form.interfaces import IInputWidget
@@ -147,8 +148,11 @@
         setUpWidget(self, 'principal', self.principal_field, IInputWidget)
         if not self.principal_widget.hasInput():
             return u''
-
-        principal = self.principal_widget.getInputValue()
+        try:
+            principal = self.principal_widget.getInputValue()
+        except MissingInputError:
+            return u''
+        
         self.principal = principal
 
         # Make sure we can use the principal id in a form by base64ing it
@@ -193,17 +197,21 @@
             name = principal_token + '.role.'+role.id
             role_widget = getattr(self, name+'_widget')
             if role_widget.hasInput():
-                setting = role_widget.getInputValue()
-                # Arrgh!
-                if setting is settings.Allow:
-                    principal_roles.assignRoleToPrincipal(
-                        role.id, principal)
-                elif setting is settings.Deny:
-                    principal_roles.removeRoleFromPrincipal(
-                        role.id, principal)
+                try:
+                    setting = role_widget.getInputValue()
+                except MissingInputError:
+                    pass
                 else:
-                    principal_roles.unsetRoleForPrincipal(
-                        role.id, principal)
+                    # Arrgh!
+                    if setting is settings.Allow:
+                        principal_roles.assignRoleToPrincipal(
+                            role.id, principal)
+                    elif setting is settings.Deny:
+                        principal_roles.removeRoleFromPrincipal(
+                            role.id, principal)
+                    else:
+                        principal_roles.unsetRoleForPrincipal(
+                            role.id, principal)
 
         for perm in perms:
             if perm.id == 'zope.Public':
@@ -211,16 +219,20 @@
             name = principal_token + '.permission.'+perm.id
             perm_widget = getattr(self, name+'_widget')
             if perm_widget.hasInput():
-                setting = perm_widget.getInputValue()
-                # Arrgh!
-                if setting is settings.Allow:
-                    principal_perms.grantPermissionToPrincipal(
-                        perm.id, principal)
-                elif setting is settings.Deny:
-                    principal_perms.denyPermissionToPrincipal(
-                        perm.id, principal)
+                try:
+                    setting = perm_widget.getInputValue()
+                except MissingInputError:
+                    pass
                 else:
-                    principal_perms.unsetPermissionForPrincipal(
-                        perm.id, principal)
+                    # Arrgh!
+                    if setting is settings.Allow:
+                        principal_perms.grantPermissionToPrincipal(
+                            perm.id, principal)
+                    elif setting is settings.Deny:
+                        principal_perms.denyPermissionToPrincipal(
+                            perm.id, principal)
+                    else:
+                        principal_perms.unsetPermissionForPrincipal(
+                            perm.id, principal)
 
         return _('Grants updated.')

Modified: Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting_ftest.txt
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting_ftest.txt	2005-08-03 18:47:41 UTC (rev 37684)
+++ Zope3/branches/Zope-3.1/src/zope/app/securitypolicy/browser/granting_ftest.txt	2005-08-03 19:30:13 UTC (rev 37685)
@@ -26,8 +26,8 @@
   ... Referer: http://localhost:8081/@@grant.html
   ... 
   ... field.principal.displayed=y"""
-  ... """&field.principal.MA__.searchstring="""
-  ... """&field.principal.MA__.search=Search""")
+  ... "&field.principal.MA__.searchstring="
+  ... "&field.principal.MA__.search=Search")
   HTTP/1.1 200 Ok
   ...
   <option value="em9wZS5tZ3I_">Manager</option>



More information about the Zope3-Checkins mailing list