Skip to content

Commit c8f88ce

Browse files
committed
Regularize the warning system.
Channels for warning_messages for debug_messages and for internal_debug_messages were established. There are two older channels "warnings" and "errors" that are still defined in the $pg object. "errors" is related to translator errors.
1 parent e1e8162 commit c8f88ce

File tree

4 files changed

+155
-134
lines changed

4 files changed

+155
-134
lines changed

conf/templates/math2/system.template

+55-56
Original file line numberDiff line numberDiff line change
@@ -93,67 +93,66 @@
9393
including the warning messages below.
9494
</p>
9595
</div>
96-
<!--#else-->
97-
<!--#if can="output_problem_body"-->
98-
<!-- ==== in this case print body parts --ELSE-- print entire body -->
99-
<div class="Body" style="background-color:#ffffff">
100-
101-
<!--#if can="output_custom_edit_message"-->
102-
<!--#output_custom_edit_message-->
103-
<!--#endif-->
104-
<!--#if can="output_summary"-->
105-
<!--#output_summary-->
106-
</div>
107-
<!--#endif-->
108-
109-
<!--#if can="output_hidden_info"-->
110-
<!--#output_hidden_info-->
111-
<!--#endif-->
112-
113-
<!--#if can="output_form_start"-->
114-
<!--#output_form_start-->
115-
<!--#if can="output_problem_body" can="output_message" can="output_editorLink"-->
116-
<div class="problem">
117-
<!--#if can="output_problem_body"-->
118-
<!--#output_problem_body-->
119-
<!--#endif-->
120-
<!--#if can="output_message"-->
121-
<!--#output_message-->
122-
<!--#endif-->
123-
<!--#if can="output_editorLink"-->
124-
<!--#output_editorLink-->
125-
<!--#endif-->
126-
</div>
96+
<!--#endif -->
97+
<!--#if can="output_problem_body"-->
98+
<!-- ==== print body parts if possible -->
99+
<div class="Body" style="background-color:#ffffff">
100+
101+
<!--#if can="output_custom_edit_message"-->
102+
<!--#output_custom_edit_message-->
103+
<!--#endif-->
104+
<!--#if can="output_summary"-->
105+
<!--#output_summary-->
106+
<!--#endif-->
107+
108+
<!--#if can="output_hidden_info"-->
109+
<!--#output_hidden_info-->
110+
<!--#endif-->
111+
112+
<!--#if can="output_form_start"-->
113+
<!--#output_form_start-->
114+
<!--#if can="output_problem_body" can="output_message" can="output_editorLink"-->
115+
<div class="problem">
116+
<!--#if can="output_problem_body"-->
117+
<!--#output_problem_body-->
127118
<!--#endif-->
128-
<!--#if can="output_checkboxes" can="output_submit_buttons"-->
129-
<p>
130-
<!--#if can="output_checkboxes"-->
131-
<!--#output_checkboxes-->
132-
<!--#endif-->
133-
<!--#if can="output_submit_buttons"-->
134-
<!--#output_submit_buttons-->
135-
<!--#endif-->
136-
</p>
119+
<!--#if can="output_message"-->
120+
<!--#output_message-->
137121
<!--#endif-->
138-
<!--#if can="output_score_summary"-->
139-
<div class="scoreSummary">
140-
<!--#output_score_summary-->
141-
</div>
122+
<!--#if can="output_editorLink"-->
123+
<!--#output_editorLink-->
142124
<!--#endif-->
143-
<!--#if can="output_misc"-->
144-
<!--#output_misc-->
125+
</div>
126+
<!--#endif-->
127+
<!--#if can="output_checkboxes" can="output_submit_buttons"-->
128+
<p>
129+
<!--#if can="output_checkboxes"-->
130+
<!--#output_checkboxes-->
145131
<!--#endif-->
146-
</form>
147-
<!--#endif-->
132+
<!--#if can="output_submit_buttons"-->
133+
<!--#output_submit_buttons-->
134+
<!--#endif-->
135+
</p>
136+
<!--#endif-->
137+
<!--#if can="output_score_summary"-->
138+
<div class="scoreSummary">
139+
<!--#output_score_summary-->
140+
</div>
141+
<!--#endif-->
142+
<!--#if can="output_misc"-->
143+
<!--#output_misc-->
144+
<!--#endif-->
145+
</form>
146+
</div>
147+
<!-- ==== end printing body parts -->
148+
<!--#else-->
149+
<!-- ==== couldn't print body parts so we'll print entire body -->
150+
<div class="Body" style="background-color:#ffffff">
151+
<!--#body-->
148152
</div>
149-
150-
<!--#else-->
151-
<!-- ==== couldn't print body parts so we'll print entire body -->
152-
<div class="Body" style="background-color:#ffffff">
153-
<!--#body-->
154-
</div>
155-
<!--#endif-->
156-
153+
<!-- ==== end printing entire body ===>
154+
<!--#endif-->
155+
157156
<!--#endif-->
158157
<!-- ==============END BODY OF PROBLEM=============== -->
159158
<!--#if can="output_past_answer_button" can="output_email_instructor"-->

