Description:
Change to better error message when the submitted file has illegal extension
Solve issue #4
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r548:ba97cbe38d86 - - 1 file changed: 1 inserted, 1 deleted
@@ -105,69 +105,69 | |||
|
105 | 105 | else |
|
106 | 106 | if source_filename |
|
107 | 107 | return Language.find_by_extension(source_filename.split('.').last) |
|
108 | 108 | else |
|
109 | 109 | return nil |
|
110 | 110 | end |
|
111 | 111 | end |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def self.find_problem_in_source(source, source_filename="") |
|
115 | 115 | prob_opt = find_option_in_source(/^TASK:/,source) |
|
116 | 116 | if problem = Problem.find_by_name(prob_opt) |
|
117 | 117 | return problem |
|
118 | 118 | else |
|
119 | 119 | if source_filename |
|
120 | 120 | return Problem.find_by_name(source_filename.split('.').first) |
|
121 | 121 | else |
|
122 | 122 | return nil |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def assign_problem |
|
128 | 128 | if self.problem_id!=-1 |
|
129 | 129 | begin |
|
130 | 130 | self.problem = Problem.find(self.problem_id) |
|
131 | 131 | rescue ActiveRecord::RecordNotFound |
|
132 | 132 | self.problem = nil |
|
133 | 133 | end |
|
134 | 134 | else |
|
135 | 135 | self.problem = Submission.find_problem_in_source(self.source, |
|
136 | 136 | self.source_filename) |
|
137 | 137 | end |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def assign_language |
|
141 | 141 | self.language = Submission.find_language_in_source(self.source, |
|
142 | 142 | self.source_filename) |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | # validation codes |
|
146 | 146 | def must_specify_language |
|
147 | 147 | return if self.source==nil |
|
148 | 148 | |
|
149 | 149 | # for output_only tasks |
|
150 | 150 | return if self.problem!=nil and self.problem.output_only |
|
151 | 151 | |
|
152 | 152 | if self.language==nil |
|
153 |
- errors.add('source'," |
|
|
153 | + errors.add('source',"Cannot detect language. Did you submit a correct source file?") unless self.language!=nil | |
|
154 | 154 | end |
|
155 | 155 | end |
|
156 | 156 | |
|
157 | 157 | def must_have_valid_problem |
|
158 | 158 | return if self.source==nil |
|
159 | 159 | if self.problem==nil |
|
160 | 160 | errors.add('problem',"must be specified.") |
|
161 | 161 | elsif (!self.problem.available) and (self.new_record?) |
|
162 | 162 | errors.add('problem',"must be valid.") |
|
163 | 163 | end |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | # callbacks |
|
167 | 167 | def assign_latest_number_if_new_recond |
|
168 | 168 | return if !self.new_record? |
|
169 | 169 | latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id) |
|
170 | 170 | self.number = (latest==nil) ? 1 : latest.number + 1; |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | end |
You need to be logged in to leave comments.
Login now