xowf::test_item::Answer_manager method render_answers (public)
<instance of xowf::test_item::Answer_manager> render_answers \ [ -as_student on|off ] \ [ -filter_submission_id filter_submission_id ] \ [ -creation_user creation_user ] [ -revision_id revision_id ] \ [ -filter_form_ids filter_form_ids ] [ -export on|off ] \ [ -orderby orderby ] [ -grading grading ] \ [ -with_grading_table on|off ] examWf
Defined in packages/xowf/tcl/test-item-procs.tcl
Return the answers in HTML format in a somewhat printer friendly way, e.g. as the exam protocol.
- Switches:
- -as_student (optional, boolean, defaults to
"false"
)- -filter_submission_id (optional, integer, accept empty)
- -creation_user (optional, integer, accept empty)
- -revision_id (optional, integer, accept empty)
- -filter_form_ids (optional, integer)
- -export (optional, boolean, defaults to
"false"
)- -orderby (optional, defaults to
"online-exam-userName"
)- -grading (optional)
- -with_grading_table (optional, boolean, defaults to
"false"
)- Parameters:
- examWf (required, object)
- Returns:
- dict containing "do_stream" and "HTML" ns_log notice "RENDER ANSWERS 0"
- Testcases:
- No testcase defined.
Source code: set combined_form_info [:QM combined_question_form $examWf] set autograde [dict get $combined_form_info autograde] set totalPoints [:QM total_points -max_items [$examWf property max_items ""] $combined_form_info] set withSignature [$examWf property signature 0] set examTitle [$examWf title] set ctx [::xowf::Context require $examWf] set results "" set wf [:get_answer_wf $examWf] if {$wf eq ""} { return [list do_stream 0 HTML ""] } if {$filter_form_ids ne "" && $filter_form_ids ni [dict get $combined_form_info question_objs]} { ns_log warning "inclass-exam: ignore invalid form_obj '$filter_form_ids';" "valid [dict get $combined_form_info question_objs]" set filter_form_ids "" } ns_log notice "--- grading '$grading'" set grading_scheme [:grading_scheme -examWf $examWf -grading $grading -total_points $totalPoints] #ns_log notice "--- grading_scheme $grading_scheme from grading '$grading'" set :grade_dict {} set :grade_csv "" set items [:submissions -creation_user $creation_user -filter_submission_id $filter_submission_id -revision_id $revision_id -wf $wf] # # In case we have many items to render (which might take a # while), use streaming mode. # set do_stream [expr {[llength [$items children]] > 100}] set HTML [:render_print_button] if {!$as_student} { # # When rendering for teachers, we offer the possibility for to # sort, filter and export submissions. # append HTML [:render_filter_bar -examWf $examWf -filter_form_ids $filter_form_ids -revision_id $revision_id -filter_submission_id $filter_submission_id -orderby $orderby] } ::xo::cc set_parameter template_file view-plain-master ::xo::cc set_parameter MenuBar 0 if {[llength $filter_form_ids] > 0} { # # Filter by questions. For the time being, we allow only a # single question, ... and we take the first ones. # append HTML "<h2>#xowf.question#: [ns_quotehtml [[lindex $filter_form_ids 0] title]]</h2>\n" set runtime_panel_view "" } elseif {$as_student} { # # Show the student his own submission # set userName [acs_user::get_element -user_id [ad_conn user_id] -element username] set fullName [::xo::get_user_name [ad_conn user_id]] set heading "$userName - $fullName" append HTML "<h2>#xowf.online-exam-review-protocol# - $heading</h2>\n" set runtime_panel_view "student" } else { # # Provide the full protocol (or a subset of it) # append HTML "<h2>#xowf.online-exam-protocol#</h2>\n" if {$filter_submission_id ne ""} { set runtime_panel_view "revision_overview" } else { set runtime_panel_view "default" } } append HTML [:grading_dialog_setup $examWf] #ns_log notice "RENDER ANSWERS 1" if {$do_stream} { # ns_log notice STREAM-[info level]-$::template::parse_level # # The following line is tricky: set on the parsing level the # title of and context of the page, since this is needed by # the streaming template. # uplevel #$::template::parse_level [subst {set title "$examTitle"; set context .}] ad_return_top_of_page [ad_parse_template -params [list context title] [template::streaming_template]] ns_write [subst { <div class=''main-content> <div class='xowiki-content' style='padding-left:15px;'> <h1>[ns_quotehtml $examTitle]</h1> [lang::util::localize $HTML] }] set HTML "" } if {$export} { set recutil [:recutil_create -clear -exam_id [$wf parent_id] -fn [expr {$filter_submission_id eq "" ? "all.rec" : "$filter_submission_id.rec"}] ] } else { set recutil "" } #ns_log notice "RENDER ANSWERS 2" # # Create zip file from file submissions # set create_zip_file [::xo::cc query_parameter create-file-submission-zip-file:boolean 0] if {$create_zip_file} { package req nx::zip [$examWf package_id] get_lang_and_name -name [$examWf set name] lang stripped_name if {[string equal [nx::zip::Archive info lookup parameters create name] -name]} { set zipFile [nx::zip::Archive new -name [ad_sanitize_filename $stripped_name]] } else { set zipFile [::nx::zip::Archive new] # # Post-register property, since it is not yet available in # this version of nx. # $zipFile object property name $zipFile configure -name [ad_sanitize_filename $stripped_name] } } else { set zipFile "" } #ns_log notice "RENDER ANSWERS 3 (submissions: [llength [$items children]])" set file_submission_exists 0 set form_objs_exam [:QM load_question_objs $examWf [$examWf property question]] set question_dict [:FL name_to_question_obj_dict $form_objs_exam] #ns_log notice "passed filter_form_ids <$filter_form_ids> form_objs_exam <$form_objs_exam>" # # Iterate over the items sorted by orderby. # $items orderby $orderby foreach submission [$items children] { set d [:render_submission=exam_protocol -submission $submission -wf $wf -examWf $examWf -exam_question_dict $question_dict -autograde $autograde -combined_form_info $combined_form_info -filter_submission_id $filter_submission_id -filter_form_ids $filter_form_ids -grading_scheme $grading_scheme -recutil $recutil -zipFile $zipFile -revision_id $revision_id -totalPoints $totalPoints -runtime_panel_view $runtime_panel_view -with_exam_heading [expr {!$as_student}] -with_signature $withSignature] set html [:dict_value $d HTML] #ns_log notice "RENDER ANSWERS setting result" dict set results [$submission set creation_user] [:dict_value $d results] if {$do_stream && $html ne ""} { ns_write [lang::util::localize $html] } else { append HTML $html } # # Check if we have found a file submission # if {!$file_submission_exists && !$export && [llength [:get_non_empty_file_formfields -submission $submission]] > 0 } { set file_submission_exists 1 } } #ns_log notice "RENDER ANSWERS 4" if {$export} { $recutil destroy } if {$with_grading_table && $autograde && $grading ne "none"} { append HTML <p>[:grading_table -csv ${:grade_csv} ${:grade_dict}]</p> # # The following lines are convenient for debugging # #set manual_gradings [$examWf property manual_gradings] #set manual_gradings [:get_exam_results -obj $examWf manual_gradings] #append HTML <pre>$manual_gradings</pre> #append HTML <pre>[:exam_results -manual_gradings $manual_gradings $results]</pre> } if {$create_zip_file} { $zipFile ns_returnZipFile [$zipFile cget -name].zip $zipFile destroy ad_script_abort } # # If we have already some file submission we are showing a link # for bulk-downloading the submissions # if {$file_submission_exists} { # # Avoid empty entries for query parameters # if {[llength $filter_form_ids] > 0} { set fos $filter_form_ids } foreach value {revision_id filter_submission_id} var {rid id} { if {[set $value] ne ""} { set $var [set $value] } } set href [$examWf pretty_link -query [export_vars { {m print-answers} {create-file-submission-zip-file 1} fos rid id }]] append HTML [ns_trim -delimiter | [subst { |<a href='[ns_quotehtml $href]'> |[::xowiki::bootstrap::icon -name download -CSSclass download-submissions] |#xowf.Download_file_submissions#</a> }]] } #ns_log notice "RENDER ANSWERS 5" # # Store statistics only in autograding cases, and only, when it # was a full evaluation of the exam. This has the advantage # that we do no have to partially update the statistics. These # are somewhat overly conservative assumptions for now, which # might be partially relaxed in the future. # if {$with_grading_table && !$as_student && $filter_submission_id eq "" && $creation_user eq "" && $revision_id eq "" } { set statistics {} set ia [$examWf instance_attributes] if {$autograde} { foreach var {__stats_success __stats_count} key {success count} { if {[$examWf exists $var]} { dict set statistics $key [$examWf set $var] $examWf unset $var } } :AM set_exam_results -obj $examWf statistics $statistics } :AM set_exam_results -obj $examWf results $results } return [list do_stream $do_stream HTML $HTML]XQL Not present: Generic, PostgreSQL, Oracle