[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4978] trunk



Revision: 4978
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4978&view=rev
Author:   einhverfr
Date:     2012-07-14 00:21:58 +0000 (Sat, 14 Jul 2012)
Log Message:
-----------
Retrieving specific customers/vendors now works via REST
One other relevant change is that there is also escaping logic in LedgerSMB::Template::TXT.  This just inspects, calls to_output, and copies.

Modified Paths:
--------------
    trunk/LedgerSMB/REST_Class/Contact.pm
    trunk/LedgerSMB/Template/TXT.pm
    trunk/rest-handler.pl

Modified: trunk/LedgerSMB/REST_Class/Contact.pm
===================================================================
--- trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-13 16:01:36 UTC (rev 4977)
+++ trunk/LedgerSMB/REST_Class/Contact.pm	2012-07-14 00:21:58 UTC (rev 4978)
@@ -40,7 +40,7 @@
     my ($request) = @_;
     my $id = $request->{classes}->{$cname};
     my $data;
-    if (defined $id){
+    if ($id or ($id eq '0')){
        my $company = LedgerSMB::DBObject::Entity::Company->get($id);
        if ($company){
           $data= $company;
@@ -51,7 +51,7 @@
              $data= $person;
              $data->{entity_type} = 'Person';
           } else {
-             die '404  Not Found';
+             die '404 Not Found';
           }
        }
        @{$data->{credit_accounts}} = 

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2012-07-13 16:01:36 UTC (rev 4977)
+++ trunk/LedgerSMB/Template/TXT.pm	2012-07-14 00:21:58 UTC (rev 4978)
@@ -67,8 +67,38 @@
     return "${name}.". get_extension($parent);
 }
 
-sub preprocess { # TODO handling of objects with to_output methods
+sub preprocess { 
+    # I wonder how much of this can be concentrated in the main template
+    # module? --CT
     my $rawvars = shift;
+    my $vars;
+    if (eval {$rawvars->can('to_output')}){
+        $rawvars = $rawvars->to_output;
+    }
+    my $type = ref $rawvars;
+
+    return $rawvars if $type =~ /^LedgerSMB::Locale/;
+    return unless defined $rawvars;
+    if ( $type eq 'ARRAY' ) {
+        for (@{$rawvars}) {
+            push @{$vars}, preprocess( $_ );
+        }
+    } elsif (!$type) {
+        return $rawvars;
+    } elsif ($type eq 'SCALAR' or $type eq 'Math::BigInt::GMP') {
+        return $$rawvars;
+    } elsif ($type eq 'CODE'){
+        return $rawvars;
+    } elsif ($type eq 'IO::File'){
+        return undef;
+    } else { # Hashes and objects
+        for ( keys %{$rawvars} ) {
+            $vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
+        }
+    }
+     
+    return $vars;
+    my $rawvars = shift;
     return $rawvars;
 }
 

Modified: trunk/rest-handler.pl
===================================================================
--- trunk/rest-handler.pl	2012-07-13 16:01:36 UTC (rev 4977)
+++ trunk/rest-handler.pl	2012-07-14 00:21:58 UTC (rev 4978)
@@ -150,6 +150,8 @@
 use Try::Tiny;
 use LedgerSMB::App_State;
 use LedgerSMB::Locale;
+use LedgerSMB::Sysconfig;
+use LedgerSMB::Template::TXT;
 use strict;
 use warnings;
 
@@ -203,7 +205,13 @@
 
     my $content;
     my $ctype;
-    warn $fmtpackage;
+
+    # We are going to re-use template escaping logic here.  Since TXT generally
+    # does not escape values but just returns a sanitized data tree (calling
+    # to_output where appropriate, we will use that.  --CT
+
+    $return_info = LedgerSMB::Template::TXT::preprocess($return_info);
+
     if ($return_info){
         if ($fmtpackage->can('to_output')){
             $content = $fmtpackage->can('to_output')->($request, $return_info);
@@ -230,8 +238,8 @@
     # Sometimes the two lines below can be useful for debugging.  Note they 
     # turn all errors into internal server errors and populate the logs with 
     # all kinds of stuff --CT
-    #use Carp;
-    #Carp::confess();
+    # use Carp;
+    # Carp::confess();
     my $content = $error;
     $content =~ s/^\d\d\d\s//;
     $error =~ s/\n/: /m;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.