Description:
[web] test_request accepting additional file git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@232 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r112:e81565ddb47a - - 2 files changed: 42 inserted, 1 deleted

@@ -74,12 +74,16
74 74 test_request.input_file_name = nil
75 75 else
76 76 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
77 77 if test_request.input_file_name == nil
78 78 test_request.errors.add_to_base("No input submitted.")
79 79 end
80 + if params[:additional_file]!=nil and params[:additional_file]!=""
81 + save_additional_file(params[:additional_file],
82 + "#{test_request.input_file_name}.files")
83 + end
80 84 end
81 85 test_request.submitted_at = Time.new
82 86 test_request.status_inqueue
83 87 test_request
84 88 end
85 89
@@ -117,12 +121,31
117 121 f.write(tempfile.read)
118 122 end
119 123 end
120 124 new_file_name
121 125 end
122 126
127 + def self.save_additional_file(tempfile,dir)
128 + new_file_name = "#{dir}/#{tempfile.original_filename}"
129 + dirname = File.dirname(new_file_name)
130 + FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname)
131 +
132 + # when the user did not submit any file
133 + return nil if tempfile==""
134 +
135 + if tempfile.instance_of?(Tempfile)
136 + tempfile.close
137 + FileUtils.move(tempfile.path,new_file_name)
138 + else
139 + File.open(new_file_name, "wb") do |f|
140 + f.write(tempfile.read)
141 + end
142 + end
143 + new_file_name
144 + end
145 +
123 146 #
124 147 # validations
125 148 #
126 149 def must_have_valid_problem
127 150 if problem==nil
128 151 errors.add('problem',"must be specified.")
@@ -54,14 +54,32
54 54 </td>
55 55 </tr>
56 56 <tr>
57 57 <td>Input data:</td>
58 58 <td>
59 59 <%= f.file_field :input_file %>
60 - (should be smaller than 2MB)
60 + </td>
61 + <td>
62 + (combined size should not exceed 2MB)
63 + </td>
64 + </tr>
65 + <tr>
66 + <td>
67 + Additional file<sup><span style="color:red">*</span></sup>:
61 68 </td>
69 + <td>
70 + <%= f.file_field :additional_file %>
71 + </td>
72 + <td>
73 + <small>
74 + * This option works <u>only</u> for task max.
75 + You can use this to submit <tt>questions.txt</tt>.<br/>
76 + The file shall be copied to the execution directory before your program runs.
77 + </small>
78 + </td>
79 + </tr>
62 80 <tr>
63 81 <td colspan="2">
64 82 <%= submit_tag 'submit' %>
65 83 </td>
66 84 </tr>
67 85 </table>
You need to be logged in to leave comments. Login now