Description:
revert simple_form_for to form_tag
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r758:d23edd5adc06 - - 5 files changed: 11 inserted, 30 deleted

@@ -49,97 +49,96
49 marcel (~> 0.3.1)
49 marcel (~> 0.3.1)
50 activesupport (5.2.3)
50 activesupport (5.2.3)
51 concurrent-ruby (~> 1.0, >= 1.0.2)
51 concurrent-ruby (~> 1.0, >= 1.0.2)
52 i18n (>= 0.7, < 2)
52 i18n (>= 0.7, < 2)
53 minitest (~> 5.1)
53 minitest (~> 5.1)
54 tzinfo (~> 1.1)
54 tzinfo (~> 1.1)
55 addressable (2.6.0)
55 addressable (2.6.0)
56 public_suffix (>= 2.0.2, < 4.0)
56 public_suffix (>= 2.0.2, < 4.0)
57 ansi (1.5.0)
57 ansi (1.5.0)
58 arel (9.0.0)
58 arel (9.0.0)
59 autoprefixer-rails (9.5.1.1)
59 autoprefixer-rails (9.5.1.1)
60 execjs
60 execjs
61 best_in_place (3.0.3)
61 best_in_place (3.0.3)
62 actionpack (>= 3.2)
62 actionpack (>= 3.2)
63 railties (>= 3.2)
63 railties (>= 3.2)
64 bindex (0.7.0)
64 bindex (0.7.0)
65 bootsnap (1.4.4)
65 bootsnap (1.4.4)
66 msgpack (~> 1.0)
66 msgpack (~> 1.0)
67 bootstrap-datepicker-rails (1.8.0.1)
67 bootstrap-datepicker-rails (1.8.0.1)
68 railties (>= 3.0)
68 railties (>= 3.0)
69 bootstrap-sass (3.4.1)
69 bootstrap-sass (3.4.1)
70 autoprefixer-rails (>= 5.2.1)
70 autoprefixer-rails (>= 5.2.1)
71 sassc (>= 2.0.0)
71 sassc (>= 2.0.0)
72 bootstrap-switch-rails (3.3.4)
72 bootstrap-switch-rails (3.3.4)
73 bootstrap-toggle-rails (2.2.1.0)
73 bootstrap-toggle-rails (2.2.1.0)
74 bootstrap3-datetimepicker-rails (4.17.47)
74 bootstrap3-datetimepicker-rails (4.17.47)
75 momentjs-rails (>= 2.8.1)
75 momentjs-rails (>= 2.8.1)
76 builder (3.2.3)
76 builder (3.2.3)
77 byebug (11.0.1)
77 byebug (11.0.1)
78 capybara (3.25.0)
78 capybara (3.25.0)
79 addressable
79 addressable
80 mini_mime (>= 0.1.3)
80 mini_mime (>= 0.1.3)
81 nokogiri (~> 1.8)
81 nokogiri (~> 1.8)
82 rack (>= 1.6.0)
82 rack (>= 1.6.0)
83 rack-test (>= 0.6.3)
83 rack-test (>= 0.6.3)
84 regexp_parser (~> 1.5)
84 regexp_parser (~> 1.5)
85 xpath (~> 3.2)
85 xpath (~> 3.2)
86 childprocess (1.0.1)
86 childprocess (1.0.1)
87 rake (< 13.0)
87 rake (< 13.0)
88 coffee-rails (4.2.2)
88 coffee-rails (4.2.2)
89 coffee-script (>= 2.2.0)
89 coffee-script (>= 2.2.0)
90 railties (>= 4.0.0)
90 railties (>= 4.0.0)
91 coffee-script (2.4.1)
91 coffee-script (2.4.1)
92 coffee-script-source
92 coffee-script-source
93 execjs
93 execjs
94 coffee-script-source (1.12.2)
94 coffee-script-source (1.12.2)
95 concurrent-ruby (1.1.5)
95 concurrent-ruby (1.1.5)
96 crass (1.0.4)
96 crass (1.0.4)
97 - diff-lcs (1.3)
98 dynamic_form (1.1.4)
97 dynamic_form (1.1.4)
99 erubi (1.8.0)
98 erubi (1.8.0)
100 erubis (2.7.0)
99 erubis (2.7.0)
101 execjs (2.7.0)
100 execjs (2.7.0)
102 ffi (1.11.1)
101 ffi (1.11.1)
103 fuzzy-string-match (1.0.1)
102 fuzzy-string-match (1.0.1)
104 RubyInline (>= 3.8.6)
103 RubyInline (>= 3.8.6)
105 globalid (0.4.2)
104 globalid (0.4.2)
106 activesupport (>= 4.2.0)
105 activesupport (>= 4.2.0)
107 haml (5.1.0)
106 haml (5.1.0)
108 temple (>= 0.8.0)
107 temple (>= 0.8.0)
109 tilt
108 tilt
110 haml-rails (1.0.0)
109 haml-rails (1.0.0)
111 actionpack (>= 4.0.1)
110 actionpack (>= 4.0.1)
112 activesupport (>= 4.0.1)
111 activesupport (>= 4.0.1)
113 haml (>= 4.0.6, < 6.0)
112 haml (>= 4.0.6, < 6.0)
114 html2haml (>= 1.0.1)
113 html2haml (>= 1.0.1)
115 railties (>= 4.0.1)
114 railties (>= 4.0.1)
116 html2haml (2.2.0)
115 html2haml (2.2.0)
117 erubis (~> 2.7.0)
116 erubis (~> 2.7.0)
118 haml (>= 4.0, < 6)
117 haml (>= 4.0, < 6)
119 nokogiri (>= 1.6.0)
118 nokogiri (>= 1.6.0)
120 ruby_parser (~> 3.5)
119 ruby_parser (~> 3.5)
121 i18n (1.6.0)
120 i18n (1.6.0)
122 concurrent-ruby (~> 1.0)
121 concurrent-ruby (~> 1.0)
123 in_place_editing (1.2.0)
122 in_place_editing (1.2.0)
124 jbuilder (2.9.1)
123 jbuilder (2.9.1)
125 activesupport (>= 4.2.0)
124 activesupport (>= 4.2.0)
126 jquery-countdown-rails (2.0.2)
125 jquery-countdown-rails (2.0.2)
127 jquery-datatables-rails (3.4.0)
126 jquery-datatables-rails (3.4.0)
128 actionpack (>= 3.1)
127 actionpack (>= 3.1)
129 jquery-rails
128 jquery-rails
130 railties (>= 3.1)
129 railties (>= 3.1)
131 sass-rails
130 sass-rails
132 jquery-rails (4.3.3)
131 jquery-rails (4.3.3)
133 rails-dom-testing (>= 1, < 3)
132 rails-dom-testing (>= 1, < 3)
134 railties (>= 4.2.0)
133 railties (>= 4.2.0)
135 thor (>= 0.14, < 2.0)
134 thor (>= 0.14, < 2.0)
136 jquery-tablesorter (1.26.1)
135 jquery-tablesorter (1.26.1)
137 railties (>= 3.2, < 6)
136 railties (>= 3.2, < 6)
138 jquery-timepicker-addon-rails (1.4.1)
137 jquery-timepicker-addon-rails (1.4.1)
139 railties (>= 3.1)
138 railties (>= 3.1)
140 jquery-ui-rails (6.0.1)
139 jquery-ui-rails (6.0.1)
141 railties (>= 3.2.16)
140 railties (>= 3.2.16)
142 listen (3.1.5)
141 listen (3.1.5)
143 rb-fsevent (~> 0.9, >= 0.9.4)
142 rb-fsevent (~> 0.9, >= 0.9.4)
144 rb-inotify (~> 0.9, >= 0.9.7)
143 rb-inotify (~> 0.9, >= 0.9.7)
145 ruby_dep (~> 1.2)
144 ruby_dep (~> 1.2)
@@ -166,113 +165,96
166 multi_json (1.13.1)
165 multi_json (1.13.1)
167 mysql2 (0.5.2)
166 mysql2 (0.5.2)
168 nio4r (2.3.1)
167 nio4r (2.3.1)
169 nokogiri (1.10.3)
168 nokogiri (1.10.3)
170 mini_portile2 (~> 2.4.0)
169 mini_portile2 (~> 2.4.0)
171 public_suffix (3.1.1)
170 public_suffix (3.1.1)
172 puma (4.0.0)
171 puma (4.0.0)
173 nio4r (~> 2.0)
172 nio4r (~> 2.0)
174 rack (2.0.7)
173 rack (2.0.7)
175 rack-test (1.1.0)
174 rack-test (1.1.0)
176 rack (>= 1.0, < 3)
175 rack (>= 1.0, < 3)
177 rails (5.2.3)
176 rails (5.2.3)
178 actioncable (= 5.2.3)
177 actioncable (= 5.2.3)
179 actionmailer (= 5.2.3)
178 actionmailer (= 5.2.3)
180 actionpack (= 5.2.3)
179 actionpack (= 5.2.3)
181 actionview (= 5.2.3)
180 actionview (= 5.2.3)
182 activejob (= 5.2.3)
181 activejob (= 5.2.3)
183 activemodel (= 5.2.3)
182 activemodel (= 5.2.3)
184 activerecord (= 5.2.3)
183 activerecord (= 5.2.3)
185 activestorage (= 5.2.3)
184 activestorage (= 5.2.3)
186 activesupport (= 5.2.3)
185 activesupport (= 5.2.3)
187 bundler (>= 1.3.0)
186 bundler (>= 1.3.0)
188 railties (= 5.2.3)
187 railties (= 5.2.3)
189 sprockets-rails (>= 2.0.0)
188 sprockets-rails (>= 2.0.0)
190 rails-controller-testing (1.0.4)
189 rails-controller-testing (1.0.4)
191 actionpack (>= 5.0.1.x)
190 actionpack (>= 5.0.1.x)
192 actionview (>= 5.0.1.x)
191 actionview (>= 5.0.1.x)
193 activesupport (>= 5.0.1.x)
192 activesupport (>= 5.0.1.x)
194 rails-dom-testing (2.0.3)
193 rails-dom-testing (2.0.3)
195 activesupport (>= 4.2.0)
194 activesupport (>= 4.2.0)
196 nokogiri (>= 1.6)
195 nokogiri (>= 1.6)
197 rails-html-sanitizer (1.0.4)
196 rails-html-sanitizer (1.0.4)
198 loofah (~> 2.2, >= 2.2.2)
197 loofah (~> 2.2, >= 2.2.2)
199 rails_bootstrap_sortable (2.0.6)
198 rails_bootstrap_sortable (2.0.6)
200 momentjs-rails (>= 2.8.3)
199 momentjs-rails (>= 2.8.3)
201 railties (5.2.3)
200 railties (5.2.3)
202 actionpack (= 5.2.3)
201 actionpack (= 5.2.3)
203 activesupport (= 5.2.3)
202 activesupport (= 5.2.3)
204 method_source
203 method_source
205 rake (>= 0.8.7)
204 rake (>= 0.8.7)
206 thor (>= 0.19.0, < 2.0)
205 thor (>= 0.19.0, < 2.0)
207 rake (12.3.2)
206 rake (12.3.2)
208 rb-fsevent (0.10.3)
207 rb-fsevent (0.10.3)
209 rb-inotify (0.10.0)
208 rb-inotify (0.10.0)
210 ffi (~> 1.0)
209 ffi (~> 1.0)
211 rdiscount (2.2.0.1)
210 rdiscount (2.2.0.1)
212 regexp_parser (1.5.1)
211 regexp_parser (1.5.1)
213 rouge (3.3.0)
212 rouge (3.3.0)
214 - rspec-core (3.8.2)
215 - rspec-support (~> 3.8.0)
216 - rspec-expectations (3.8.4)
217 - diff-lcs (>= 1.2.0, < 2.0)
218 - rspec-support (~> 3.8.0)
219 - rspec-mocks (3.8.1)
220 - diff-lcs (>= 1.2.0, < 2.0)
221 - rspec-support (~> 3.8.0)
222 - rspec-rails (3.8.2)
223 - actionpack (>= 3.0)
224 - activesupport (>= 3.0)
225 - railties (>= 3.0)
226 - rspec-core (~> 3.8.0)
227 - rspec-expectations (~> 3.8.0)
228 - rspec-mocks (~> 3.8.0)
229 - rspec-support (~> 3.8.0)
230 - rspec-support (3.8.2)
231 ruby-progressbar (1.10.0)
213 ruby-progressbar (1.10.0)
232 ruby_dep (1.5.0)
214 ruby_dep (1.5.0)
233 ruby_parser (3.13.1)
215 ruby_parser (3.13.1)
234 sexp_processor (~> 4.9)
216 sexp_processor (~> 4.9)
235 rubyzip (1.2.3)
217 rubyzip (1.2.3)
236 sass (3.7.4)
218 sass (3.7.4)
237 sass-listen (~> 4.0.0)
219 sass-listen (~> 4.0.0)
238 sass-listen (4.0.0)
220 sass-listen (4.0.0)
239 rb-fsevent (~> 0.9, >= 0.9.4)
221 rb-fsevent (~> 0.9, >= 0.9.4)
240 rb-inotify (~> 0.9, >= 0.9.7)
222 rb-inotify (~> 0.9, >= 0.9.7)
241 sass-rails (5.0.7)
223 sass-rails (5.0.7)
242 railties (>= 4.0.0, < 6)
224 railties (>= 4.0.0, < 6)
243 sass (~> 3.1)
225 sass (~> 3.1)
244 sprockets (>= 2.8, < 4.0)
226 sprockets (>= 2.8, < 4.0)
245 sprockets-rails (>= 2.0, < 4.0)
227 sprockets-rails (>= 2.0, < 4.0)
246 tilt (>= 1.1, < 3)
228 tilt (>= 1.1, < 3)
247 sassc (2.0.1)
229 sassc (2.0.1)
248 ffi (~> 1.9)
230 ffi (~> 1.9)
249 rake
231 rake
250 sassc-rails (2.1.1)
232 sassc-rails (2.1.1)
251 railties (>= 4.0.0)
233 railties (>= 4.0.0)
252 sassc (>= 2.0)
234 sassc (>= 2.0)
253 sprockets (> 3.0)
235 sprockets (> 3.0)
254 sprockets-rails
236 sprockets-rails
255 tilt
237 tilt
256 select2-rails (4.0.3)
238 select2-rails (4.0.3)
257 thor (~> 0.14)
239 thor (~> 0.14)
258 selenium-webdriver (3.142.3)
240 selenium-webdriver (3.142.3)
259 childprocess (>= 0.5, < 2.0)
241 childprocess (>= 0.5, < 2.0)
260 rubyzip (~> 1.2, >= 1.2.2)
242 rubyzip (~> 1.2, >= 1.2.2)
261 sexp_processor (4.12.0)
243 sexp_processor (4.12.0)
262 simple_form (4.1.0)
244 simple_form (4.1.0)
263 actionpack (>= 5.0)
245 actionpack (>= 5.0)
264 activemodel (>= 5.0)
246 activemodel (>= 5.0)
265 spring (2.1.0)
247 spring (2.1.0)
266 spring-watcher-listen (2.0.1)
248 spring-watcher-listen (2.0.1)
267 listen (>= 2.7, < 4.0)
249 listen (>= 2.7, < 4.0)
268 spring (>= 1.2, < 3.0)
250 spring (>= 1.2, < 3.0)
269 sprockets (3.7.2)
251 sprockets (3.7.2)
270 concurrent-ruby (~> 1.0)
252 concurrent-ruby (~> 1.0)
271 rack (> 1, < 3)
253 rack (> 1, < 3)
272 sprockets-rails (3.2.1)
254 sprockets-rails (3.2.1)
273 actionpack (>= 4.0)
255 actionpack (>= 4.0)
274 activesupport (>= 4.0)
256 activesupport (>= 4.0)
275 sprockets (>= 3.0.0)
257 sprockets (>= 3.0.0)
276 sqlite3 (1.4.1)
258 sqlite3 (1.4.1)
277 temple (0.8.1)
259 temple (0.8.1)
278 thor (0.20.3)
260 thor (0.20.3)
@@ -293,64 +275,63
293 websocket-extensions (0.1.4)
275 websocket-extensions (0.1.4)
294 will_paginate (3.0.12)
276 will_paginate (3.0.12)
295 xpath (3.2.0)
277 xpath (3.2.0)
296 nokogiri (~> 1.8)
278 nokogiri (~> 1.8)
297 yaml_db (0.7.0)
279 yaml_db (0.7.0)
298 rails (>= 3.0)
280 rails (>= 3.0)
299 rake (>= 0.8.7)
281 rake (>= 0.8.7)
300
282
301 PLATFORMS
283 PLATFORMS
302 ruby
284 ruby
303
285
304 DEPENDENCIES
286 DEPENDENCIES
305 ace-rails-ap
287 ace-rails-ap
306 activerecord-session_store
288 activerecord-session_store
307 autoprefixer-rails
289 autoprefixer-rails
308 best_in_place (~> 3.0.1)
290 best_in_place (~> 3.0.1)
309 bootsnap (>= 1.1.0)
291 bootsnap (>= 1.1.0)
310 bootstrap-datepicker-rails
292 bootstrap-datepicker-rails
311 bootstrap-sass (~> 3.4.1)
293 bootstrap-sass (~> 3.4.1)
312 bootstrap-switch-rails
294 bootstrap-switch-rails
313 bootstrap-toggle-rails
295 bootstrap-toggle-rails
314 bootstrap3-datetimepicker-rails
296 bootstrap3-datetimepicker-rails
315 byebug
297 byebug
316 capybara (>= 2.15)
298 capybara (>= 2.15)
317 coffee-rails
299 coffee-rails
318 dynamic_form
300 dynamic_form
319 fuzzy-string-match
301 fuzzy-string-match
320 haml
302 haml
321 haml-rails
303 haml-rails
322 in_place_editing
304 in_place_editing
323 jbuilder (~> 2.5)
305 jbuilder (~> 2.5)
324 jquery-countdown-rails
306 jquery-countdown-rails
325 jquery-datatables-rails
307 jquery-datatables-rails
326 jquery-rails
308 jquery-rails
327 jquery-tablesorter
309 jquery-tablesorter
328 jquery-timepicker-addon-rails
310 jquery-timepicker-addon-rails
329 jquery-ui-rails
311 jquery-ui-rails
330 listen (>= 3.0.5, < 3.2)
312 listen (>= 3.0.5, < 3.2)
331 mail
313 mail
332 minitest-reporters
314 minitest-reporters
333 momentjs-rails
315 momentjs-rails
334 mysql2
316 mysql2
335 puma
317 puma
336 rails (~> 5.2)
318 rails (~> 5.2)
337 rails-controller-testing
319 rails-controller-testing
338 rails_bootstrap_sortable
320 rails_bootstrap_sortable
339 rdiscount
321 rdiscount
340 rouge
322 rouge
341 - rspec-rails
342 sassc-rails
323 sassc-rails
343 select2-rails
324 select2-rails
344 selenium-webdriver
325 selenium-webdriver
345 simple_form
326 simple_form
346 spring
327 spring
347 spring-watcher-listen (~> 2.0.0)
328 spring-watcher-listen (~> 2.0.0)
348 sqlite3
329 sqlite3
349 uglifier
330 uglifier
350 web-console (>= 3.3.0)
331 web-console (>= 3.3.0)
351 webdriver
332 webdriver
352 will_paginate (~> 3.0.7)
333 will_paginate (~> 3.0.7)
353 yaml_db
334 yaml_db
354
335
355 BUNDLED WITH
336 BUNDLED WITH
356 1.17.2
337 1.17.2
@@ -1,104 +1,104
1 class Problem < ActiveRecord::Base
1 class Problem < ActiveRecord::Base
2
2
3 belongs_to :description
3 belongs_to :description
4 has_and_belongs_to_many :contests, :uniq => true
4 has_and_belongs_to_many :contests, :uniq => true
5
5
6 #has_and_belongs_to_many :groups
6 #has_and_belongs_to_many :groups
7 has_many :groups_problems, class_name: 'GroupProblem'
7 has_many :groups_problems, class_name: 'GroupProblem'
8 has_many :groups, :through => :groups_problems
8 has_many :groups, :through => :groups_problems
9
9
10 has_many :problems_tags, class_name: 'ProblemTag'
10 has_many :problems_tags, class_name: 'ProblemTag'
11 has_many :tags, through: :problems_tags
11 has_many :tags, through: :problems_tags
12
12
13 has_many :test_pairs, :dependent => :delete_all
13 has_many :test_pairs, :dependent => :delete_all
14 has_many :testcases, :dependent => :destroy
14 has_many :testcases, :dependent => :destroy
15
15
16 has_many :submissions
16 has_many :submissions
17
17
18 validates_presence_of :name
18 validates_presence_of :name
19 validates_format_of :name, :with => /\A\w+\z/
19 validates_format_of :name, :with => /\A\w+\z/
20 validates_presence_of :full_name
20 validates_presence_of :full_name
21
21
22 scope :available, -> { where(available: true) }
22 scope :available, -> { where(available: true) }
23
23
24 DEFAULT_TIME_LIMIT = 1
24 DEFAULT_TIME_LIMIT = 1
25 DEFAULT_MEMORY_LIMIT = 32
25 DEFAULT_MEMORY_LIMIT = 32
26
26
27 def self.available_problems
27 def self.available_problems
28 available.order(date_added: :desc).order(:name)
28 available.order(date_added: :desc).order(:name)
29 #Problem.available.all(:order => "date_added DESC, name ASC")
29 #Problem.available.all(:order => "date_added DESC, name ASC")
30 end
30 end
31
31
32 def self.create_from_import_form_params(params, old_problem=nil)
32 def self.create_from_import_form_params(params, old_problem=nil)
33 org_problem = old_problem || Problem.new
33 org_problem = old_problem || Problem.new
34 - import_params, problem = Problem.extract_params_and_check(params,
34 + import_params, problem = Problem.extract_params_and_check(params,
35 org_problem)
35 org_problem)
36
36
37 if !problem.errors.empty?
37 if !problem.errors.empty?
38 return problem, 'Error importing'
38 return problem, 'Error importing'
39 end
39 end
40
40
41 problem.full_score = 100
41 problem.full_score = 100
42 problem.date_added = Time.new
42 problem.date_added = Time.new
43 problem.test_allowed = true
43 problem.test_allowed = true
44 problem.output_only = false
44 problem.output_only = false
45 problem.available = false
45 problem.available = false
46
46
47 if not problem.save
47 if not problem.save
48 return problem, 'Error importing'
48 return problem, 'Error importing'
49 end
49 end
50
50
51 import_to_db = params.has_key? :import_to_db
51 import_to_db = params.has_key? :import_to_db
52
52
53 importer = TestdataImporter.new(problem)
53 importer = TestdataImporter.new(problem)
54
54
55 - if not importer.import_from_file(import_params[:file],
55 + if not importer.import_from_file(import_params[:file],
56 - import_params[:time_limit],
56 + import_params[:time_limit],
57 import_params[:memory_limit],
57 import_params[:memory_limit],
58 import_params[:checker_name],
58 import_params[:checker_name],
59 import_to_db)
59 import_to_db)
60 problem.errors.add(:base,'Import error.')
60 problem.errors.add(:base,'Import error.')
61 end
61 end
62
62
63 return problem, importer.log_msg
63 return problem, importer.log_msg
64 end
64 end
65
65
66 def self.download_file_basedir
66 def self.download_file_basedir
67 return "#{Rails.root}/data/tasks"
67 return "#{Rails.root}/data/tasks"
68 end
68 end
69
69
70 def get_submission_stat
70 def get_submission_stat
71 result = Hash.new
71 result = Hash.new
72 #total number of submission
72 #total number of submission
73 result[:total_sub] = Submission.where(problem_id: self.id).count
73 result[:total_sub] = Submission.where(problem_id: self.id).count
74 result[:attempted_user] = Submission.where(problem_id: self.id).group(:user_id)
74 result[:attempted_user] = Submission.where(problem_id: self.id).group(:user_id)
75 result[:pass] = Submission.where(problem_id: self.id).where("points >= ?",self.full_score).count
75 result[:pass] = Submission.where(problem_id: self.id).where("points >= ?",self.full_score).count
76 return result
76 return result
77 end
77 end
78
78
79 def long_name
79 def long_name
80 "[#{name}] #{full_name}"
80 "[#{name}] #{full_name}"
81 end
81 end
82
82
83 protected
83 protected
84
84
85 def self.to_i_or_default(st, default)
85 def self.to_i_or_default(st, default)
86 if st!=''
86 if st!=''
87 result = st.to_i
87 result = st.to_i
88 end
88 end
89 result ||= default
89 result ||= default
90 end
90 end
91
91
92 def self.to_f_or_default(st, default)
92 def self.to_f_or_default(st, default)
93 if st!=''
93 if st!=''
94 result = st.to_f
94 result = st.to_f
95 end
95 end
96 result ||= default
96 result ||= default
97 end
97 end
98
98
99 def self.extract_params_and_check(params, problem)
99 def self.extract_params_and_check(params, problem)
100 time_limit = Problem.to_f_or_default(params[:time_limit],
100 time_limit = Problem.to_f_or_default(params[:time_limit],
101 DEFAULT_TIME_LIMIT)
101 DEFAULT_TIME_LIMIT)
102 memory_limit = Problem.to_i_or_default(params[:memory_limit],
102 memory_limit = Problem.to_i_or_default(params[:memory_limit],
103 DEFAULT_MEMORY_LIMIT)
103 DEFAULT_MEMORY_LIMIT)
104
104
@@ -1,59 +1,59
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'problems'
2 = stylesheet_link_tag 'problems'
3
3
4 %h1 Import problems
4 %h1 Import problems
5
5
6 %p= link_to '[Back to problem list]', problems_path
6 %p= link_to '[Back to problem list]', problems_path
7
7
8 - if @problem and @problem.errors
8 - if @problem and @problem.errors
9 =error_messages_for 'problem'
9 =error_messages_for 'problem'
10
10
11 - = simple_form_for :problem, url: do_import_problems_path, :multipart => true do |f|
11 + = form_tag do_import_problems_path, :multipart => true do |f|
12
12
13 .submitbox
13 .submitbox
14 %table
14 %table
15 %tr
15 %tr
16 %td Name:
16 %td Name:
17 %td= text_field_tag 'name'
17 %td= text_field_tag 'name'
18 %tr
18 %tr
19 %td Full name:
19 %td Full name:
20 %td
20 %td
21 = text_field_tag 'full_name'
21 = text_field_tag 'full_name'
22 %span{:class => 'help'} Leave blank to use the same value as the name above.
22 %span{:class => 'help'} Leave blank to use the same value as the name above.
23 %tr
23 %tr
24 %td Testdata file:
24 %td Testdata file:
25 %td= file_field_tag 'file'
25 %td= file_field_tag 'file'
26 %tr
26 %tr
27 %td
27 %td
28 %td
28 %td
29 %span{:class => 'help'}
29 %span{:class => 'help'}
30 In .zip, .tgz, tar.gz, .tar format.
30 In .zip, .tgz, tar.gz, .tar format.
31 It should includes inputs (e.g., 1.in, 2a.in, 2b.in)
31 It should includes inputs (e.g., 1.in, 2a.in, 2b.in)
32 and solutions (e.g., 1.sol, 2a.sol, 2b.sol).
32 and solutions (e.g., 1.sol, 2a.sol, 2b.sol).
33 %br/
33 %br/
34 You may put task description in *.html for raw html
34 You may put task description in *.html for raw html
35 and *.md or *.markdown for markdown.
35 and *.md or *.markdown for markdown.
36 %br/
36 %br/
37 You may also put a pdf file for the task description
37 You may also put a pdf file for the task description
38 %tr
38 %tr
39 %td Checker:
39 %td Checker:
40 %td= select_tag 'checker', options_for_select([['Text checker','text'],['Float checker','float']], 'text')
40 %td= select_tag 'checker', options_for_select([['Text checker','text'],['Float checker','float']], 'text')
41 %tr
41 %tr
42 %td
42 %td
43 %td
43 %td
44 %span{:class => 'help'}
44 %span{:class => 'help'}
45 "Text" checker checks if the text (including numbers) is the same, ignoring any whitespace
45 "Text" checker checks if the text (including numbers) is the same, ignoring any whitespace
46 %br/
46 %br/
47 "Float" checker checks if all numbers is within EPSILON error using formula |a-b| < EPSILON * max(|a|,|b|)
47 "Float" checker checks if all numbers is within EPSILON error using formula |a-b| < EPSILON * max(|a|,|b|)
48
48
49 - if @allow_test_pair_import
49 - if @allow_test_pair_import
50 %tr
50 %tr
51 %td
51 %td
52 %td
52 %td
53 = check_box_tag 'import_to_db'
53 = check_box_tag 'import_to_db'
54 Import test data to database (for a test-pair task)
54 Import test data to database (for a test-pair task)
55 %tr
55 %tr
56 %td Time limit:
56 %td Time limit:
57 %td
57 %td
58 = text_field_tag 'time_limit'
58 = text_field_tag 'time_limit'
59 %span{:class => 'help'} In seconds. Leave blank to use 1 sec.
59 %span{:class => 'help'} In seconds. Leave blank to use 1 sec.
@@ -222,59 +222,59
222 role = Role.create(:name => 'admin')
222 role = Role.create(:name => 'admin')
223 user_admin_right = Right.create(:name => 'user_admin',
223 user_admin_right = Right.create(:name => 'user_admin',
224 :controller => 'user_admin',
224 :controller => 'user_admin',
225 :action => 'all')
225 :action => 'all')
226 problem_admin_right = Right.create(:name=> 'problem_admin',
226 problem_admin_right = Right.create(:name=> 'problem_admin',
227 :controller => 'problems',
227 :controller => 'problems',
228 :action => 'all')
228 :action => 'all')
229
229
230 graders_right = Right.create(:name => 'graders_admin',
230 graders_right = Right.create(:name => 'graders_admin',
231 :controller => 'graders',
231 :controller => 'graders',
232 :action => 'all')
232 :action => 'all')
233
233
234 role.rights << user_admin_right;
234 role.rights << user_admin_right;
235 role.rights << problem_admin_right;
235 role.rights << problem_admin_right;
236 role.rights << graders_right;
236 role.rights << graders_right;
237 role.save
237 role.save
238 end
238 end
239
239
240 def seed_root
240 def seed_root
241 return if User.find_by_login('root')
241 return if User.find_by_login('root')
242
242
243 root = User.new(:login => 'root',
243 root = User.new(:login => 'root',
244 :full_name => 'Administrator',
244 :full_name => 'Administrator',
245 :alias => 'root')
245 :alias => 'root')
246 root.password = 'ioionrails';
246 root.password = 'ioionrails';
247
247
248 class << root
248 class << root
249 public :encrypt_new_password
249 public :encrypt_new_password
250 def valid?(context=nil)
250 def valid?(context=nil)
251 true
251 true
252 end
252 end
253 end
253 end
254
254
255 root.encrypt_new_password
255 root.encrypt_new_password
256
256
257 root.roles << Role.find_by_name('admin')
257 root.roles << Role.find_by_name('admin')
258
258
259 root.activated = true
259 root.activated = true
260 root.save
260 root.save
261 end
261 end
262
262
263 def seed_users_and_roles
263 def seed_users_and_roles
264 seed_roles
264 seed_roles
265 seed_root
265 seed_root
266 end
266 end
267
267
268 def seed_more_languages
268 def seed_more_languages
269 Language.delete_all
269 Language.delete_all
270 - Language.create( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
270 + Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
271 - Language.create( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
271 + Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
272 - Language.create( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
272 + Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
273 - Language.create( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
273 + Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
274 - Language.create( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
274 + Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
275 - Language.create( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
275 + Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
276 end
276 end
277
277
278 seed_config
278 seed_config
279 seed_users_and_roles
279 seed_users_and_roles
280 seed_more_languages
280 seed_more_languages
@@ -49,97 +49,97
49
49
50 def self.long_ext(filename)
50 def self.long_ext(filename)
51 i = filename.index('.')
51 i = filename.index('.')
52 len = filename.length
52 len = filename.length
53 return filename.slice(i..len)
53 return filename.slice(i..len)
54 end
54 end
55
55
56 # extract an archive file located at +tempfile+ to the +raw_dir+
56 # extract an archive file located at +tempfile+ to the +raw_dir+
57 def extract(tempfile)
57 def extract(tempfile)
58 testdata_filename = save_testdata_file(tempfile)
58 testdata_filename = save_testdata_file(tempfile)
59 ext = TestdataImporter.long_ext(tempfile.original_filename)
59 ext = TestdataImporter.long_ext(tempfile.original_filename)
60
60
61 extract_dir = File.join(GraderScript.raw_dir, @problem.name)
61 extract_dir = File.join(GraderScript.raw_dir, @problem.name)
62 if File.exists? extract_dir
62 if File.exists? extract_dir
63 backup_count = 0
63 backup_count = 0
64 begin
64 begin
65 backup_count += 1
65 backup_count += 1
66 backup_dirname = "#{extract_dir}.backup.#{backup_count}"
66 backup_dirname = "#{extract_dir}.backup.#{backup_count}"
67 end while File.exists? backup_dirname
67 end while File.exists? backup_dirname
68 File.rename(extract_dir, backup_dirname)
68 File.rename(extract_dir, backup_dirname)
69 end
69 end
70 Dir.mkdir extract_dir
70 Dir.mkdir extract_dir
71
71
72 if ext=='.tar.gz' or ext=='.tgz'
72 if ext=='.tar.gz' or ext=='.tgz'
73 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
73 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
74 elsif ext=='.tar'
74 elsif ext=='.tar'
75 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
75 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
76 elsif ext=='.zip'
76 elsif ext=='.zip'
77 cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
77 cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
78 else
78 else
79 return nil
79 return nil
80 end
80 end
81
81
82 system(cmd)
82 system(cmd)
83
83
84 files = Dir["#{extract_dir}/**/*1*.in"]
84 files = Dir["#{extract_dir}/**/*1*.in"]
85 return nil if files.length==0
85 return nil if files.length==0
86
86
87 File.delete(testdata_filename)
87 File.delete(testdata_filename)
88
88
89 return File.dirname(files[0])
89 return File.dirname(files[0])
90 end
90 end
91
91
92 def save_testdata_file(tempfile)
92 def save_testdata_file(tempfile)
93 ext = TestdataImporter.long_ext(tempfile.original_filename)
93 ext = TestdataImporter.long_ext(tempfile.original_filename)
94 testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}")
94 testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}")
95
95
96 return nil if tempfile==""
96 return nil if tempfile==""
97 -
97 +
98 if tempfile.instance_of?(Tempfile)
98 if tempfile.instance_of?(Tempfile)
99 tempfile.close
99 tempfile.close
100 FileUtils.move(tempfile.path,testdata_filename)
100 FileUtils.move(tempfile.path,testdata_filename)
101 else
101 else
102 File.open(testdata_filename, "wb") do |f|
102 File.open(testdata_filename, "wb") do |f|
103 f.write(tempfile.read)
103 f.write(tempfile.read)
104 end
104 end
105 end
105 end
106
106
107 return testdata_filename
107 return testdata_filename
108 end
108 end
109
109
110 def import_test_pairs(dirname)
110 def import_test_pairs(dirname)
111 test_num = 1
111 test_num = 1
112 while FileTest.exists? "#{dirname}/#{test_num}.in"
112 while FileTest.exists? "#{dirname}/#{test_num}.in"
113 in_filename = "#{dirname}/#{test_num}.in"
113 in_filename = "#{dirname}/#{test_num}.in"
114 sol_filename = "#{dirname}/#{test_num}.sol"
114 sol_filename = "#{dirname}/#{test_num}.sol"
115
115
116 break if not FileTest.exists? sol_filename
116 break if not FileTest.exists? sol_filename
117
117
118 test_pair = TestPair.new(:input => open(in_filename).read,
118 test_pair = TestPair.new(:input => open(in_filename).read,
119 :solution => open(sol_filename).read,
119 :solution => open(sol_filename).read,
120 :problem => @problem)
120 :problem => @problem)
121 break if not test_pair.save
121 break if not test_pair.save
122
122
123 test_num += 1
123 test_num += 1
124 end
124 end
125 return test_num > 1
125 return test_num > 1
126 end
126 end
127
127
128 def import_problem_description(dirname)
128 def import_problem_description(dirname)
129 html_files = Dir["#{dirname}/*.html"]
129 html_files = Dir["#{dirname}/*.html"]
130 markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"]
130 markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"]
131 if (html_files.length != 0) or (markdown_files.length != 0)
131 if (html_files.length != 0) or (markdown_files.length != 0)
132 description = @problem.description || Description.new
132 description = @problem.description || Description.new
133
133
134 if html_files.length != 0
134 if html_files.length != 0
135 filename = html_files[0]
135 filename = html_files[0]
136 description.markdowned = false
136 description.markdowned = false
137 else
137 else
138 filename = markdown_files[0]
138 filename = markdown_files[0]
139 description.markdowned = true
139 description.markdowned = true
140 end
140 end
141
141
142 description.body = open(filename).read
142 description.body = open(filename).read
143 description.save
143 description.save
144 @problem.description = description
144 @problem.description = description
145 @problem.save
145 @problem.save
You need to be logged in to leave comments. Login now