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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 03 May 2005 06:44:57 -0000


albertel		Tue May  3 02:44:57 2005 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
    /loncom/homework	bridgetask.pm 
  Log:
  - setup env so lonxml::whichuser returns data for user being graded
  - need to reset rndseed, since we don't know til the end of <Task> who we are grading
  - remember who we are grading
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.372 loncom/xml/lonxml.pm:1.373
--- loncom/xml/lonxml.pm:1.372	Thu Apr  7 02:56:27 2005
+++ loncom/xml/lonxml.pm	Tue May  3 02:44:56 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.372 2005/04/07 06:56:27 albertel Exp $
+# $Id: lonxml.pm,v 1.373 2005/05/03 06:44:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -784,13 +784,18 @@
 # $safeeval->deny(":base_orig");
   $safeeval->permit("require");
   $safeinit .= ';$external::target="'.$target.'";';
-  my $rndseed;
-  my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
-  $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
-  $safeinit .= ';$external::randomseed="'.$rndseed.'";';
-  &Apache::lonxml::debug("Setting rndseed to $rndseed");
   &Apache::run::run($safeinit,$safeeval);
+  &initialize_rndseed($safeeval);
+}
 
+sub initialize_rndseed {
+    my ($safeeval)=@_;
+    my $rndseed;
+    my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
+    $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
+    my $safeinit = '$external::randomseed="'.$rndseed.'";';
+    &Apache::lonxml::debug("Setting rndseed to $rndseed");
+    &Apache::run::run($safeinit,$safeeval);
 }
 
 sub default_homework_load {
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.15 loncom/homework/bridgetask.pm:1.16
--- loncom/homework/bridgetask.pm:1.15	Tue May  3 01:31:51 2005
+++ loncom/homework/bridgetask.pm	Tue May  3 02:44:56 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.15 2005/05/03 05:31:51 albertel Exp $
+# $Id: bridgetask.pm,v 1.16 2005/05/03 06:44:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -95,14 +95,17 @@
 sub start_Task {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 
-    &Apache::structuretags::initialize_storage();
-    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
     my ($status,$accessmsg,$slot);
+    if ($target ne 'webgrade') {
+	&Apache::structuretags::initialize_storage();
+	&Apache::lonhomework::showhash(%Apache::lonhomework::history);
+    } 
+
     $Apache::lonhomework::parsing_a_task=1;
     #should get back a <html> or the neccesary stuff to start XML/MathML
     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
-
+    
     if ($target eq 'web') {
 	$body_tag_start.=&add_previous_version_button();
 	if ($Apache::lonhomework::modifygrades) {
@@ -177,15 +180,20 @@
 	}
     } elsif ($target eq 'webgrade') {
 	$result.=$head_tag_start.$body_tag_start.$form_tag_start;
+	$result.=
+	    '<input type="hidden" name="grade_target" value="webgrade" />';
 	$result.=&show_queue();
 	my $todo=&get_from_queue();
 	if ($todo) {
+	    &setup_env_for_other_user($todo,$safeeval);
 	    my ($symb,$uname,$udom)=&decode_queue_key($todo);
-	    $result.="\n".'<table><tr><td>Found'.
-		$symb.':'.$uname.':'.$udom.'</td></tr></table>';
+	    $result.="\n".'<table><tr><td>Found '.
+		&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
 	    $result.='<input type="hidden" name="gradingkey" value="'.
-		&HTML::Entites::encode($todo).'" />';
+		&Apache::lonnet::escape($todo).'" />';
 	    $Apache::bridgetask::queue_key=$todo;
+	    &Apache::structuretags::initialize_storage();
+	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
 	} else {
 	    $result.="\n".
 		'<table><tr><td>No user to be graded.</td></tr></table>';
@@ -255,12 +263,21 @@
     return $result;
 }
 
+sub setup_env_for_other_user {
+    my ($queue_key,$safeeval)=@_;
+    my ($symb,$uname,$udom)=&decode_queue_key($queue_key);
+    $env{'form.grade_symb'}=$symb;
+    $env{'form.grade_domain'}=$udom;
+    $env{'form.grade_username'}=$uname;
+    $env{'form.grade_courseid'}=$env{'request.course.id'};
+    &Apache::lonxml::initialize_rndseed($safeeval);
+}
+
 sub add_to_queue {
     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
     my %data;
-    #$data{"$symb\0timestamp"}=time;
     $data{"$symb\0queue\0$uname\@$udom"}=[$Apache::inputtags::slot_name];
     &Apache::lonnet::put('gradingqueue',\%data,$cdom,$cnum);
 }
@@ -270,17 +287,29 @@
     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
-    my $regexp="^$symb\0queue";
+    my $regexp="^$symb\0";
     my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp);
-    $result.="\n<h3>Current Queue</h3><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>type</th><th>data</th></tr>";
     foreach my $key (sort(keys(%queue))) {
-	my ($symb,undef,$user) = split("\0",$key);
-	my ($uname,$udom) = split('@',$user);
-	my $title=&Apache::lonnet::gettitle($symb);
-	$result.="<tr><td>$title</td><td>$uname</td><td>";
-	my $slot=$queue{$key}->[0];
-	my %slot_data=&Apache::lonnet::get_slot($slot);
-	$result.="End time: ".&Apache::lonlocal::locallocaltime($slot_data{'endtime'})."</td></tr>";
+	if ($key=~/locked$/) {
+	    my ($symb,$uname,$udom) = &decode_queue_key($key);
+	    my $title=&Apache::lonnet::gettitle($symb);
+	    $result.="<tr><td>$title</td><td>$uname</td><td>";
+	    $result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
+	} elsif ($key=~/timestamp$/) {
+	    my ($symb,undef) = split("\0",$key);
+	    my $title=&Apache::lonnet::gettitle($symb);
+	    $result.="<tr><td>$title</td><td></td><td>";
+	    $result.='<td>last queue modification time</td><td>'.
+		&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
+	} else {
+	    my ($symb,$uname,$udom) = &decode_queue_key($key);
+	    my $title=&Apache::lonnet::gettitle($symb);
+	    $result.="<tr><td>$title</td><td>$uname</td><td>";
+	    my $slot=$queue{$key}->[0];
+	    my %slot_data=&Apache::lonnet::get_slot($slot);
+	    $result.='<td>queue entry</td><td>End time: '.&Apache::lonlocal::locallocaltime($slot_data{'endtime'})."</td></tr>";
+	}
     }
     $result.="</table><hr />\n";
     return $result;
@@ -305,7 +334,7 @@
 
 sub pick_from_queue_data {
     my ($check_section,$queue,$cdom,$cnum)=@_;
-    foreach my $key (sort(keys(%$queue))) {
+    foreach my $key (keys(%$queue)) {
 	my ($symb,$uname,$udom)=&decode_queue_key($key);
 	if ($check_section) {
 	    my $section=&Apache::lonnet::getsection($uname,$udom);
@@ -331,7 +360,7 @@
 
 sub find_mid_grade {
     my ($symb,$cdom,$cnum)=@_;
-    my $todo=$env{'form.gradingkey'};
+    my $todo=&Apache::lonnet::unescape($env{'form.gradingkey'});
     my $me=$env{'user.name'}.'@'.$env{'user.domain'};
     if ($todo) {
 	my $who=&queue_key_locked($todo,$cdom,$cnum);
@@ -359,6 +388,7 @@
     # 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)));
+    if ($todo) { return $todo; }
     while (1) {
 	my $starttime=time;
 	&Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime},