[Jifty-commit] r2065 - in jifty/trunk: lib/Jifty/Action/Record lib/Jifty/Plugin lib/Jifty/Plugin/REST t/TestApp/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Oct 25 02:00:02 EDT 2006


Author: jesse
Date: Wed Oct 25 02:00:01 2006
New Revision: 2065

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action/Record/Search.pm
   jifty/trunk/lib/Jifty/Plugin/REST.pm
   jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
   jifty/trunk/t/TestApp/t/12-search.t

Log:
 r29270 at pinglin:  jesse | 2006-10-24 22:59:15 -0700
  negative searchng for Search actions


Modified: jifty/trunk/lib/Jifty/Action/Record/Search.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Search.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Search.pm	Wed Oct 25 02:00:01 2006
@@ -85,24 +85,24 @@
         # Magic _id refers_to columns
         next if($field =~ /^(.*)_id$/ && $self->record->column($1));
 
+        my $label = $info->{label} || $field;
+        $args->{"${field}_not"} = {%$info, label => "$label is not"};
         if($column->type =~ /^(?:text|varchar)/i) {
             $info->{render_as} = 'text';
-            my $label = $info->{label} || $field;
             $args->{"${field}_contains"} = {%$info, label => "$label contains"};
             $args->{"${field}_lacks"} = {%$info, label => "$label lacks"};
         } elsif($column->type =~ /(?:date|time)/) {
-            my $label = $info->{label} || $field;
             $args->{"${field}_after"} = {%$info, label => "$label after"};
             $args->{"${field}_before"} = {%$info, label => "$label before"};
         } elsif(    $column->type =~ /(?:int)/
                 && !$column->refers_to) {
-            my $label = $info->{label} || $field;
             $args->{"${field}_gt"} = {%$info, label => "$label greater than"};
             $args->{"${field}_lt"} = {%$info, label => "$label less than"};
         }
     }
 
     $args->{contains} = {type => 'text', label => 'Any field contains'};
+    $args->{lacks} = {type => 'text', label => 'No field contains'};
 
     return $self->_cached_arguments($args);
 }
@@ -144,7 +144,9 @@
             if($field =~ m{^(.*)_([[:alpha:]]+)$}) {
                 $field = $1;
                 $op = $2;
-                if($op eq 'contains') {
+                if($op eq 'not') {
+                    $op = '!=';
+                } elsif($op eq 'contains') {
                     $op = 'LIKE';
                     $value = "%$value%";
                 } elsif($op eq 'lacks') {
@@ -162,6 +164,13 @@
         
         if(defined($value)) {
             next if $value =~ /^\s*$/;
+           
+            if ($op && $op =~ /^(?:!=|NOT LIKE)$/) {
+                $collection->limit( column   => $field, value    => $value, operator => $op || "=", entry_aggregator => 'OR', $op ? (case_sensitive => 0) : (),);
+                $collection->limit( column   => $field, value    => 'NULL', operator => 'IS');
+            } else { 
+
+            
             $collection->limit(
                 column   => $field,
                 value    => $value,
@@ -169,6 +178,10 @@
                 entry_aggregator => 'AND',
                 $op ? (case_sensitive => 0) : (),
                );
+
+            } 
+
+
         } else {
             $collection->limit(
                 column   => $field,

Modified: jifty/trunk/lib/Jifty/Plugin/REST.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/REST.pm	Wed Oct 25 02:00:01 2006
@@ -5,4 +5,23 @@
 use base qw/Jifty::Plugin/;
 
 our $VERSION = 0.01;
+
+=head1 NAME
+
+Jifty::Plugin::REST
+
+=head1 DESCRIPTION
+
+A RESTian web services API for your Jifty app.
+
+=head1 USAGE
+
+Add the following to your site_config.yml
+
+ framework:
+   Plugins:
+     - REST: {}
+ 
+
+=cut
 1;

Modified: jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm	Wed Oct 25 02:00:01 2006
@@ -1,7 +1,9 @@
-use strict;
+package Jifty::Plugin::REST::Dispatcher;
 use warnings;
 
-package Jifty::Plugin::REST::Dispatcher;
+
+
+
 use CGI qw( start_html end_html ul li a dl dt dd );
 use Jifty::Dispatcher -base;
 use Jifty::YAML ();

Modified: jifty/trunk/t/TestApp/t/12-search.t
==============================================================================
--- jifty/trunk/t/TestApp/t/12-search.t	(original)
+++ jifty/trunk/t/TestApp/t/12-search.t	Wed Oct 25 02:00:01 2006
@@ -12,7 +12,8 @@
 use lib 't/lib';
 use Jifty::SubTest;
 
-use Jifty::Test qw(no_plan);
+use Jifty::Test tests => 53;
+
 
 my $user = TestApp::Model::User->new(current_user => TestApp::CurrentUser->superuser);
 
@@ -155,6 +156,24 @@
 is($result->count, 1);
 is($result->first->name, 'third_user');
 
+
+
+# exact negative searching
+$search->argument_values({ name_not => 'third_user'});
+$search->run;
+
+$result = $search->result->content('search');
+
+isa_ok($result, 'Jifty::Collection');
+is($result->count, 2);
+ok($result->first->name =~ /test/, "it's a test user" );
+
+
+
+
+
+
+
 # This is case insensitive substring
 $search->argument_values({name_contains => 'TEST'});
 $search->run;
@@ -211,4 +230,4 @@
 $result = $search->result->content('search');
 
 isa_ok($result, 'Jifty::Collection');
-is($result->count, 0);
+is($result->count, 0, "found nothing");


More information about the Jifty-commit mailing list