conf/templates/math3/system.template

+55-56
Original file line numberDiff line numberDiff line change
@@ -93,67 +93,66 @@
9393
including the warning messages below.
9494
</p>
9595
</div>
96-
<!--#else-->
97-
<!--#if can="output_problem_body"-->
98-
<!-- ==== in this case print body parts --ELSE-- print entire body -->
99-
<div class="Body" style="background-color:#ffffff">
100-
101-
<!--#if can="output_custom_edit_message"-->
102-
<!--#output_custom_edit_message-->
103-
<!--#endif-->
104-
<!--#if can="output_summary"-->
105-
<!--#output_summary-->
106-
</div>
107-
<!--#endif-->
108-
109-
<!--#if can="output_hidden_info"-->
110-
<!--#output_hidden_info-->
111-
<!--#endif-->
112-
113-
<!--#if can="output_form_start"-->
114-
<!--#output_form_start-->
115-
<!--#if can="output_problem_body" can="output_message" can="output_editorLink"-->
116-
<div class="problem">
117-
<!--#if can="output_problem_body"-->
118-
<!--#output_problem_body-->
119-
<!--#endif-->
120-
<!--#if can="output_message"-->
121-
<!--#output_message-->
122-
<!--#endif-->
123-
<!--#if can="output_editorLink"-->
124-
<!--#output_editorLink-->
125-
<!--#endif-->
126-
</div>
96+
<!--#endif -->
97+
<!--#if can="output_problem_body"-->
98+
<!-- ==== print body parts if possible -->
99+
<div class="Body" style="background-color:#ffffff">
100+
101+
<!--#if can="output_custom_edit_message"-->
102+
<!--#output_custom_edit_message-->
103+
<!--#endif-->
104+
<!--#if can="output_summary"-->
105+
<!--#output_summary-->
106+
<!--#endif-->
107+
108+
<!--#if can="output_hidden_info"-->
109+
<!--#output_hidden_info-->
110+
<!--#endif-->
111+
112+
<!--#if can="output_form_start"-->
113+
<!--#output_form_start-->
114+
<!--#if can="output_problem_body" can="output_message" can="output_editorLink"-->
115+
<div class="problem">
116+
<!--#if can="output_problem_body"-->
117+
<!--#output_problem_body-->
127118
<!--#endif-->
128-
<!--#if can="output_checkboxes" can="output_submit_buttons"-->
129-
<p>
130-
<!--#if can="output_checkboxes"-->
131-
<!--#output_checkboxes-->
132-
<!--#endif-->
133-
<!--#if can="output_submit_buttons"-->
134-
<!--#output_submit_buttons-->
135-
<!--#endif-->
136-
</p>
119+
<!--#if can="output_message"-->
120+
<!--#output_message-->
137121
<!--#endif-->
138-
<!--#if can="output_score_summary"-->
139-
<div class="scoreSummary">
140-
<!--#output_score_summary-->
141-
</div>
122+
<!--#if can="output_editorLink"-->
123+
<!--#output_editorLink-->
142124
<!--#endif-->
143-
<!--#if can="output_misc"-->
144-
<!--#output_misc-->
125+
</div>
126+
<!--#endif-->
127+
<!--#if can="output_checkboxes" can="output_submit_buttons"-->
128+
<p>
129+
<!--#if can="output_checkboxes"-->
130+
<!--#output_checkboxes-->
145131
<!--#endif-->
146-
</form>
147-
<!--#endif-->
132+
<!--#if can="output_submit_buttons"-->
133+
<!--#output_submit_buttons-->
134+
<!--#endif-->
135+
</p>
136+
<!--#endif-->
137+
<!--#if can="output_score_summary"-->
138+
<div class="scoreSummary">
139+
<!--#output_score_summary-->
140+
</div>
141+
<!--#endif-->
142+
<!--#if can="output_misc"-->
143+
<!--#output_misc-->
144+
<!--#endif-->
145+
</form>
146+
</div>
147+
<!-- ==== end printing body parts -->
148+
<!--#else-->
149+
<!-- ==== couldn't print body parts so we'll print entire body -->
150+
<div class="Body" style="background-color:#ffffff">
151+
<!--#body-->
148152
</div>
149-
150-
<!--#else-->
151-
<!-- ==== couldn't print body parts so we'll print entire body -->
152-
<div class="Body" style="background-color:#ffffff">
153-
<!--#body-->
154-
</div>
155-
<!--#endif-->
156-
153+
<!-- ==== end printing entire body ===>
154+
<!--#endif-->
155+
157156
<!--#endif-->
158157
<!-- ==============END BODY OF PROBLEM=============== -->
159158
<!--#if can="output_past_answer_button" can="output_email_instructor"-->

