[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm studentcalc.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 05 Sep 2003 01:57:54 -0000
This is a MIME encoded message
--matthew1062727074
Content-Type: text/plain
matthew Thu Sep 4 21:57:54 2003 EDT
Modified files:
/loncom/interface/spreadsheet Spreadsheet.pm classcalc.pm
studentcalc.pm assesscalc.pm
Log:
Clear package variables on both normal completion and on interruption.
--matthew1062727074
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030904215754.txt"
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.22 loncom/interface/spreadsheet/Spreadsheet.pm:1.23
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.22 Thu Sep 4 21:06:45 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm Thu Sep 4 21:57:54 2003
@@ -1,5 +1,5 @@
#
-# $Id: Spreadsheet.pm,v 1.22 2003/09/05 01:06:45 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.23 2003/09/05 01:57:54 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -231,6 +231,16 @@
# the descendents of the spreadsheet class.
}
+sub clear_package {
+ # This method is here to remind you that it will be overridden by
+ # the descendents of the spreadsheet class.
+}
+
+sub cleanup {
+ my $self = shift();
+ $self->clear_package();
+}
+
sub initialize_spreadsheet_package {
&load_spreadsheet_expirationdates();
&clear_spreadsheet_definition_cache();
@@ -1341,6 +1351,7 @@
sub outsheet_excel {
my $self = shift;
my ($r) = @_;
+ my $connection = $r->connection();
$r->print("<h2>Preparing Excel Spreadsheet</h2>");
#
# Create excel worksheet
@@ -1364,7 +1375,7 @@
$self->excel_output_row($worksheet,0,$rows_output++,'Summary');
$rows_output++; # skip a line
#
- $self->excel_rows($worksheet,$cols_output,$rows_output);
+ $self->excel_rows($connection,$worksheet,$cols_output,$rows_output);
#
#
# Close the excel file
@@ -1382,6 +1393,7 @@
sub outsheet_csv {
my $self = shift;
my ($r) = @_;
+ my $connection = $r->connection();
my $csvdata = '';
my @Values;
#
@@ -1405,7 +1417,7 @@
}
#
# Output the body of the spreadsheet
- $self->csv_rows($file);
+ $self->csv_rows($connection,$file);
#
# Close the csv file
close($file);
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.11 loncom/interface/spreadsheet/classcalc.pm:1.12
--- loncom/interface/spreadsheet/classcalc.pm:1.11 Thu Sep 4 21:06:45 2003
+++ loncom/interface/spreadsheet/classcalc.pm Thu Sep 4 21:57:54 2003
@@ -1,5 +1,5 @@
#
-# $Id: classcalc.pm,v 1.11 2003/09/05 01:06:45 matthew Exp $
+# $Id: classcalc.pm,v 1.12 2003/09/05 01:57:54 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -73,6 +73,11 @@
return;
}
+sub clear_package {
+ undef(@Students);
+ &Apache::studentcalc::clear_package();
+}
+
sub html_header {
my $self = shift;
my ($toprow,$bottomrow);
@@ -257,6 +262,8 @@
sub compute {
my $self = shift;
my ($r) = @_;
+ my $connection = $r->connection();
+ if ($connection->aborted()) { $self->cleanup(); return; }
$self->initialize_safe_space();
my %c = $self->constants();
my %f = $self->formulas();
@@ -269,10 +276,13 @@
&Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
'Processing first student');
foreach my $student (@Students) {
+ if ($connection->aborted()) { $self->cleanup(); return; }
my $sname = $student->{'username'}.':'.$student->{'domain'};
my $studentsheet = Apache::studentcalc->new
($student->{'username'},$student->{'domain'},undef);
- my @exportdata = $studentsheet->export_data();
+ if ($connection->aborted()) { $self->cleanup(); return; }
+ my @exportdata = $studentsheet->export_data($r);
+ if ($connection->aborted()) { $self->cleanup(); return; }
my $rownum = $self->get_row_number_from_key($sname);
$f{'A'.$rownum} = $sname;
$self->{'row_source'}->{$rownum} = $sname;
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.17 loncom/interface/spreadsheet/studentcalc.pm:1.18
--- loncom/interface/spreadsheet/studentcalc.pm:1.17 Thu Sep 4 21:06:45 2003
+++ loncom/interface/spreadsheet/studentcalc.pm Thu Sep 4 21:57:54 2003
@@ -1,5 +1,5 @@
#
-# $Id: studentcalc.pm,v 1.17 2003/09/05 01:06:45 matthew Exp $
+# $Id: studentcalc.pm,v 1.18 2003/09/05 01:57:54 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -103,6 +103,7 @@
sub clear_package {
undef(@Sequences);
undef(%Exportrows);
+ &Apache::assesscalc::clear_package();
}
sub get_title {
@@ -414,6 +415,9 @@
sub compute {
my $self = shift;
+ my ($r) = @_;
+ my $connection = $r->connection();
+ if ($connection->aborted()) { $self->cleanup; return; }
if (! defined($current_course) ||
$current_course ne $ENV{'request.course.id'}) {
$current_course = $ENV{'request.course.id'};
@@ -440,6 +444,7 @@
foreach my $seq (@sequences) {
next if ($seq->{'num_assess'}<1);
foreach my $resource (@{$seq->{'contents'}}) {
+ if ($connection->aborted()) { $self->cleanup(); return; }
next if ($resource->{'type'} ne 'assessment');
my $rownum = $self->get_row_number_from_key($resource->{'symb'});
my $cell = 'A'.$rownum;
@@ -450,11 +455,13 @@
$self->{'row_source'}->{$rownum} = $assess_filename;
}
$f{$cell} = $resource->{'symb'}.'__&&&__'.$assess_filename;
+ if ($connection->aborted()) { $self->cleanup(); return; }
my $assessSheet = Apache::assesscalc->new($self->{'name'},
$self->{'domain'},
$assess_filename,
$resource->{'symb'});
- my @exportdata = $assessSheet->export_data();
+ my @exportdata = $assessSheet->export_data($r);
+ if ($connection->aborted()) { $self->cleanup(); return; }
if ($assessSheet->blackout()) {
$self->blackout(1);
$self->{'blackout_rows'}->{$rownum} = 1;
@@ -615,6 +622,8 @@
#############################################
sub export_data {
my $self = shift;
+ my ($r) = @_;
+ my $connection = $r->connection();
my $student = $self->{'name'}.':'.$self->{'domain'};
if (! exists($Exportrows{$student}) ||
! defined($Exportrows{$student}) ||
@@ -623,8 +632,9 @@
! exists($Exportrows{$student}->{'time'}) ||
! defined($Exportrows{$student}->{'time'}) ||
! $self->check_expiration_time($Exportrows{$student}->{'time'})) {
- $self->compute();
+ $self->compute($r);
}
+ if ($connection->aborted()) { $self->cleanup(); return; }
my @Data = @{$Exportrows{$student}->{'data'}};
for (my $i=0; $i<=$#Data;$i++) {
$Data[$i]="'".$Data[$i]."'" if ($Data[$i]=~/\D/ && defined($Data[$i]));
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.18 loncom/interface/spreadsheet/assesscalc.pm:1.19
--- loncom/interface/spreadsheet/assesscalc.pm:1.18 Thu Sep 4 21:06:45 2003
+++ loncom/interface/spreadsheet/assesscalc.pm Thu Sep 4 21:57:54 2003
@@ -1,5 +1,5 @@
#
-# $Id: assesscalc.pm,v 1.18 2003/09/05 01:06:45 matthew Exp $
+# $Id: assesscalc.pm,v 1.19 2003/09/05 01:57:54 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -208,11 +208,17 @@
########################################################
sub ensure_current_parameter_caches {
my $self = shift;
+ ##
+ ## Check for a modified parameters
+ ##
if (! defined($current_course) ||
$current_course ne $ENV{'request.course.id'} ) {
$current_course = $ENV{'request.course.id'};
undef(%courseopt);
}
+ ##
+ ## Check for new user
+ ##
if (! defined($current_name) || $current_name ne $self->{'name'} ||
! defined($current_domain) || $current_domain ne $self->{'domain'}) {
$current_domain = $self->{'domain'};
@@ -518,6 +524,9 @@
sub compute {
my $self = shift;
+ my ($r) = @_;
+ my $connection = $r->connection();
+ if ($connection->aborted()) { $self->cleanup(); return; }
# $self->logthis('computing');
$self->initialize_safe_space();
#########################################
@@ -556,7 +565,9 @@
}
#
# Get the values of the metadata fields
+ if ($connection->aborted()) { $self->cleanup(); return; }
$self->ensure_current_parameter_caches();
+ if ($connection->aborted()) { $self->cleanup(); return; }
my $filename = $self->{'coursefilename'}.'_parms.db';
if (tie(%parmhash,'GDBM_File',
$self->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
@@ -568,6 +579,7 @@
} else {
$self->logthis('unable to tie '.$filename);
}
+ if ($connection->aborted()) { $self->cleanup(); return; }
#
# Clean out unnecessary parameters
foreach (keys(%parameters)) {
@@ -602,8 +614,10 @@
}
}
}
+ if ($connection->aborted()) { $self->cleanup(); return; }
#
# Move the parameters into the spreadsheet
+ if ($connection->aborted()) { $self->cleanup(); return; }
while (my ($parm,$value) = each(%parameters)) {
my $cell = 'A'.$self->get_row_number_from_key($parm);
$f{$cell} = $parm;
@@ -612,6 +626,7 @@
}
$self->formulas(\%f);
$self->constants(\%c);
+ if ($connection->aborted()) { $self->cleanup(); return; }
$self->calcsheet();
#
# Store export row in cache
@@ -622,6 +637,7 @@
# Save the export data
$self->save_export_data();
$self->save() if ($self->need_to_save());
+ if ($connection->aborted()) { $self->cleanup(); return; }
return;
}
@@ -731,6 +747,8 @@
#############################################
sub export_data {
my $self = shift;
+ my ($r) = @_;
+ my $connection = $r->connection();
my $symb = $self->{'symb'};
if (! exists($ENV{'request.role.adv'}) || ! $ENV{'request.role.adv'} ||
! exists($Exportrows{$symb}) || ! defined($Exportrows{$symb}) ||
@@ -739,8 +757,9 @@
! defined($Exportrows{$symb}->{$self->{'filename'}}) ||
! ref($Exportrows{$symb}->{$self->{'filename'}})
) {
- $self->compute();
+ $self->compute($r);
}
+ if ($connection->aborted()) { $self->cleanup(); return; }
my @Data = @{$Exportrows{$symb}->{$self->{'filename'}}};
if ($Data[0] =~ /^(.*)___=___/) {
$self->{'sheetname'} = $1;
--matthew1062727074--