editable and non editable fields

Sébastien Robin <[email protected]> Wed, 21 Jan 2004 19:10:50 +0100
Newsgroups gmane.comp.web.zope.formulator.devel
Message-ID <[email protected]>
Hi all,

Since in my company we need all the time the possibility to make a field 
non editable, I have made a short patch (with this mail) that just add a 
checkbox 'editable' (just below 'enabled'). When the checkbox is not set, 
then instead of calling field.render, it simply calls field.render_view.

By the way, in reply to Clemens, for sure settings as "hidden", 
"disabled", "readonly" make the edit tab a bit less manageable. But if a 
new tab is added, then may be another tales tab is needed, well... this 
can make one getting lost between tabs... :)

Regards.


  Sébastien.
-- 
Sebastien ROBIN

About www.nexedi.com 

Nexedi is a consulting and development services company helping small and 
medium organisations to choose open source / free software and fulfill 
their IT application needs. Nexedi is the founder of the ERP5 project, a 
Free / Open Source ERP software based on innovative technologies 
(www.erp5.org).

About www.storever.com

Storever provides a reliable source for OpenBrick, WiFi infrastructure, 
notebooks and servers preconfigured with the GNU/Linux operating system

_______________________________________________
formulator-dev mailing list
formulator-dev-IAPFreCvJWM6s/[email protected]
http://lists.infrae.com/mailman/listinfo/formulator-dev
Formulator-1.6.1-editable.patch (text/x-diff, 2 KB)
diff -ru Formulator-1.6.1/Field.py Formulator-1.6.1.patch/Field.py
--- Formulator-1.6.1/Field.py	2004-01-21 17:06:17.000000000 +0100
+++ Formulator-1.6.1.patch/Field.py	2004-01-21 17:05:58.000000000 +0100
@@ -177,12 +177,14 @@
                 return getattr(self.validator, name)
             else:
                 return "Unknown error: %s" % name
-    
+
     security.declarePrivate('_render_helper')
     def _render_helper(self, key, value, REQUEST):
         value = self._get_default(key, value, REQUEST)
         if self.get_value('hidden'):
             return self.widget.render_hidden(self, key, value, REQUEST)
+        elif (not self.get_value('editable')):
+            return self.widget.render_view(self, value)
         else:
             return self.widget.render(self, key, value, REQUEST)
 
diff -ru Formulator-1.6.1/Validator.py Formulator-1.6.1.patch/Validator.py
--- Formulator-1.6.1/Validator.py	2004-01-21 17:06:17.000000000 +0100
+++ Formulator-1.6.1.patch/Validator.py	2004-01-21 17:05:58.000000000 +0100
@@ -10,7 +10,7 @@
 class ValidatorBase:
     """Even more minimalistic base class for validators.
     """
-    property_names = ['enabled']
+    property_names = ['enabled','editable']
 
     message_names = []
 
@@ -24,10 +24,18 @@
         "get a validation error as a field suddenly got enabled that "
         "wasn't there when the form was drawn."),
                                    default=1)
-    
+
+    editable = fields.CheckBoxField('editable',
+                                   title="Editable",
+                                   description=(
+        "If a field is not editable, then the user can only see"
+        "the value. This allows to drawn very different forms depending"
+        "on use permissions."),
+                                   default=1)
+
     def raise_error(self, error_key, field):
         raise ValidationError(error_key, field)
-    
+
     def validate(self, field, key, REQUEST):    
         pass # override in subclass
 
Seulement dans Formulator-1.6.1.patch: .Validator.py.swp