Description:
prevents submission language assignment when already specified
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r773:1aa5e27cc4f1 - - 1 file changed: 3 inserted, 1 deleted
@@ -106,61 +106,63 | |||
|
106 | 106 | return problem |
|
107 | 107 | else |
|
108 | 108 | if source_filename |
|
109 | 109 | return Problem.find_by_name(source_filename.split('.').first) |
|
110 | 110 | else |
|
111 | 111 | return nil |
|
112 | 112 | end |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def assign_problem |
|
117 | 117 | if self.problem_id!=-1 |
|
118 | 118 | begin |
|
119 | 119 | self.problem = Problem.find(self.problem_id) |
|
120 | 120 | rescue ActiveRecord::RecordNotFound |
|
121 | 121 | self.problem = nil |
|
122 | 122 | end |
|
123 | 123 | else |
|
124 | 124 | self.problem = Submission.find_problem_in_source(self.source, |
|
125 | 125 | self.source_filename) |
|
126 | 126 | end |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def assign_language |
|
130 | + if self.language == nil | |
|
130 | 131 | self.language = Submission.find_language_in_source(self.source, |
|
131 | 132 | self.source_filename) |
|
132 | 133 | end |
|
134 | + end | |
|
133 | 135 | |
|
134 | 136 | # validation codes |
|
135 | 137 | def must_specify_language |
|
136 | 138 | return if self.source==nil |
|
137 | 139 | |
|
138 | 140 | # for output_only tasks |
|
139 | 141 | return if self.problem!=nil and self.problem.output_only |
|
140 | 142 | |
|
141 | 143 | if self.language==nil |
|
142 |
- errors.add('source',"Cannot detect language. Did you submit a correct source file?") |
|
|
144 | + errors.add('source',"Cannot detect language. Did you submit a correct source file?") | |
|
143 | 145 | end |
|
144 | 146 | end |
|
145 | 147 | |
|
146 | 148 | def must_have_valid_problem |
|
147 | 149 | return if self.source==nil |
|
148 | 150 | if self.problem==nil |
|
149 | 151 | errors.add('problem',"must be specified.") |
|
150 | 152 | else |
|
151 | 153 | #admin always have right |
|
152 | 154 | return if self.user.admin? |
|
153 | 155 | |
|
154 | 156 | #check if user has the right to submit the problem |
|
155 | 157 | errors.add('problem',"must be valid.") if (!self.user.available_problems.include?(self.problem)) and (self.new_record?) |
|
156 | 158 | end |
|
157 | 159 | end |
|
158 | 160 | |
|
159 | 161 | # callbacks |
|
160 | 162 | def assign_latest_number_if_new_recond |
|
161 | 163 | return if !self.new_record? |
|
162 | 164 | latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id) |
|
163 | 165 | self.number = (latest==nil) ? 1 : latest.number + 1; |
|
164 | 166 | end |
|
165 | 167 | |
|
166 | 168 | end |
You need to be logged in to leave comments.
Login now