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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r112:e81565ddb47a - - 2 files changed: 42 inserted, 1 deleted
@@ -77,6 +77,10 | |||||
|
77 | if test_request.input_file_name == nil |
|
77 | if test_request.input_file_name == nil |
|
78 | test_request.errors.add_to_base("No input submitted.") |
|
78 | test_request.errors.add_to_base("No input submitted.") |
|
79 | end |
|
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 | end |
|
84 | end |
|
81 | test_request.submitted_at = Time.new |
|
85 | test_request.submitted_at = Time.new |
|
82 | test_request.status_inqueue |
|
86 | test_request.status_inqueue |
@@ -120,6 +124,25 | |||||
|
120 | new_file_name |
|
124 | new_file_name |
|
121 | end |
|
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 | # validations |
|
147 | # validations |
|
125 | # |
|
148 | # |
@@ -57,8 +57,26 | |||||
|
57 | <td>Input data:</td> |
|
57 | <td>Input data:</td> |
|
58 | <td> |
|
58 | <td> |
|
59 | <%= f.file_field :input_file %> |
|
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 | </td> |
|
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 | <tr> |
|
80 | <tr> |
|
63 | <td colspan="2"> |
|
81 | <td colspan="2"> |
|
64 | <%= submit_tag 'submit' %> |
|
82 | <%= submit_tag 'submit' %> |
You need to be logged in to leave comments.
Login now