[LON-CAPA-cvs] cvs: loncom /homework grades.pm /interface portfolio.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 25 Jan 2006 22:56:26 -0000


albertel		Wed Jan 25 17:56:26 2006 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
    /loncom/homework	grades.pm 
  Log:
  - properly handle files like a.txt.pdf and ones with no extension
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.92 loncom/interface/portfolio.pm:1.93
--- loncom/interface/portfolio.pm:1.92	Mon Dec 19 18:19:18 2005
+++ loncom/interface/portfolio.pm	Wed Jan 25 17:56:11 2006
@@ -143,7 +143,7 @@
     	#$dom 
     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
     	$filename =~ s/\s+$//;
-    	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(.*)\.(.*)/)) {
+    	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
             if ($dirptr&$testdir) {
                 if ($select_mode eq 'true'){
                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.303 loncom/homework/grades.pm:1.304
--- loncom/homework/grades.pm:1.303	Tue Jan 17 18:09:50 2006
+++ loncom/homework/grades.pm	Wed Jan 25 17:56:25 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.303 2006/01/17 23:09:50 banghart Exp $
+# $Id: grades.pm,v 1.304 2006/01/25 22:56:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2410,22 +2410,23 @@
             &Apache::lonnet::logthis("should be unmarking and remarking $key",@portfiles);
             foreach my $file (@portfiles) {
                 &Apache::lonnet::unmark_as_readonly($domain,$stuname,[$symb,$env{'request.course.id'}],$file);
-                my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*$)/);
+                my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
                 my $version = 0;
-                my @answer_file_parts = split(/\./, $answer_file);
+		my ($answer_name,$answer_ver,$answer_ext) =
+		    &file_name_version_ext($answer_file);
                 my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stuname,$portfolio_root);
-                my @file_names;
-                my @file_name_parts;
                 foreach my $row (@dir_list) {
-                    @file_names = split(/\&/,$row,2);
-                    @file_name_parts = split(/\./, $file_names[0]);
-                    # ($file_name_parts[scalar @file_name_parts] eq $answer_file_parts[scalar @answer_file_parts])
-                    if (($file_name_parts[0] eq $answer_file_parts[0]) && 
-                        ($file_name_parts[-1] eq $answer_file_parts[-1])) {
+                    my ($file) = split(/\&/,$row,2);
+		    my ($file_name,$file_version,$file_ext) =
+			&file_name_version_ext($file);
+                    if (($file_name eq $answer_name) && 
+			($file_ext eq $answer_ext)) {
                         # gets here if filename and extension match, regardless of version
-                        if (scalar @file_name_parts == 3) { # a versioned file is found
-                            # so save it for later
-                            if ($file_name_parts[1] > $version) {$version = $file_name_parts[1]};
+                        if ($file_version ne '') {
+                            # a versioned file is found  so save it for later
+                            if ($file_version > $version) {
+				$version = $file_version;
+			    }
                         }
                     }
                 }
@@ -2434,11 +2435,13 @@
                 if($env{'form.copy'} eq '-1') {
                     &Apache::lonnet::logthis('problem getting file '.$directory.$answer_file);
                 } else {
-                   my $copy_result = &Apache::lonnet::finishuserfileupload($stuname,$domain,'copy',
-                                    '/portfolio'.$directory.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]);
-                    push(@v_portfiles, $directory.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]);
+		    my $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
+		    my $copy_result = &Apache::lonnet::finishuserfileupload(
+                                        $stuname,$domain,'copy',
+				        '/portfolio'.$directory.$new_answer);
+                    push(@v_portfiles, $directory.$new_answer);
                     &Apache::lonnet::mark_as_readonly($domain,$stuname,
-                                ['/portfolio'.$directory.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]],
+                                ['/portfolio'.$directory.$new_answer],
                                 [$symb,$env{'request.course.id'},'graded']);
                 }
             }
@@ -2449,6 +2452,22 @@
     
 }
 
+sub file_name_version_ext {
+    my ($file)=@_;
+    my @file_parts = split(/\./, $file);
+    my ($name,$version,$ext);
+    if (@file_parts > 1) {
+	$ext=pop(@file_parts);
+	if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
+	    $version=pop(@file_parts);
+	}
+	$name=join('.',@file_parts);
+    } else {
+	$name=join('.',@file_parts);
+    }
+    return($name,$version,$ext);
+}
+
 #--------------------------------------------------------------------------------------
 #
 #-------------------------- Next few routines handles grading by section or whole class