[PATCH] zope-formulator hide day for DateTime

Ian Duggan <[email protected]> Mon, 28 Feb 2005 14:33:57 -0800
Newsgroups gmane.comp.web.zope.formulator.devel
Organization Swish Marketing, Inc.
Message-ID <[email protected]>
--Boundary-00=_Vx5ICIR7SUASBbt
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


The attached patch adds an option to DateTime fields to hide the day when 
rendering the form element. This allows you to have date selections for 
MONTH, YEAR type things. The datatype is still a full date, but it defaults 
to the first or today, depending on the value of "default to now".

--Ian

--Boundary-00=_Vx5ICIR7SUASBbt
Content-Type: text/x-diff; charset="us-ascii";
	name="zope-formualtor-hide-day.final.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="zope-formualtor-hide-day.final.patch"

diff -urN zope-formulator-1.7.0/Form.py zope-formulator-1.7.0-swish/Form.py
--- zope-formulator-1.7.0/Form.py	2004-08-06 15:17:14.000000000 -0700
+++ zope-formulator-1.7.0-swish/Form.py	2005-02-25 16:38:37.000000000 -0800
@@ -780,6 +780,10 @@
         add_and_edit(self, id, REQUEST)
         return ''
 
+    # security declaration for the generic "add field" form,
+    # which is set as a class attribute in "initializeForm" later on
+    security.declareProtected("Change Formulator Forms", "fieldAdd")
+
     security.declareProtected('View management screens', 'formTest')
     formTest = DTMLFile('dtml/formTest', globals())
 
diff -urN zope-formulator-1.7.0/Widget.py zope-formulator-1.7.0-swish/Widget.py
--- zope-formulator-1.7.0/Widget.py	2004-08-21 10:17:02.000000000 -0700
+++ zope-formulator-1.7.0-swish/Widget.py	2005-02-25 19:07:00.000000000 -0800
@@ -713,7 +713,7 @@
     property_names = Widget.property_names +\
                      ['default_now', 'date_separator', 'time_separator',
                       'input_style', 'input_order',
-                      'date_only', 'ampm_time_style']
+                      'date_only', 'hide_day', 'ampm_time_style']
 
     default = fields.DateTimeField('default',
                                    title="Default",
@@ -779,6 +779,12 @@
         "Display the date only, not the time."),
                                      default=0)
 
+    hide_day = fields.CheckBoxField('hide_day',
+                                           title="Hide day field",
+                                           description=(
+        "Hide the day field."),
+                                           default=0)
+
     ampm_time_style = fields.CheckBoxField('ampm_time_style',
                                            title="AM/PM time style",
                                            description=(
@@ -789,6 +795,7 @@
 
     def render(self, field, key, value, REQUEST):
         use_ampm = field.get_value('ampm_time_style')
+        hide_day = field.get_value('hide_day')
         # FIXME: backwards compatibility hack:
         if not hasattr(field, 'sub_form'):
             from StandardFields import create_datetime_text_sub_form
@@ -834,10 +841,21 @@
                      ('day', day),
                      ('year', year)]
         result = []
+	hidden_day_part = ""
         for sub_field_name, sub_field_value in order:
+	    if hide_day and (sub_field_name == 'day'):
+	        dayvalue = sub_field_value
+		if dayvalue == None:
+		    dayvalue = "01" 
+                sub_key = field.generate_subfield_key(sub_field_name)
+                sub_field = field.sub_form.get_field(sub_field_name)
+                hidden_day_part = sub_field.widget.render_hidden(sub_field, sub_key,    
+			    			                 dayvalue, 
+							         REQUEST)
+		continue
             result.append(field.render_sub_field(sub_field_name,
                                                  sub_field_value, REQUEST))
-        date_result = string.join(result, field.get_value('date_separator'))
+        date_result = string.join(result, field.get_value('date_separator')) + hidden_day_part
         if not field.get_value('date_only'):
             time_result = (field.render_sub_field('hour', hour, REQUEST) +
                            field.get_value('time_separator') +

--Boundary-00=_Vx5ICIR7SUASBbt
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
formulator-dev mailing list
formulator-dev-IAPFreCvJWM6s/[email protected]
http://lists.infrae.com/mailman/listinfo/formulator-dev

--Boundary-00=_Vx5ICIR7SUASBbt--