Description:
fixed problem import from validation (thanks Witchakorn Kamolpornwijit)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r310:6939525421a6 - - 1 file changed: 23 inserted, 17 deleted
@@ -18,10 +18,11 | |||
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | - problem = old_problem || Problem.new | |
|
22 |
- import_params = Problem.extract_params_and_check(params, |
|
|
21 | + org_problem = old_problem || Problem.new | |
|
22 | + import_params, problem = Problem.extract_params_and_check(params, | |
|
23 | + org_problem) | |
|
23 | 24 | |
|
24 | - if not problem.valid? | |
|
25 | + if problem.errors.length!=0 | |
|
25 | 26 | return problem, 'Error importing' |
|
26 | 27 | end |
|
27 | 28 | |
@@ -57,25 +58,29 | |||
|
57 | 58 | |
|
58 | 59 | def self.to_i_or_default(st, default) |
|
59 | 60 | if st!='' |
|
60 | - st.to_i | |
|
61 | - else | |
|
62 | - default | |
|
61 | + result = st.to_i | |
|
63 | 62 | end |
|
63 | + result ||= default | |
|
64 | + end | |
|
65 | + | |
|
66 | + def self.to_f_or_default(st, default) | |
|
67 | + if st!='' | |
|
68 | + result = st.to_f | |
|
69 | + end | |
|
70 | + result ||= default | |
|
64 | 71 | end |
|
65 | 72 | |
|
66 | 73 | def self.extract_params_and_check(params, problem) |
|
67 |
- time_limit = Problem.to_ |
|
|
74 | + time_limit = Problem.to_f_or_default(params[:time_limit], | |
|
68 | 75 | DEFAULT_TIME_LIMIT) |
|
69 | 76 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
70 | 77 | DEFAULT_MEMORY_LIMIT) |
|
71 | 78 | |
|
72 |
- if time_limit |
|
|
73 | - problem.errors.add_to_base('Time limit format errors.') | |
|
74 | - elsif time_limit<=0 or time_limit >60 | |
|
79 | + if time_limit<=0 or time_limit >60 | |
|
75 | 80 | problem.errors.add_to_base('Time limit out of range.') |
|
76 | 81 | end |
|
77 | 82 | |
|
78 |
- if memory_limit==0 and memory_limit |
|
|
83 | + if memory_limit==0 and params[:memory_limit]!='0' | |
|
79 | 84 | problem.errors.add_to_base('Memory limit format errors.') |
|
80 | 85 | elsif memory_limit<=0 or memory_limit >512 |
|
81 | 86 | problem.errors.add_to_base('Memory limit out of range.') |
@@ -88,7 +93,7 | |||
|
88 | 93 | file = params[:file] |
|
89 | 94 | |
|
90 | 95 | if problem.errors.length!=0 |
|
91 | - return problem | |
|
96 | + return nil, problem | |
|
92 | 97 | end |
|
93 | 98 | |
|
94 | 99 | problem.name = params[:name] |
@@ -98,11 +103,12 | |||
|
98 | 103 | problem.full_name = params[:name] |
|
99 | 104 | end |
|
100 | 105 | |
|
101 | - return { | |
|
102 | - :time_limit => time_limit, | |
|
103 | - :memory_limit => memory_limit, | |
|
104 | - :file => file | |
|
105 | - } | |
|
106 | + return [{ | |
|
107 | + :time_limit => time_limit, | |
|
108 | + :memory_limit => memory_limit, | |
|
109 | + :file => file | |
|
110 | + }, | |
|
111 | + problem] | |
|
106 | 112 | end |
|
107 | 113 | |
|
108 | 114 | end |
You need to be logged in to leave comments.
Login now