Description:
[web] fix time.new, time.now to use gmtime git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@249 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

r121:00c0c912cae9 - - 3 files changed: 3 inserted, 3 deleted

@@ -20,49 +20,49
20 reset_session
20 reset_session
21 flash[:notice] = saved_notice
21 flash[:notice] = saved_notice
22
22
23 render :action => 'login', :layout => 'empty'
23 render :action => 'login', :layout => 'empty'
24 end
24 end
25
25
26 def list
26 def list
27 prepare_list_information
27 prepare_list_information
28 end
28 end
29
29
30 def help
30 def help
31 @user = User.find(session[:user_id])
31 @user = User.find(session[:user_id])
32 end
32 end
33
33
34 def submit
34 def submit
35 user = User.find(session[:user_id])
35 user = User.find(session[:user_id])
36
36
37 @submission = Submission.new(params[:submission])
37 @submission = Submission.new(params[:submission])
38 @submission.user = user
38 @submission.user = user
39 @submission.language_id = 0
39 @submission.language_id = 0
40 if params['file']!=''
40 if params['file']!=''
41 @submission.source = params['file'].read
41 @submission.source = params['file'].read
42 @submission.source_filename = params['file'].original_filename
42 @submission.source_filename = params['file'].original_filename
43 end
43 end
44 - @submission.submitted_at = Time.new
44 + @submission.submitted_at = Time.new.gmtime
45
45
46 if user.site!=nil and user.site.finished?
46 if user.site!=nil and user.site.finished?
47 @submission.errors.add_to_base "The contest is over."
47 @submission.errors.add_to_base "The contest is over."
48 prepare_list_information
48 prepare_list_information
49 render :action => 'list' and return
49 render :action => 'list' and return
50 end
50 end
51
51
52 if @submission.valid?
52 if @submission.valid?
53 if @submission.save == false
53 if @submission.save == false
54 flash[:notice] = 'Error saving your submission'
54 flash[:notice] = 'Error saving your submission'
55 elsif Task.create(:submission_id => @submission.id,
55 elsif Task.create(:submission_id => @submission.id,
56 :status => Task::STATUS_INQUEUE) == false
56 :status => Task::STATUS_INQUEUE) == false
57 flash[:notice] = 'Error adding your submission to task queue'
57 flash[:notice] = 'Error adding your submission to task queue'
58 end
58 end
59 else
59 else
60 prepare_list_information
60 prepare_list_information
61 render :action => 'list' and return
61 render :action => 'list' and return
62 end
62 end
63 redirect_to :action => 'list'
63 redirect_to :action => 'list'
64 end
64 end
65
65
66 def source
66 def source
67 submission = Submission.find(params[:id])
67 submission = Submission.find(params[:id])
68 if submission.user_id == session[:user_id]
68 if submission.user_id == session[:user_id]
@@ -1,27 +1,27
1 class Site < ActiveRecord::Base
1 class Site < ActiveRecord::Base
2
2
3 belongs_to :country
3 belongs_to :country
4 has_many :users
4 has_many :users
5
5
6 def clear_start_time_if_not_started
6 def clear_start_time_if_not_started
7 if !self.started
7 if !self.started
8 self.start_time = nil
8 self.start_time = nil
9 end
9 end
10 end
10 end
11
11
12 def finished?
12 def finished?
13 if !self.started
13 if !self.started
14 return false
14 return false
15 end
15 end
16
16
17 contest_time = Configuration['contest.time_limit']
17 contest_time = Configuration['contest.time_limit']
18 if tmatch = /(\d+):(\d+)/.match(contest_time)
18 if tmatch = /(\d+):(\d+)/.match(contest_time)
19 h = tmatch[1].to_i
19 h = tmatch[1].to_i
20 m = tmatch[2].to_i
20 m = tmatch[2].to_i
21 - return Time.now > (self.start_time + h.hour + m.minute)
21 + return Time.now.gmtime > (self.start_time + h.hour + m.minute)
22 else
22 else
23 false
23 false
24 end
24 end
25 end
25 end
26
26
27 end
27 end
@@ -61,49 +61,49
61 test_request.problem = problem
61 test_request.problem = problem
62 if problem!=nil
62 if problem!=nil
63 test_request.submission =
63 test_request.submission =
64 Submission.find_by_user_problem_number(user.id,
64 Submission.find_by_user_problem_number(user.id,
65 problem.id,
65 problem.id,
66 params[:submission_number])
66 params[:submission_number])
67 else
67 else
68 test_request.submission = nil
68 test_request.submission = nil
69 end
69 end
70
70
71 # checks if the user submits any input file
71 # checks if the user submits any input file
72 if params[:input_file]==nil or params[:input_file]==""
72 if params[:input_file]==nil or params[:input_file]==""
73 test_request.errors.add_to_base("No input submitted.")
73 test_request.errors.add_to_base("No input submitted.")
74 test_request.input_file_name = nil
74 test_request.input_file_name = nil
75 else
75 else
76 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
76 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
77 if test_request.input_file_name == nil
77 if test_request.input_file_name == nil
78 test_request.errors.add_to_base("No input submitted.")
78 test_request.errors.add_to_base("No input submitted.")
79 end
79 end
80 if params[:additional_file]!=nil and params[:additional_file]!=""
80 if params[:additional_file]!=nil and params[:additional_file]!=""
81 save_additional_file(params[:additional_file],
81 save_additional_file(params[:additional_file],
82 "#{test_request.input_file_name}.files")
82 "#{test_request.input_file_name}.files")
83 end
83 end
84 end
84 end
85 - test_request.submitted_at = Time.new
85 + test_request.submitted_at = Time.new.gmtime
86 test_request.status_inqueue
86 test_request.status_inqueue
87 test_request
87 test_request
88 end
88 end
89
89
90 protected
90 protected
91
91
92 def self.name_of(problem)
92 def self.name_of(problem)
93 if problem!=nil
93 if problem!=nil
94 problem.name
94 problem.name
95 else
95 else
96 "default"
96 "default"
97 end
97 end
98 end
98 end
99
99
100 def self.random_input_file_name(user,problem)
100 def self.random_input_file_name(user,problem)
101 problem_name = TestRequest.name_of(problem)
101 problem_name = TestRequest.name_of(problem)
102 begin
102 begin
103 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
103 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
104 end while File.exists?(tmpname)
104 end while File.exists?(tmpname)
105 tmpname
105 tmpname
106 end
106 end
107
107
108 def self.save_input_file(tempfile, user, problem)
108 def self.save_input_file(tempfile, user, problem)
109 new_file_name = random_input_file_name(user,problem)
109 new_file_name = random_input_file_name(user,problem)
You need to be logged in to leave comments. Login now