Description:
[web] fixed submission numbering bugs: should sort by number instead of submitted_at because submitted_at can be equal git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@149 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r72:4bf745b7ef5b - - 1 file changed: 1 inserted, 1 deleted

@@ -7,25 +7,25
7 validates_presence_of :source
7 validates_presence_of :source
8 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
8 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
9 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
9 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
10 validate :must_specify_language
10 validate :must_specify_language
11 validate :must_have_valid_problem
11 validate :must_have_valid_problem
12
12
13 before_save :assign_latest_number_if_new_recond
13 before_save :assign_latest_number_if_new_recond
14
14
15 def self.find_last_by_user_and_problem(user_id, problem_id)
15 def self.find_last_by_user_and_problem(user_id, problem_id)
16 last_sub = find(:first,
16 last_sub = find(:first,
17 :conditions => {:user_id => user_id,
17 :conditions => {:user_id => user_id,
18 :problem_id => problem_id},
18 :problem_id => problem_id},
19 - :order => 'submitted_at DESC')
19 + :order => 'number DESC')
20 return last_sub
20 return last_sub
21 end
21 end
22
22
23 def self.find_all_last_by_problem(problem_id)
23 def self.find_all_last_by_problem(problem_id)
24 # need to put in SQL command, maybe there's a better way
24 # need to put in SQL command, maybe there's a better way
25 Submission.find_by_sql("SELECT * FROM submissions " +
25 Submission.find_by_sql("SELECT * FROM submissions " +
26 "WHERE id = " +
26 "WHERE id = " +
27 "(SELECT MAX(id) FROM submissions AS subs " +
27 "(SELECT MAX(id) FROM submissions AS subs " +
28 "WHERE subs.user_id = submissions.user_id AND " +
28 "WHERE subs.user_id = submissions.user_id AND " +
29 "problem_id = " + problem_id.to_s + " " +
29 "problem_id = " + problem_id.to_s + " " +
30 "GROUP BY user_id)")
30 "GROUP BY user_id)")
31 end
31 end
You need to be logged in to leave comments. Login now