[Jifty-commit] r1288 - in jifty: . trunk/lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Jun 14 12:28:48 EDT 2006


Author: nelhage
Date: Wed Jun 14 12:28:46 2006
New Revision: 1288

Modified:
   jifty/   (props changed)
   jifty/trunk/lib/Jifty/Action.pm
   jifty/trunk/lib/Jifty/Action/Record.pm

Log:
 r12637 at phanatique:  nelhage | 2006-06-14 12:28:43 -0400
 Canonicalizing all dates by default using Jifty::DateTime


Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Wed Jun 14 12:28:46 2006
@@ -643,6 +643,9 @@
 If it doesn't have a B<canonicalizer> attribute, but the action has a
 C<canonicalize_I<ARGUMENT>> function, also invoke that function.
 
+If neither of those are true, by default canonicalize dates using
+_canonicalize_date
+
 =cut
 
 # XXX TODO: This is named with an underscore to prevent infinite
@@ -665,11 +668,29 @@
         $value = $field_info->{canonicalizer}->( $self, $value );
     } elsif ( $self->can($default_method) ) {
         $value = $self->$default_method( $value );
+    } elsif (   defined( $field_info->{render_as} )
+             && lc( $field_info->{render_as} ) eq 'date') {
+        $value = $self->_canonicalize_date( $value );
     }
 
     $self->argument_value($field => $value);
 }
 
+
+=head2 _canonicalize_date DATE
+
+Parses and returns the date using L<Time::ParseDate>.
+
+=cut
+
+sub _canonicalize_date {
+    my $self = shift;
+    my $val = shift;
+    return undef unless defined $val and $val =~ /\S/;
+    return undef unless my $obj = Jifty::DateTime->new_from_string($val);
+    return $obj->ymd;
+}
+
 =head2 _validate_arguments
 
 Validates the form fields.  This is done by calling

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Wed Jun 14 12:28:46 2006
@@ -82,7 +82,6 @@
         }
         $self->record->load_by_primary_keys(%given_pks) if %given_pks;
     }
-
     return $self;
 }
 
@@ -233,10 +232,6 @@
         and $column->render_as eq "Date" )
       {
         $info->{'ajax_canonicalizes'} = 1;
-        $info->{'canonicalizer'} ||= sub {
-          my ( $self, $value ) = @_;
-          return _canonicalize_date( $self, $value );
-        };
       }
 
       # If we're hand-coding a render_as, hints or label, let's use it.
@@ -266,20 +261,6 @@
     return $self->record->writable_attributes;
 }
 
-=head2 _canonicalize_date DATE
-
-Parses and returns the date using L<Time::ParseDate>.
-
-=cut
-
-sub _canonicalize_date {
-    my $self = shift;
-    my $val = shift;
-    return undef unless defined $val and $val =~ /\S/;
-    return undef unless my $obj = Jifty::DateTime->new_from_string($val);
-    return $obj->ymd;
-}
-
 =head2 take_action
 
 Throws an error unless it is overridden; use


More information about the Jifty-commit mailing list