[Jifty-commit] r680 - jifty/trunk jifty/trunk/lib/Jifty jifty/trunk/lib/Jifty/Action/Record

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Mar 8 01:47:48 EST 2006


Author: jesse
Date: Wed Mar  8 01:47:46 2006
New Revision: 680

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

Log:
 r25819 at truegrounds:  jesse | 2006-03-07 22:46:53 -0800
 * Autocomplete and canonicalization fixes.


Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Wed Mar  8 01:47:46 2006
@@ -42,6 +42,7 @@
 requires('Jifty::DBI' => '0.16' );            # Jifty::DBI::Collection Jifty::DBI::Handle Jifty::DBI::Record::Cachable Jifty::DBI::SchemaGenerator
 requires('Locale::Maketext::Simple');
 requires('Log::Log4perl');
+requires('LWP::UserAgent');
 requires('Math::BigInt');
 requires('Module::Install::Admin' => '0.50');
 requires('Module::Pluggable' => '2.95');

Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Wed Mar  8 01:47:46 2006
@@ -167,7 +167,7 @@
     my $self = shift;
     $self->check_authorization || return;
     $self->setup || return;
-    $self->_canonicalize_arguments || return;
+    $self->_canonicalize_arguments;
     $self->_validate_arguments;
 }
 
@@ -537,15 +537,9 @@
     my $self   = shift;
     my @fields = $self->argument_names;
 
-    my $all_fields_ok = 1;
     foreach my $field (@fields) {
-        next unless $field and exists $self->argument_values->{$field};
-        unless ( $self->_canonicalize_argument($field) ) {
-
-            $all_fields_ok = 0;
-        }
+        $self->_canonicalize_argument($field) if exists $self->argument_values->{$field};
     }
-    return $all_fields_ok;
 }
 
 
@@ -574,17 +568,14 @@
     if ( $field_info->{canonicalizer}
         and UNIVERSAL::isa( $field_info->{canonicalizer}, 'CODE' ) )
     {
-        return $field_info->{canonicalizer}->( $self, $value );
+        $value = $field_info->{canonicalizer}->( $self, $value );
     }
 
     elsif ( $self->can($default_method) ) {
-        return $self->$default_method( $value );
+        $value = $self->$default_method( $value );
     }
 
-    # If none of the checks have failed so far, then it's ok
-    else {
-        return $field;
-    }
+    $self->argument_value($field => $value);
 }
 
 =head2 _validate_arguments
@@ -702,7 +693,7 @@
 
     if ( $field_info->{autocompleter}  )
     {
-        return $field_info->{autocompleter}->(  $value );
+        return $field_info->{autocompleter}->( $self, $value );
     }
 
     elsif ( $self->can($default_autocomplete) ) {

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Wed Mar  8 01:47:46 2006
@@ -192,10 +192,23 @@
    
         my $autocomplete_method = "autocomplete_".$field;
         if ($self->record->can($autocomplete_method) ) {
-            $info->{'autocompleter'} = sub { 
-                    my $value = shift;
-                    return $self->record->$autocomplete_method( $value);
-                };
+            $info->{'autocompleter'} ||= sub { 
+                my($self, $value) = @_;
+                return $self->record->$autocomplete_method( $value);
+            };
+        }
+
+	my $canonicalize_method = "canonicalize_".$field;
+        if ($self->record->can($canonicalize_method) ) {
+            $info->{'canonicalizer'} ||= sub {
+                my($self, $value) = @_;
+                return $self->record->$canonicalize_method( $value );
+            };
+        } elsif (defined $column->render_as and $column->render_as eq "Date") {
+            $info->{'canonicalizer'} ||= sub {
+                my($self, $value) = @_;
+                return _canonicalize_date($self, $value );
+            };
         }
 
 
@@ -213,30 +226,6 @@
 }
 
 
-=head2 _canonicalize_argument ARGUMENT_NAME
-
-Canonicalizes the argument named ARGUMENT_NAME. This routine actually
-just makes sure we canonicalize dates and then passes on to the
-superclass.
-
-=cut
-
-
-sub _canonicalize_argument {
-    my $self = shift;
-    my $arg_name = shift;
-
-
-    if (exists $self->arguments->{$arg_name}->{'render_as'} 
-     and $self->arguments->{$arg_name}->{'render_as'} eq 'Date') {
-        my $value = $self->_canonicalize_date($self->argument_value($arg_name));
-        $self->argument_value($arg_name => $value);
-    }
-
-    return($self->SUPER::_canonicalize_argument($arg_name));
-
-}
-
 =head2 _canonicalize_date DATE
 
 Parses and returns the date using L<Time::ParseDate>.

Modified: jifty/trunk/lib/Jifty/Action/Record/Update.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Update.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Update.pm	Wed Mar  8 01:47:46 2006
@@ -95,7 +95,7 @@
     
         # if both the new and old values are defined and equal, we don't want to change em
         # XXX TODO "$old" is a cheap hack to scalarize datetime objects
-        next if ( defined $old and defined $self->argument_value($field) and "$old" eq $self->argument_value($field) );
+        next if ( defined $old and defined $self->argument_value($field) and "$old" eq "".$self->argument_value($field) );
 
         
         # If _both_ the values are ''


More information about the Jifty-commit mailing list