Description:
Change to better error message when the submitted file has illegal extension Solve issue #4
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r548:ba97cbe38d86 - - 1 file changed: 1 inserted, 1 deleted

@@ -57,117 +57,117
57 57 :user_id => user_id,
58 58 :problem_id => problem_id,
59 59 :number => number
60 60 })
61 61 end
62 62
63 63 def self.find_all_by_user_problem(user_id, problem_id)
64 64 Submission.find(:all,
65 65 :conditions => {
66 66 :user_id => user_id,
67 67 :problem_id => problem_id,
68 68 })
69 69 end
70 70
71 71 def download_filename
72 72 if self.problem.output_only
73 73 return self.source_filename
74 74 else
75 75 timestamp = self.submitted_at.localtime.strftime("%H%M%S")
76 76 return "#{self.problem.name}-#{timestamp}.#{self.language.ext}"
77 77 end
78 78 end
79 79
80 80 protected
81 81
82 82 def self.find_option_in_source(option, source)
83 83 if source==nil
84 84 return nil
85 85 end
86 86 i = 0
87 87 source.each_line do |s|
88 88 if s =~ option
89 89 words = s.split
90 90 return words[1]
91 91 end
92 92 i = i + 1
93 93 if i==10
94 94 return nil
95 95 end
96 96 end
97 97 return nil
98 98 end
99 99
100 100 def self.find_language_in_source(source, source_filename="")
101 101 langopt = find_option_in_source(/^LANG:/,source)
102 102 if langopt
103 103 return (Language.find_by_name(langopt) ||
104 104 Language.find_by_pretty_name(langopt))
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',"must specify programming language") unless self.language!=nil
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