[Jifty-commit] r721 - in jifty/trunk: . lib/Jifty lib/Jifty/Action/Record lib/Jifty/Web/Form/Field share/web/static/js share/web/templates/__jifty share/web/templates/__jifty/admin/fragments/list

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Mar 21 12:10:14 EST 2006


Author: alexmv
Date: Tue Mar 21 12:10:12 2006
New Revision: 721

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action/Record/Create.pm
   jifty/trunk/lib/Jifty/Action/Record/Update.pm
   jifty/trunk/lib/Jifty/Record.pm
   jifty/trunk/lib/Jifty/Web/Form/Element.pm
   jifty/trunk/lib/Jifty/Web/Form/Field/Upload.pm
   jifty/trunk/share/web/static/js/jifty.js
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list
   jifty/trunk/share/web/templates/__jifty/halo

Log:
 r11750 at zoq-fot-pik:  chmrr | 2006-03-21 12:09:55 -0500
  * BLOB and file upload fixes


Modified: jifty/trunk/lib/Jifty/Action/Record/Create.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Create.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Create.pm	Tue Mar 21 12:10:12 2006
@@ -57,7 +57,16 @@
     my $record = $self->record;
 
     my %values;
-    $values{$_} = $self->argument_value($_) for grep { defined $self->argument_value($_) } $self->argument_names;
+    for (grep { defined $self->argument_value($_) } $self->argument_names) {
+        $values{$_} = $self->argument_value($_);
+        if (ref $values{$_} eq "Fh") { # CGI.pm's "lightweight filehandle class"
+            local $/;
+            my $fh = $values{$_};
+            binmode $fh;
+            $values{$_} = scalar <$fh>;
+        }
+    }
+
     my ($id, $msg) = $record->create(%values);
 
     # Handle errors?

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	Tue Mar 21 12:10:12 2006
@@ -74,7 +74,6 @@
     my $changed = 0;
 
     for my $field ( $self->argument_names ) {
-
         # Skip values that weren't submitted
         next unless exists $self->argument_values->{$field};
 
@@ -83,11 +82,20 @@
         # Skip nonexistent fields
         next unless $column;
 
+        # Grab the value
+        my $value = $self->argument_value($field);
+
         # Boolean and integer fields should be skipped if blank.
         # (This logic should be moved into SB or something.)
         next
             if ( defined $column->type and ( $column->type =~ /^bool/i || $column->type =~ /^int/i )
-            and defined $self->argument_value($field) and $self->argument_value($field) eq '' );
+            and defined $value and $value eq '' );
+
+        if (ref $value eq "Fh") { # CGI.pm's "lightweight filehandle class"
+            local $/;
+            binmode $value;
+            $value = scalar <$value>;
+        }
 
         # Skip fields that have not changed
         my $old = $self->record->$field;
@@ -96,15 +104,14 @@
     
         # 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 $value and "$old" eq "$value" );
 
-        
         # If _both_ the values are ''
         next if (  (not defined $old or not length $old)
-                    and ( not defined $self->argument_value($field) or not length $self->argument_value($field) ));
+                    and ( not defined $value or not length $value ));
 
         my $setter = "set_$field";
-        my ( $val, $msg ) = $self->record->$setter( $self->argument_value($field) );
+        my ( $val, $msg ) = $self->record->$setter( $value );
         $self->result->field_error($field, $msg)
           if not $val and $msg;
 

Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Record.pm	Tue Mar 21 12:10:12 2006
@@ -227,13 +227,14 @@
     
 sub _value {
     my $self = shift;
+    my $column = shift;
 
-    unless ($self->check_read_rights(@_)) {
+    unless ($self->check_read_rights( $column => @_ )) {
         return (undef);
     }
-    my $value = $self->SUPER::_value(@_);
-    return $value if ref $value;
-    return   Encode::decode_utf8($value);
+    my $value = $self->SUPER::_value( $column => @_ );
+    return $value if ref $value or $self->column($column)->type eq 'blob';
+    return Encode::decode_utf8($value);
 #   This is the "Right' way to do things according to audrey, but it breaks
 #    
 #    my $value = $self->SUPER::_value(@_);

Modified: jifty/trunk/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Element.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Element.pm	Tue Mar 21 12:10:12 2006
@@ -181,8 +181,7 @@
 
             push @fragments, \%args;
         }
-        $response .= qq| $trigger="update( @{[ Jifty::JSON::objToJson( {actions => \@actions, fragments => \@fragments }, {singlequote => 1}) ]} );|;
-        $response .= qq|return false;"|;
+        $response .= qq| $trigger="update( @{[ Jifty::JSON::objToJson( {actions => \@actions, fragments => \@fragments }, {singlequote => 1}) ]} ) "|;
     }
     return $response;
 }

Modified: jifty/trunk/lib/Jifty/Web/Form/Field/Upload.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field/Upload.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field/Upload.pm	Tue Mar 21 12:10:12 2006
@@ -33,4 +33,15 @@
     '';
 }
 
+=head2 render_value
+
+The 'value', rendered, is empty so that BLOBs and the like don't get
+streamed to the browser.
+
+=cut
+
+sub render_value {
+    '';
+}
+
 1;

Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js	(original)
+++ jifty/trunk/share/web/static/js/jifty.js	Tue Mar 21 12:10:12 2006
@@ -50,6 +50,16 @@
         return serialized.join('&');
     },
 
+    // Returns true if there is a file upload form as one of our elements
+    hasUpload: function() {
+        var fields = this.fields();
+        for (var i = 0; i < fields.length; i++) {
+            if (fields[i].getAttribute("type") == "file")
+                return true;
+        }
+        return false;
+    },
+
     // Return the action as a data strcture suitible to be JSON'd
     data_structure: function() {
         var a = {};
@@ -368,8 +378,11 @@
     for (var i = 0; i < named_args['actions'].length; i++) {
         var moniker = named_args['actions'][i];
         var a = new Action(moniker);
-        if (a.register)
+        if (a.register) {
+            if (a.hasUpload)
+                return true;
             request['actions'][moniker] = a.data_structure();
+        }
     }
 
     request['fragments'] = {};
@@ -516,6 +529,7 @@
     new Ajax.Request(document.URL,
                      options
                     );
+    return false;
 }
 
 function trace( msg ){

Modified: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list	(original)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list	Tue Mar 21 12:10:12 2006
@@ -2,7 +2,6 @@
 $object_type
 $page => 1
 $new_slot => 1
-$render_submit => 1
 $item_path => "/__jifty/admin/fragments/list/view"
 </%args>
 <%init>
@@ -46,10 +45,6 @@
 % }
 </div>
 
-% if ($collection->count and $render_submit) { 
-<% Jifty->web->form->submit( label =>  "Save") %>
-% }
-
 % if ($new_slot) {
 <% Jifty->web->region(
         name => 'new_item',

Modified: jifty/trunk/share/web/templates/__jifty/halo
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/halo	(original)
+++ jifty/trunk/share/web/templates/__jifty/halo	Tue Mar 21 12:10:12 2006
@@ -113,7 +113,7 @@
 <li>
 <span class="fixed"><% $_->[1] %></span><br />
 % if (@{$_->[2]}) {
-<b>Bindings:</b> <tt><% join(',', map {defined $_ ? $_ : "undef"} @{$_->[2]}) %></tt><br />
+<b>Bindings:</b> <tt><% join(',', map {defined $_ ? ($_ =~ /\0/ ? "*BLOB*" : $_ ) : "undef"} @{$_->[2]}) %></tt><br />
 % }
 <i><% $_->[3] %> seconds</i>
 </li>


More information about the Jifty-commit mailing list