[open-ils-commits] r10306 - in trunk/Open-ILS: examples
examples/templates src/support-scripts
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Aug 7 15:33:23 EDT 2008
Author: erickson
Date: 2008-08-07 15:33:15 -0400 (Thu, 07 Aug 2008)
New Revision: 10306
Added:
trunk/Open-ILS/examples/templates/overdue_combined_xml.example
Modified:
trunk/Open-ILS/examples/opensrf.xml.example
trunk/Open-ILS/examples/templates/overdue_7day.example
trunk/Open-ILS/examples/templates/predue_1day.example
trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl
Log:
added logic for generating a template from the combined overdue data (e.g. xml file). added sample combined xml file.
Modified: trunk/Open-ILS/examples/opensrf.xml.example
===================================================================
--- trunk/Open-ILS/examples/opensrf.xml.example 2008-08-07 17:16:30 UTC (rev 10305)
+++ trunk/Open-ILS/examples/opensrf.xml.example 2008-08-07 19:33:15 UTC (rev 10306)
@@ -59,6 +59,7 @@
<!-- The system can generate an XML file of overdue notices. This is the
directory where they are stored. Files are named overdue.YYYY-MM-DD.xml -->
<notice_dir>/openils/var/data/overdue</notice_dir>
+ <combined_template>/openils/var/data/templates/overdue_combined_xml.example</combined_template>
<notice>
<!-- Notify at 7 days overdue -->
@@ -69,7 +70,7 @@
<!-- do we attempt email notification? -->
<email_notify>true</email_notify>
<!-- notice template file -->
- <template>/openils/var/data/templates/overdue_7day.example</template>
+ <email_template>/openils/var/data/templates/overdue_7day.example</email_template>
</notice>
</overdue>
@@ -85,7 +86,7 @@
<notify_interval>1 day</notify_interval>
<file_append>false</file_append>
<email_notify>true</email_notify>
- <template>/openils/var/data/templates/predue_1day.example</template>
+ <email_template>/openils/var/data/templates/predue_1day.example</email_template>
</notice>
</predue>
</notifications>
Modified: trunk/Open-ILS/examples/templates/overdue_7day.example
===================================================================
--- trunk/Open-ILS/examples/templates/overdue_7day.example 2008-08-07 17:16:30 UTC (rev 10305)
+++ trunk/Open-ILS/examples/templates/overdue_7day.example 2008-08-07 19:33:15 UTC (rev 10306)
@@ -1,3 +1,4 @@
+[%- USE date -%]
[%- SET user = circ_list.0.usr -%]
[%- SET lib = circ_list.0.circ_lib -%]
To: [% user.email %]
@@ -12,9 +13,8 @@
[% FOREACH circ = circ_list %]
[% get_bib_attr(circ, 'title') %], by [% get_bib_attr(circ, 'author') %]
Call Number: [% circ.target_copy.call_number.label %]
- [%- SET date = parse_due_date(circ) %]
- Due Date: [% date.year %]-[% date.month %]-[% date.day -%]
- [%- IF date.hour -%] [% date.hour %]:[% date.minute %] [%- END %]
+ [%- SET due_date = parse_due_date(circ) %]
+ Due Date: [% date.format(due_date, '%Y-%m-%d') %]
Barcode: [% circ.target_copy.barcode %]
[% END %]
@@ -25,9 +25,8 @@
Contact your library for more information:
[% lib.name %]
-[%- SET addr = lib.mailing_address -%]
-[%- IF !addr -%] [%- SET addr = lib.billing_address -%] [%- END %]
-[% lib.mailing_address.street1 %] [% lib.mailing_address.street2 %]
+[% lib.mailing_address.street1 %]
+[% lib.mailing_address.street2 %]
[% lib.mailing_address.city %], [% lib.mailing_address.state %]
[% lib.mailing_address.post_code %]
[% lib.phone %]
Added: trunk/Open-ILS/examples/templates/overdue_combined_xml.example
===================================================================
--- trunk/Open-ILS/examples/templates/overdue_combined_xml.example (rev 0)
+++ trunk/Open-ILS/examples/templates/overdue_combined_xml.example 2008-08-07 19:33:15 UTC (rev 10306)
@@ -0,0 +1,53 @@
+[% USE date %]
+<?xml version='1.0' encoding='UTF-8'?>
+<file type="notice" date="[% date.format(date.now,'%Y-%m-%d') %]" time="[% date.format(date.now, '%H:%M:%S') %]">
+ [%- FOREACH circ_set = overdues %]
+ <notice type='overdue' notify_interval='[% circ_set.notice.notify_interval %]'>
+ [%- SET user = circ_set.circ_list.0.usr -%]
+ [%- SET lib = circ_set.circ_list.0.circ_lib -%]
+ [%- SET user_addr = user.mailing_address -%]
+ [%- IF !user_addr -%]
+ [%- SET user_addr = user.billing_address -%]
+ [%- END %]
+ [%- SET lib_addr = lib.mailing_address -%]
+ [%- IF !lib_addr -%]
+ [%- SET lib_addr = lib.billing_address -%]
+ [%- END %]
+ <patron>
+ <barcode>[% user.card.barcode %]</barcode>
+ <first_given_name>[% user.first_given_name %]</first_given_name>
+ <family_name>[% user.family_name %]</family_name>
+ <addr_street1>[% escape_xml(user_addr.street1) %]</addr_street1>
+ <addr_street2>[% escape_xml(user_addr.street2) %]</addr_street2>
+ <addr_city>[% escape_xml(user_addr.city) %]</addr_city>
+ <addr_state>[% user_addr.state %]</addr_state>
+ <addr_post_code>[% user_addr.post_code %]</addr_post_code>
+ <email>[% user.email %]</email>
+ <sys_id>[% user.id %]</sys_id>
+ </patron>
+ <location>
+ <name>[% escape_xml(lib.name) %]</name>
+ <phone>[% lib.phone %]</phone>
+ <addr_street1>[% escape_xml(lib_addr.street1) %]</addr_street1>
+ <addr_street2>[% escape_xml(lib_addr.street2) %]</addr_street2>
+ <addr_city>[% escape_xml(lib_addr.city) %]</addr_city>
+ <addr_state>[% lib_addr.state %]</addr_state>
+ <addr_post_code>[% lib_addr.post_code %]</addr_post_code>
+ <email>[% lib.email %]</email>
+ <sys_id>[% lib.id %]</sys_id>
+ </location>
+ [%- FOREACH circ = circ_set.circ_list %]
+ [%- SET due_date = parse_due_date(circ) %]
+ <item>
+ <title>[% escape_xml(get_bib_attr(circ, 'title')) %]</title>
+ <author>[% escape_xml(get_bib_attr(circ, 'author')) %]</author>
+ <due_date>[% date.format(due_date, '%Y-%m-%d') %]</due_date>
+ <call_number>[% escape_xml(circ.target_copy.call_number.label) %]</call_number>
+ <barcode>[% escape_xml(circ.target_copy.barcode) %]</barcode>
+ <circ_id>[% circ.id %]</circ_id>
+ </item>
+ [%- END %]
+ </notice>
+ [%- END %]
+</file>
+
Modified: trunk/Open-ILS/examples/templates/predue_1day.example
===================================================================
--- trunk/Open-ILS/examples/templates/predue_1day.example 2008-08-07 17:16:30 UTC (rev 10305)
+++ trunk/Open-ILS/examples/templates/predue_1day.example 2008-08-07 19:33:15 UTC (rev 10306)
@@ -1,3 +1,4 @@
+[%- USE date -%]
[%- SET user = circ_list.0.usr -%]
[%- SET lib = circ_list.0.circ_lib -%]
To: [% user.email %]
@@ -12,9 +13,8 @@
[% FOREACH circ = circ_list %]
[% get_bib_attr(circ, 'title') %], by [% get_bib_attr(circ, 'author') %]
Call Number: [% circ.target_copy.call_number.label %]
- [%- SET date = parse_due_date(circ) %]
- Due Date: [% date.year %]-[% date.month %]-[% date.day -%]
- [%- IF date.hour -%] [% date.hour %]:[% date.minute %] [%- END %]
+ [%- SET due_date = parse_due_date(circ) %]
+ Due Date: [% date.format(due_date, '%Y-%m-%d') %]
Barcode: [% circ.target_copy.barcode %]
[% END %]
Modified: trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl 2008-08-07 17:16:30 UTC (rev 10305)
+++ trunk/Open-ILS/src/support-scripts/generate_circ_notices.pl 2008-08-07 19:33:15 UTC (rev 10306)
@@ -35,8 +35,10 @@
my $settings = undef;
my $e = OpenILS::Utils::CStoreEditor->new;
+my @global_overdue_circs; # all circ collections stored here go into the final global XML file
+
my ($osrf_config, $send_email, $gen_day_intervals, $days_back) =
- ('/openils/conf/opensrf_core.xml', 1, 0, 0);
+ ('/openils/conf/opensrf_core.xml', 0, 0, 0);
GetOptions(
'osrf_osrf_config=s' => \$osrf_config,
@@ -85,9 +87,33 @@
generate_notice_set($_, 'overdue') for @overdues;
generate_notice_set($_, 'predue') for @predues;
+
+ generate_global_overdue_file();
}
+sub generate_global_overdue_file {
+ $logger->info("notice: processing ".scalar(@global_overdue_circs)." for global template");
+ return unless @global_overdue_circs;
+ my $tt = Template->new({ABSOLUTE => 1});
+
+ $tt->process(
+ $settings->config_value(notifications => overdue => 'combined_template'),
+ {
+ overdues => \@global_overdue_circs,
+ get_bib_attr => \&get_bib_attr,
+ parse_due_date => \&parse_due_date, # let the templates decide date format
+ escape_xml => \&escape_xml,
+ },
+ \&global_overdue_output
+ ) or $logger->error('notice: Template error '.$tt->error);
+}
+
+sub global_overdue_output {
+ print shift() . "\n";
+}
+
+
sub generate_notice_set {
my($notice, $type) = @_;
@@ -116,7 +142,7 @@
};
# if a circ duration is defined for this type of notice
- if(my $durs = $settings->{circ_duration_range}) {
+ if(my $durs = $notice->{circ_duration_range}) {
$QUERY->{where}->{'+circ'}->{duration} = {between => [$durs->{from}, $durs->{to}]};
}
@@ -175,16 +201,27 @@
notifications => $type => 'sender_address') ||
$settings->config_value(notifications => 'sender_address');
- $tt->process(
- $notice->{template},
- { circ_list => $circ_list,
- get_bib_attr => \&get_bib_attr,
- parse_due_date => \&parse_due_date, # let the templates decide date format
- smtp_sender => $sender,
- smtp_repley => $sender # XXX
- },
- \&handle_template_output
- ) or $logger->error('notice: Template error '.$tt->error);
+ my $context = {
+ circ_list => $circ_list,
+ get_bib_attr => \&get_bib_attr,
+ parse_due_date => \&parse_due_date, # let the templates decide date format
+ smtp_sender => $sender,
+ smtp_repley => $sender, # XXX
+ notice => $notice,
+ };
+
+ push(@global_overdue_circs, $context) if
+ $type eq 'overdue' and $notice->{file_append} =~ /always/i;
+
+ if($send_email and $circ_list->[0]->usr->email) {
+ if(my $tmpl = $notice->{email_template}) {
+ $tt->process($tmpl, $context, \&email_template_output)
+ or $logger->error('notice: Template error '.$tt->error);
+ }
+ } else {
+ push(@global_overdue_circs, $context)
+ if $type eq 'overdue' and $notice->{file_append} =~ /noemail/i;
+ }
}
sub get_bib_attr {
@@ -201,31 +238,35 @@
}
}
+# provides a date that Template::Plugin::Date can parse
sub parse_due_date {
my $circ = shift;
my $due = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($circ->due_date));
- my $info = {
- year => $due->year,
- month => sprintf("%0.2d",$due->month),
- day => sprintf("%0.2d", $due->day)
- };
+ return sprintf(
+ "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.2d",
+ $due->hour,
+ $due->minute,
+ $due->second,
+ $due->day,
+ $due->month,
+ $due->year
+ );
+}
- # for day-based circulations, hour and minute are not relevant
- return $info if (OpenSRF::Utils->interval_to_seconds($circ->duration) % 86400) == 0;
-
- $info->{hour} = sprintf("%0.2d",$due->hour);
- $info->{minute} = sprintf("%0.2d",$due->minute);
- return $info;
+sub escape_xml {
+ my $str = shift;
+ $str =~ s/&/&/sog;
+ $str =~ s/</</sog;
+ $str =~ s/>/>/sog;
+ return $str;
}
-sub handle_template_output {
+sub email_template_output {
my $str = shift;
print "$str\n";
}
-
-
sub fetch_circ_data {
my @circs = @_;
More information about the open-ils-commits
mailing list