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

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