lib/WeBWorK/ContentGenerator.pm

+3-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,9 @@ sub if_warnings {
12371237
my ($self, $arg) = @_;
12381238
my $r = $self->r;
12391239

1240-
if (MP2 ? $r->notes->get("warnings") : $r->notes("warnings")) {
1240+
if ( (MP2 ? $r->notes->get("warnings") : $r->notes("warnings"))
1241+
or ($self->{pgerrors}) )
1242+
{
12411243
return $arg;
12421244
} else {
12431245
!$arg;

lib/WeBWorK/ContentGenerator/Problem.pm

+42-21
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,16 @@ sub pre_header_initialize {
722722
effectivePermissionLevel => $db->getPermissionLevel($effectiveUserName)->permission,
723723
},
724724
);
725+
# sometimes, for example if the file can't be read, $pg->{pgcore} won't be defined
726+
# because the PG file is never run
727+
#
728+
if (defined ($pg->{pgcore}) ) {
729+
$self->addmessage(join(CGI::br(),@{$pg->{flags}->{DEBUG_messages}} ) ) if @{$pg->{flags}->{DEBUG_messages}};
730+
$self->{pgdebug} = $pg->{pgcore}->{flags}->{DEBUG_messages};
731+
$self->{pgwarning} = $pg->{pgcore}->{flags}->{WARNING_messages};
732+
$self->{pginternalerrors} = $pg->{pgcore}->get_internal_debug_messages ;
733+
$self->{pgerrors} = @{$self->{pgdebug}} || @{$self->{pgwarning}} || @{$self->{pginternalerrors}};
734+
}
725735

726736
debug("end pg processing");
727737

@@ -739,17 +749,39 @@ sub pre_header_initialize {
739749
$self->{will} = \%will;
740750
$self->{pg} = $pg;
741751
}
742-
743-
sub if_errors($$) {
744-
my ($self, $arg) = @_;
752+
sub warnings {
753+
my $self = shift;
754+
$self->SUPER::warnings();
755+
my $r = $self->r;
756+
my $pg = $self->{pg};
745757

746-
if ($self->{isOpen}) {
747-
return $self->{pg}->{flags}->{error_flag} ? $arg : !$arg;
748-
} else {
749-
return !$arg;
758+
my @pgdebug = @{ $self->{pgdebug} };
759+
my @pgwarning = @{ $self->{pgwarning} };
760+
my @pginternalerrors = @{ $self->{pginternalerrors} };
761+
# my $pgerrordiv = $pgdebug||$pgwarning||$pginternalerrors; # is 1 if any of these are non-empty
762+
# print warning messages
763+
if ( $self->{pgerrors} ) {
764+
print CGI::start_div();
765+
print CGI::h3({style=>"color:red;"}, $r->maketext("Additional Error Messages"));
766+
print CGI::p(CGI::h3("PG debug messages"), CGI::br(), @pgdebug ) if @pgdebug ;
767+
print CGI::p(CGI::h3("PG warning messages"), CGI::br(), @pgwarning ) if @pgwarning ;
768+
print CGI::p(CGI::h3("PG internal errors"), CGI::br(), @pginternalerrors ) if @pginternalerrors;
769+
print CGI::end_div();
750770
}
771+
"";
751772
}
752773

774+
### #FIXME not clear this is ever used
775+
# sub if_errors($$) {
776+
# my ($self, $arg) = @_;
777+
#
778+
# if ($self->{isOpen}) {
779+
# return $self->{pg}->{flags}->{error_flag} ? $arg : !$arg;
780+
# } else {
781+
# return !$arg;
782+
# }
783+
# }
784+
753785
sub head {
754786
my ($self) = @_;
755787

@@ -1213,18 +1245,6 @@ sub output_misc{
12131245
my %will = %{ $self->{will} };
12141246
my $user = $r->param('user');
12151247

1216-
print CGI::start_div();
1217-
1218-
my $pgdebug = join(CGI::br(), @{$pg->{pgcore}->{flags}->{DEBUG_messages}} );
1219-
my $pgwarning = join(CGI::br(), @{$pg->{pgcore}->{flags}->{WARNING_messages}} );
1220-
my $pginternalerrors = join(CGI::br(), @{$pg->{pgcore}->get_internal_debug_messages} );
1221-
my $pgerrordiv = $pgdebug||$pgwarning||$pginternalerrors; # is 1 if any of these are non-empty
1222-
1223-
print CGI::p({style=>"color:red;"}, $r->maketext("Checking additional error messages")) if $pgerrordiv ;
1224-
print CGI::p("pg debug<br/> $pgdebug" ) if $pgdebug ;
1225-
print CGI::p("pg warning<br/>$pgwarning" ) if $pgwarning ;
1226-
print CGI::p("pg internal errors<br/> $pginternalerrors") if $pginternalerrors;
1227-
print CGI::end_div() if $pgerrordiv ;
12281248

12291249
# save state for viewOptions
12301250
print CGI::hidden(
@@ -1261,7 +1281,8 @@ sub output_misc{
12611281

12621282
# output_summary subroutine
12631283

1264-
# prints out the summary of the questions that the student has answered for the current problem, along with available information about correctness
1284+
# prints out the feedback on the questions that the student has answered for
1285+
# the current problem, along with available information about correctness
12651286

12661287
sub output_summary{
12671288

@@ -1284,7 +1305,7 @@ sub output_summary{
12841305
#FIXME -- the following is a kludge: if showPartialCorrectAnswers is negative don't show anything.
12851306
# until after the due date
12861307
# do I need to check $will{showCorrectAnswers} to make preflight work??
1287-
if (($pg->{flags}->{showPartialCorrectAnswers} >= 0 and $submitAnswers) ) {
1308+
if (defined($pg->{flags}->{showPartialCorrectAnswers}) and ($pg->{flags}->{showPartialCorrectAnswers} >= 0 and $submitAnswers) ) {
12881309
# print this if user submitted answers OR requested correct answers
12891310

12901311
print $self->attemptResults($pg, 1,

0 commit comments

Comments
 (0)