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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 09 Feb 2006 22:34:35 -0000


albertel		Thu Feb  9 17:34:35 2006 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - make it easier to regrade a specific user.
  
  
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.104 loncom/homework/bridgetask.pm:1.105
--- loncom/homework/bridgetask.pm:1.104	Wed Feb  8 17:44:14 2006
+++ loncom/homework/bridgetask.pm	Thu Feb  9 17:34:35 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.104 2006/02/08 22:44:14 albertel Exp $
+# $Id: bridgetask.pm,v 1.105 2006/02/09 22:34:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -198,9 +198,19 @@
 	$result.='<p>'.&mt("Review Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
 	$result.=' <input type="submit" name="reviewasubmission" value="'.
 	    &mt("Select an entry from the review queue").'" /> </p>'."\n";
-	$result.=' <input type="submit" name="regradeasubmission" value="'.
+	$result.='<p> <input type="submit" name="regradeasubmission" value="'.
 	    &mt("Select a user to regrade.").'" /> </p>'."\n";
-    }
+	$result.='<p> <input type="submit" name="regradeaspecificsubmission" value="'.
+	    &mt("Regrade user:").'" />'."\n";
+	$result.='<input type="text" size="12" name="gradinguser" />';
+	$result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
+						     'gradingdomain');
+	$result.=' '.
+	    &Apache::loncommon::selectstudent_link('gradesubmission',
+						   'gradinguser',
+						   'gradingdomain');
+	$result.=&Apache::loncommon::studentbrowser_javascript();
+  }
     return $result;
 }
 
@@ -515,7 +525,7 @@
         #       Hrrm, vaildation pass should perhaps say 'not_locked'
         #       perhaps do a search if there is a key that is mine and if
         #       there isn't reshow the queue....
-	my ($todo,$status_code)=&get_key_todo($target);
+	my ($todo,$status_code,$msg)=&get_key_todo($target);
 
 	if ($todo) {
 	    &setup_env_for_other_user($todo,$safeeval);
@@ -544,7 +554,7 @@
 		if      ($status_code eq 'stop') {
 		    $result.='<b>'.&mt("Stopped grading.").'</b>'.$back;
 		} elsif ($status_code eq 'lock_failed') {
-		    $result.='<b>'.&mt("Failed to lock the request record.")
+		    $result.='<b>'.&mt("Failed to lock the requested record.")
 			.'</b>'.$back;
 		} elsif ($status_code eq 'unlock') {
 		    $result.='<b>'.&mt("Unlocked the requested record.")
@@ -556,6 +566,8 @@
 		    $result.=&select_user();
 		} elsif ($status_code eq 'unable') {
 		    $result.='<b>'.&mt("Unable to aqcuire a user to grade.").'</b>'.$back;
+		} elsif ($status_code eq 'not_allowed') {
+		    $result.='<b>'.&mt('Not allowed to grade the requested user.').' '.$msg.'</b>'.$back;
 		} else {
 		    $result.='<b>'.&mt("No user to be graded.").'</b>'.$back;
 		}
@@ -622,6 +634,57 @@
 	return (undef,'select_user');
     }
 
+
+    my $me=$env{'user.name'}.'@'.$env{'user.domain'};
+
+    #need to try both queues..
+    if (defined($env{'form.regradeaspecificsubmission'}) &&
+	defined($env{'form.gradinguser'})               &&
+	defined($env{'form.gradingdomain'})               ) {
+	my ($symb,$cid)=&Apache::lonxml::whichuser();
+	my $cnum  = $env{'course.'.$cid.'.num'};
+	my $cdom  = $env{'course.'.$cid.'.domain'};
+	my $uname = $env{'form.gradinguser'};
+	my $udom  = $env{'form.gradingdomain'};
+
+	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
+
+	my $queue;
+
+	if      (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
+	    $env{'form.queue'} = $queue = 'gradingqueue';
+	} elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
+	    $env{'form.queue'} = $queue = 'reviewqueue';
+	}
+	
+	if (!$queue) {
+	    $env{'form.queue'} = $queue = 'none';
+	    #not queued so doing either a re or pre grade
+	    return ($gradingkey);
+	}
+
+	my $who=&queue_key_locked($queue,$gradingkey);
+	if ($who eq $me) {
+	    #already have the lock
+	    $env{'form.gradingkey'}=&Apache::lonnet::escape($gradingkey);
+	    return ($gradingkey);
+	}
+	
+	if (!defined($who)) {
+	    if (&lock_key($queue,$gradingkey)) {
+		return ($gradingkey);
+	    } else {
+		return (undef,'lock_failed');
+	    }
+	}
+
+	#otherwise (defined($who) && $who ne $me) some else has it...
+	return (undef,'not_allowed',
+		&mt('Another user ([_1]) currently has the record for [_2] locked.',
+		    $who,$env{'form.gradinguser'}.'@'.$env{'form.gradingdomain'}));
+    }
+
+
     my $queue=$env{'form.queue'};
 
     if (!defined($queue)) {
@@ -649,7 +712,6 @@
 	&& $env{'form.queuemode'} eq 'selected') {
 	
 	my $who=&queue_key_locked($queue,$gradingkey);
-	my $me=$env{'user.name'}.'@'.$env{'user.domain'};
 	if ($who eq $me) {
 	    &Apache::lonxml::debug("Found a key was given to me");
 	    return ($gradingkey,'selected');