[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm essayresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 03 May 2005 05:31:51 -0000


This is a MIME encoded message

--albertel1115098311
Content-Type: text/plain

albertel		Tue May  3 01:31:51 2005 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm essayresponse.pm 
  Log:
  - if uploaded filetypes isn't set can upload any file
  - added a lot of debuggin info
  - actaully compiles now
  - wroks correctly in the null case
  - add non-fuctional submissions buttons to improve the look of grade mode
  - if no user to grade don't show criteria
  
  
--albertel1115098311
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050503013151.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.14 loncom/homework/bridgetask.pm:1.15
--- loncom/homework/bridgetask.pm:1.14	Mon May  2 20:05:41 2005
+++ loncom/homework/bridgetask.pm	Tue May  3 01:31:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.14 2005/05/03 00:05:41 albertel Exp $
+# $Id: bridgetask.pm,v 1.15 2005/05/03 05:31:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -52,6 +52,8 @@
     @Apache::bridgetask::instance=();
     # list of all Instance ids seen in this problem
     @Apache::bridgetask::instancelist=();
+    # key of queud user data that we are currently grading
+    $Apache::bridgetask::queue_key='';
 }
 
 sub proctor_check_auth {
@@ -174,11 +176,22 @@
 	    }
 	}
     } elsif ($target eq 'webgrade') {
-	$result.=$head_tag_start.$body_tag_start.$form_tag_start.
-	    'Yahoo!';
+	$result.=$head_tag_start.$body_tag_start.$form_tag_start;
 	$result.=&show_queue();
-	$result.=&get_from_queue();
-
+	my $todo=&get_from_queue();
+	if ($todo) {
+	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
+	    $result.="\n".'<table><tr><td>Found'.
+		$symb.':'.$uname.':'.$udom.'</td></tr></table>';
+	    $result.='<input type="hidden" name="gradingkey" value="'.
+		&HTML::Entites::encode($todo).'" />';
+	    $Apache::bridgetask::queue_key=$todo;
+	} else {
+	    $result.="\n".
+		'<table><tr><td>No user to be graded.</td></tr></table>';
+	    my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+	}
+	
     } else {
 	# page_start returned a starting result, delete it if we don't need it
 	$result = '';
@@ -191,14 +204,14 @@
     my $result='';
     my $status=$Apache::inputtags::status['-1'];
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
-	$target eq 'tex' || $target eq 'webgrade') {
+	$target eq 'tex') {
 	if (
 	    (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
 	    ($target eq 'answer') || ($target eq 'tex')
 	   ) {
 	    if ($target eq 'web') {
 		if ($status eq 'CAN_ANSWER') {
-		    $result.='<table border="1">'.
+		    $result.="\n".'<table border="1">'.
 			&Apache::inputtags::file_selector('0',"bridgetask","*",
 							  'portfolioonly').
 							  "</table>";
@@ -224,6 +237,15 @@
 		&add_to_queue();
 	    }
 	}
+    } elsif ($target eq 'webgrade') {
+	$result.="\n<hr />";
+	$result.='<input type="submit" name="next" value="'.
+	    &mt('Save & Next').'" /> ';
+	$result.='<input type="submit" name="end" value="'.
+	    &mt('Save & Stop Grading').'" /> ';
+	$result.='<input type="submit" name="end" value="'.
+	    &mt('Throw Away & Stop Grading').'" /> ';
+	$result.='</form>'.&Apache::loncommon::endbodytag().'</html>';
     } elsif ($target eq 'meta') {
 	$result.='<parameter part="0" package="Task"></parameter>'."\n";
 	#$result.=&Apache::response::meta_part_order();
@@ -250,7 +272,7 @@
     my $cdom=$env{'course.'.$cid.'.domain'};
     my $regexp="^$symb\0queue";
     my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
-    $result.="<table><tr><th>resource</th><th>user</th><th>Time available for grading</th></tr>";
+    $result.="\n<h3>Current Queue</h3><table><tr><th>resource</th><th>user</th><th>Time available for grading</th></tr>";
     foreach my $key (sort(keys(%queue))) {
 	my ($symb,undef,$user) = split("\0",$key);
 	my ($uname,$udom) = split('@',$user);
@@ -260,7 +282,7 @@
 	my %slot_data=&Apache::lonnet::get_slot($slot);
 	$result.="End time: ".&Apache::lonlocal::locallocaltime($slot_data{'endtime'})."</td></tr>";
     }
-    $result.="</table>";
+    $result.="</table><hr />\n";
     return $result;
 }
 
@@ -272,7 +294,7 @@
 }
 
 sub queue_key_locked {
-    my ($key)=@_;
+    my ($key,$cdom,$cnum)=@_;
     my ($key_locked,$value)=
 	&Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum);
     if ($key_locked eq "$key\0locked") {
@@ -282,54 +304,97 @@
 }
 
 sub pick_from_queue_data {
-    my ($check_section,$queue)=@_;
+    my ($check_section,$queue,$cdom,$cnum)=@_;
     foreach my $key (sort(keys(%$queue))) {
 	my ($symb,$uname,$udom)=&decode_queue_key($key);
 	if ($check_section) {
 	    my $section=&Apache::lonnet::getsection($uname,$udom);
-	    if ($section ne $check_section) { next; }
+	    if ($section ne $check_section) {
+		&Apache::lonnet::logthis("not my sec");
+		next;
+	    }
 	}
 	my $slot=$queue->{$key}[0];
 	my %slot_data=&Apache::lonnet::get_slot($slot);
-	if ($slot_data{'endtime'} > time) { next; }
-	if (&queue_key_locked($key)) { next; }
+	if ($slot_data{'endtime'} > time) { 
+	    &Apache::lonnet::logthis("not time");
+	    next;
+	}
+	if (&queue_key_locked($key,$cdom,$cnum)) {
+	    &Apache::lonnet::logthis("someone already has um.");
+	    next;
+	}
 	return $key;
     }
     return undef;
 }
 
+sub find_mid_grade {
+    my ($symb,$cdom,$cnum)=@_;
+    my $todo=$env{'form.gradingkey'};
+    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
+    if ($todo) {
+	my $who=&queue_key_locked($todo,$cdom,$cnum);
+	if ($who eq $me) { return $todo; }
+    }
+    my $regexp="^$symb\0.*\0locked\$";
+    my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
+    foreach my $key (keys(%locks)) {
+	my $who=$locks{$key};
+	if ($who eq $me) {
+	    $todo=$key;
+	    $todo=~s/\0locked$//;
+	    return $todo;
+	}
+    }
+    return undef;
+}
+
 sub get_from_queue {
     my $result;
     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
     my $todo;
+    # FIXME need to find if I am 'mid grading'
+    $todo=&find_mid_grade($symb,$cdom,$cnum);
+    &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
     while (1) {
 	my $starttime=time;
 	&Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},
 			     $cdom,$cnum);
+	&Apache::lonnet::logthis("$starttime");
 	my $regexp="^$symb\0queue\0";
 	my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
 	#make a pass looking for a user in my section
 	if ($env{'request.course.sec'}) {
-	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue);
+	    &Apache::lonnet::logthis("sce");
+	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
+					$cdom,$cnum);
+	    &Apache::lonnet::logthis("sce $todo");
 	}
 	# no one in our section so look for any user that is ready for grading
 	if (!$todo) {
-	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue);
+	    &Apache::lonnet::logthis("no sce");
+	    $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue,
+					$cdom,$cnum);
+	    &Apache::lonnet::logthis("no sce $todo");
 	}
 	# no user to grade 
 	if (!$todo) { last; }
