[open-ils-commits] [GIT] Evergreen ILS branch rel_2_3 updated. 44f601f85bd37095fa986ac43e13d851c243ba42

Evergreen Git git at git.evergreen-ils.org
Mon Aug 20 16:17:18 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_3 has been updated
       via  44f601f85bd37095fa986ac43e13d851c243ba42 (commit)
       via  d2f0443d1299e4593fb6a3998c63addb137fc17a (commit)
       via  7339fcdfdc41e6dee2fc7a5eac058313646342d4 (commit)
       via  d6067b6fe02a994926a490c3e4326de74a2e12b0 (commit)
      from  a5822e48bdc361a40e436f5c58e27d7c79875f86 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 44f601f85bd37095fa986ac43e13d851c243ba42
Author: Dan Scott <dscott at laurentian.ca>
Date:   Fri Aug 17 15:06:59 2012 -0400

    TPAC i18n: Turn UA locales into Evergreen locales
    
    We need to convert the likes of fr_ca into fr-CA to be able to pull the
    appropriate localized values from the database via CStoreEditor.
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
index 02cf017..44c6018 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
@@ -170,9 +170,8 @@ sub load_context {
         $cgi->cookie(OILS_HTTP_COOKIE_LOCALE) || 
         parse_accept_lang($r->headers_in->get('Accept-Language')) || 'en_us';
 
-
     # set the editor default locale for each page load
-    $OpenILS::Utils::CStoreEditor::default_locale = $ctx->{locale};
+    $OpenILS::Utils::CStoreEditor::default_locale = parse_eg_locale($ctx->{locale});
 
     my $mprefix = $ctx->{media_prefix};
     if($mprefix and $mprefix !~ /^http/ and $mprefix !~ /^\//) {
@@ -183,7 +182,7 @@ sub load_context {
     return $ctx;
 }
 
-# turn Accept-Language into sometihng EG can understand
+# turn Accept-Language into something EG can understand
 # TODO: try all langs, not just the first
 sub parse_accept_lang {
     my $al = shift;
@@ -195,6 +194,18 @@ sub parse_accept_lang {
     return $locale;
 }
 
+# Accept-Language uses locales like 'en', 'fr', 'fr_fr', while Evergreen
+# internally uses 'en-US', 'fr-CA', 'fr-FR' (always with the 2 lowercase,
+# hyphen, 2 uppercase convention)
+sub parse_eg_locale {
+    my $ua_locale = shift || 'en_us';
+
+    $ua_locale =~ m/^(..).?(..)?$/;
+    my $lang_code = lc($1);
+    my $region_code = $2 ? uc($2) : uc($1);
+    return "$lang_code-$region_code";
+}
+
 # Given a URI, finds the configured template and any extra page 
 # arguments (trailing path info).  Any extra data is returned
 # as page arguments, in the form of an array, one item per 

commit d2f0443d1299e4593fb6a3998c63addb137fc17a
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Aug 17 10:11:50 2012 -0400

    Make tpac cache locale-aware
    
    Add a locale level to the TPAC object cache.  Each component of the
    cache now looks like $cache{$component}{$locale}{stuff...}
    
    e.g. $cache{list}{en_ca}{aout} = [...] # en_ca-fetched org unit types
    
    The calling code in the templates requires no changes (abstraction
    FTW).
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
index eb0c703..e7e3bd1 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
@@ -11,12 +11,14 @@ my $U = 'OpenILS::Application::AppUtils';
 
 my $ro_object_subs; # cached subs
 our %cache = ( # cached data
-    map => {aou => {}}, # others added dynamically as needed
-    list => {},
-    search => {},
-    org_settings => {},
-    eg_cache_hash => undef,
-    search_filter_groups => {}
+    map => {en_us => {}},
+    list => {en_us => {}},
+    search => {en_us => {}},
+    org_settings => {en_us => {}},
+    search_filter_groups => {en_us => {}},
+    aou_tree => {en_us => undef},
+    aouct_tree => {},
+    eg_cache_hash => undef
 );
 
 sub init_ro_object_cache {
@@ -24,7 +26,7 @@ sub init_ro_object_cache {
     my $e = $self->editor;
     my $ctx = $self->ctx;
 
-    # reset org unit setting cache on each page load to avoid the 
+    # reset org unit setting cache on each page load to avoid the
     # requirement of reloading apache with each org-setting change
     $cache{org_settings} = {};
 
@@ -55,17 +57,17 @@ sub init_ro_object_cache {
         # Retrieve the full set of objects with class $hint
         $ro_object_subs->{$list_key} = sub {
             my $method = "retrieve_all_$eclass";
-            $cache{list}{$hint} = $e->$method() unless $cache{list}{$hint};
-            return $cache{list}{$hint};
+            $cache{list}{$ctx->{locale}}{$hint} = $e->$method() unless $cache{list}{$ctx->{locale}}{$hint};
+            return $cache{list}{$ctx->{locale}}{$hint};
         };
-    
+
         # locate object of class $hint with Ident field $id
         $cache{map}{$hint} = {};
         $ro_object_subs->{$get_key} = sub {
             my $id = shift;
-            return $cache{map}{$hint}{$id} if $cache{map}{$hint}{$id}; 
-            ($cache{map}{$hint}{$id}) = grep { $_->$ident_field eq $id } @{$ro_object_subs->{$list_key}->()};
-            return $cache{map}{$hint}{$id};
+            return $cache{map}{$ctx->{locale}}{$hint}{$id} if $cache{map}{$ctx->{locale}}{$hint}{$id};
+            ($cache{map}{$ctx->{locale}}{$hint}{$id}) = grep { $_->$ident_field eq $id } @{$ro_object_subs->{$list_key}->()};
+            return $cache{map}{$ctx->{locale}}{$hint}{$id};
         };
 
         # search for objects of class $hint where field=value
@@ -76,7 +78,7 @@ sub init_ro_object_cache {
             my $cacheval = $val;
             if (ref $val) {
                 $val = [sort(@$val)] if ref $val eq 'ARRAY';
-                $cacheval = OpenSRF::Utils::JSON->perl2JSON($val); 
+                $cacheval = OpenSRF::Utils::JSON->perl2JSON($val);
                 #$self->apache->log->info("cacheval : $cacheval");
             }
             my $search_obj = {$field => $val};
@@ -84,17 +86,17 @@ sub init_ro_object_cache {
                 $search_obj->{$filterfield} = $filterval;
                 $cacheval .= ':' . $filterfield . ':' . $filterval;
             }
-            $cache{search}{$hint}{$field} = {} unless $cache{search}{$hint}{$field};
-            $cache{search}{$hint}{$field}{$cacheval} = $e->$method($search_obj) 
-                unless $cache{search}{$hint}{$field}{$cacheval};
-            return $cache{search}{$hint}{$field}{$cacheval};
+            #$cache{search}{$ctx->{locale}}{$hint}{$field} = {} unless $cache{search}{$ctx->{locale}}{$hint}{$field};
+            $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval} = $e->$method($search_obj)
+                unless $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval};
+            return $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval};
         };
     }
 
     $ro_object_subs->{aou_tree} = sub {
 
         # fetch the org unit tree
-        unless($cache{aou_tree}) {
+        unless($cache{aou_tree}{$ctx->{locale}}) {
             my $tree = $e->search_actor_org_unit([
 			    {   parent_ou => undef},
 			    {   flesh            => -1,
@@ -108,16 +110,17 @@ sub init_ro_object_cache {
             sub flesh_aout {
                 my $node = shift;
                 my $ro_object_subs = shift;
+                my $ctx = shift;
                 $node->ou_type( $ro_object_subs->{get_aout}->($node->ou_type) );
-                $cache{map}{aou}{$node->id} = $node;
-                flesh_aout($_, $ro_object_subs) foreach @{$node->children};
+                $cache{map}{$ctx->{locale}}{aou}{$node->id} = $node;
+                flesh_aout($_, $ro_object_subs, $ctx) foreach @{$node->children};
             };
-            flesh_aout($tree, $ro_object_subs);
+            flesh_aout($tree, $ro_object_subs, $ctx);
 
-            $cache{aou_tree} = $tree;
+            $cache{aou_tree}{$ctx->{locale}} = $tree;
         }
 
-        return $cache{aou_tree};
+        return $cache{aou_tree}{$ctx->{locale}};
     };
 
     # Add a special handler for the tree-shaped org unit cache
@@ -125,20 +128,20 @@ sub init_ro_object_cache {
         my $org_id = shift;
         return undef unless defined $org_id;
         $ro_object_subs->{aou_tree}->(); # force the org tree to load
-        return $cache{map}{aou}{$org_id};
+        return $cache{map}{$ctx->{locale}}{aou}{$org_id};
     };
 
     # Returns a flat list of aou objects.  often easier to manage than a tree.
     $ro_object_subs->{aou_list} = sub {
         $ro_object_subs->{aou_tree}->(); # force the org tree to load
-        return [ values %{$cache{map}{aou}} ];
+        return [ values %{$cache{map}{$ctx->{locale}}{aou}} ];
     };
 
     $ro_object_subs->{aouct_tree} = sub {
 
         # fetch the org unit tree
-        unless(exists $cache{aouct_tree}) {
-            $cache{aouct_tree} = undef;
+        unless(exists $cache{aouct_tree}{$ctx->{locale}}) {
+            $cache{aouct_tree}{$ctx->{locale}} = undef;
 
             my $tree_id = $e->search_actor_org_unit_custom_tree(
                 {purpose => 'opac', active => 't'},
@@ -169,11 +172,11 @@ sub init_ro_object_cache {
                     }
                 }
 
-                $cache{aouct_tree} = $node_tree->org_unit;
+                $cache{aouct_tree}{$ctx->{locale}} = $node_tree->org_unit;
             }
         }
 
-        return $cache{aouct_tree};
+        return $cache{aouct_tree}{$ctx->{locale}};
     };
 
     # turns an ISO date into something TT can understand
@@ -195,14 +198,11 @@ sub init_ro_object_cache {
     $ro_object_subs->{get_org_setting} = sub {
         my($org_id, $setting) = @_;
 
-        $cache{org_settings}{$org_id} = {} 
-            unless $cache{org_settings}{$org_id};
-
-        $cache{org_settings}{$org_id}{$setting} = 
+        $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting} =
             $U->ou_ancestor_setting_value($org_id, $setting)
-                unless exists $cache{org_settings}{$org_id}{$setting};
+                unless exists $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
 
-        return $cache{org_settings}{$org_id}{$setting};
+        return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
     };
 
     $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;

commit 7339fcdfdc41e6dee2fc7a5eac058313646342d4
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Aug 17 10:10:55 2012 -0400

    Set the default CStoreEditor locale on page load
    
    Ech CStoreEditor request will use the locale of the current
    page as the default opensrf session locale.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
index 25285b1..02cf017 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
@@ -170,6 +170,10 @@ sub load_context {
         $cgi->cookie(OILS_HTTP_COOKIE_LOCALE) || 
         parse_accept_lang($r->headers_in->get('Accept-Language')) || 'en_us';
 
+
+    # set the editor default locale for each page load
+    $OpenILS::Utils::CStoreEditor::default_locale = $ctx->{locale};
+
     my $mprefix = $ctx->{media_prefix};
     if($mprefix and $mprefix !~ /^http/ and $mprefix !~ /^\//) {
         # if a hostname is provided /w no protocol, match the protocol to the current page

commit d6067b6fe02a994926a490c3e4326de74a2e12b0
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Aug 17 10:08:16 2012 -0400

    CStoreEditor default session locale
    
    Adds a new package-level variable:
    
    $OpenILS::Utils::CStoreEditor::default_locale
    
    If set, this value is used as the session_locale for new opensrf client
    sessions.  If unset, the session_locale remains untouched by
    CStoreEditor.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
index d41e435..51854e3 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
@@ -13,6 +13,10 @@ my %PERMS;
 my $cache;
 my %xact_ed_cache;
 
+# if set, we will use this locale for all new sessions
+# if unset, we rely on the existing opensrf locale propagation
+our $default_locale;
+
 our $always_xact = 0;
 our $_loaded = 1;
 
@@ -207,8 +211,17 @@ sub session {
 	my( $self, $session ) = @_;
 	$self->{session} = $session if $session;
 
+	# sessions can stick around longer than a single request/transaction.
+	# kill it if our default locale was altered since the last request
+	# and it does not match the locale of the existing session.
+	delete $self->{session} if
+		$default_locale and
+		$self->{session} and
+		$self->{session}->session_locale ne $default_locale;
+
 	if(!$self->{session}) {
 		$self->{session} = OpenSRF::AppSession->create($self->app);
+		$self->{session}->session_locale($default_locale) if $default_locale;
 
 		if( ! $self->{session} ) {
 			my $str = "Error creating cstore session with OpenSRF::AppSession->create()!";

-----------------------------------------------------------------------

Summary of changes:
 .../src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm |   13 ++++
 .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm   |   72 ++++++++++----------
 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm     |   17 +++++-
 3 files changed, 65 insertions(+), 37 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list