+	&Apache::lonnet::logthis("got $todo");
 	# otherwise found someone so lets try to lock them
 	my $success=&Apache::lonnet::newput('gradingqueue',
 					    {"$todo\0locked"=>
 						 $env{'user.name'}.'@'.$env{'user.domain'}},
 					   $cdom,$cnum);
 	# someone else already picked them
+	&Apache::lonnet::logthis("success $todo");
 	if ($success ne 'ok') { next; }
 	my (undef,$endtime)=
 	    &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"],
 				 $cdom,$cnum);
+	&Apache::lonnet::logthis("emd  $endtime");
 	# someone else already modified the queue, 
 	# perhaps our picked user wass already fully graded between
 	# when we picked him and when we locked his record? so lets
@@ -338,13 +403,16 @@
 	    my ($key,$value)=
 		&Apache::lonnet::get('gradingqueue',["$todo"],
 				     $cdom,$cnum);
+	    &Apache::lonnet::logthis("check  $key .. $value");
 	    if ($key eq $todo && ref($value)) {
 	    } else {
 		&Apache::lonnet::del('gradingqueue',["$todo\0locked"],
 				     $cdom,$cnum);
+		&Apache::lonnet::logthis("del");
 		next;
 	    }
 	}
+	&Apache::lonnet::logthis("last $todo");
 	last;
     }
     return $todo;
@@ -398,7 +466,7 @@
 	$result=$dimension{'intro'}.$dimension{$instance.'.text'};
     } elsif ($target eq 'webgrade') {
 	my $instance=&get_instance();
-	$result.='<table>';
+	$result.="\n".'<table>';
 	foreach my $id (@{$dimension{$instance.'.criterias'}}) {
 	    $result.='<tr><td>'.
 		$dimension{$instance.'.criteria.'.$id}.'</td></tr>';
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.64 loncom/homework/essayresponse.pm:1.65
--- loncom/homework/essayresponse.pm:1.64	Mon Apr 18 20:56:39 2005
+++ loncom/homework/essayresponse.pm	Tue May  3 01:31:51 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.64 2005/04/19 00:56:39 matthew Exp $
+# $Id: essayresponse.pm,v 1.65 2005/05/03 05:31:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -164,12 +164,14 @@
 	$Apache::lonhomework::results{"resource.$part.$id.$which"}=$files;
 	my @submitted_files = split(/,/,$files);
 	my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
-	$uploadedfiletypes=~s/[^\w\,]//g;
-	$uploadedfiletypes=','.$uploadedfiletypes.',';
-	foreach my $file (@submitted_files) {
-	    my ($extension)=($file=~/\.(\w+)$/);
-	    unless ($uploadedfiletypes=~/\,$extension\,/i) {
-		$$award='INVALID_FILETYPE';
+	if ($uploadedfiletypes) {
+	    $uploadedfiletypes=~s/[^\w\,]//g;
+	    $uploadedfiletypes=','.$uploadedfiletypes.',';
+	    foreach my $file (@submitted_files) {
+		my ($extension)=($file=~/\.(\w+)$/);
+		unless ($uploadedfiletypes=~/\,$extension\,/i) {
+		    $$award='INVALID_FILETYPE';
+		}
 	    }
 	}
 	if ($$award ne 'INVALID_FILETYPE' && ref($uploadedflag)) {

--albertel1115098311--