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

@@ -1,92 +1,92
1 1 class MainController < ApplicationController
2 2
3 3 before_filter :authenticate, :except => [:index, :login]
4 4
5 5 #
6 6 # COMMENT OUT: filter in each action instead
7 7 #
8 8 # before_filter :verify_time_limit, :only => [:submit]
9 9
10 10 verify :method => :post, :only => [:submit],
11 11 :redirect_to => { :action => :index }
12 12
13 13
14 14 def index
15 15 redirect_to :action => 'login'
16 16 end
17 17
18 18 def login
19 19 saved_notice = flash[:notice]
20 20 reset_session
21 21 flash[:notice] = saved_notice
22 22
23 23 render :action => 'login', :layout => 'empty'
24 24 end
25 25
26 26 def list
27 27 prepare_list_information
28 28 end
29 29
30 30 def help
31 31 @user = User.find(session[:user_id])
32 32 end
33 33
34 34 def submit
35 35 user = User.find(session[:user_id])
36 36
37 37 @submission = Submission.new(params[:submission])
38 38 @submission.user = user
39 39 @submission.language_id = 0
40 40 if params['file']!=''
41 41 @submission.source = params['file'].read
42 42 @submission.source_filename = params['file'].original_filename
43 43 end
44 - @submission.submitted_at = Time.new
44 + @submission.submitted_at = Time.new.gmtime
45 45
46 46 if user.site!=nil and user.site.finished?
47 47 @submission.errors.add_to_base "The contest is over."
48 48 prepare_list_information
49 49 render :action => 'list' and return
50 50 end
51 51
52 52 if @submission.valid?
53 53 if @submission.save == false
54 54 flash[:notice] = 'Error saving your submission'
55 55 elsif Task.create(:submission_id => @submission.id,
56 56 :status => Task::STATUS_INQUEUE) == false
57 57 flash[:notice] = 'Error adding your submission to task queue'
58 58 end
59 59 else
60 60 prepare_list_information
61 61 render :action => 'list' and return
62 62 end
63 63 redirect_to :action => 'list'
64 64 end
65 65
66 66 def source
67 67 submission = Submission.find(params[:id])
68 68 if submission.user_id == session[:user_id]
69 69 if submission.problem.output_only
70 70 fname = submission.source_filename
71 71 else
72 72 fname = submission.problem.name + '.' + submission.language.ext
73 73 end
74 74 send_data(submission.source,
75 75 {:filename => fname,
76 76 :type => 'text/plain'})
77 77 else
78 78 flash[:notice] = 'Error viewing source'
79 79 redirect_to :action => 'list'
80 80 end
81 81 end
82 82
83 83 def compiler_msg
84 84 @submission = Submission.find(params[:id])
85 85 if @submission.user_id == session[:user_id]
86 86 render :action => 'compiler_msg', :layout => 'empty'
87 87 else
88 88 flash[:notice] = 'Error viewing source'
89 89 redirect_to :action => 'list'
90 90 end
91 91 end
92 92
@@ -1,27 +1,27
1 1 class Site < ActiveRecord::Base
2 2
3 3 belongs_to :country
4 4 has_many :users
5 5
6 6 def clear_start_time_if_not_started
7 7 if !self.started
8 8 self.start_time = nil
9 9 end
10 10 end
11 11
12 12 def finished?
13 13 if !self.started
14 14 return false
15 15 end
16 16
17 17 contest_time = Configuration['contest.time_limit']
18 18 if tmatch = /(\d+):(\d+)/.match(contest_time)
19 19 h = tmatch[1].to_i
20 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 22 else
23 23 false
24 24 end
25 25 end
26 26
27 27 end
@@ -37,97 +37,97
37 37 def self.get_inqueue_and_change_status(status)
38 38 # since there will be only one grader grading TestRequest
39 39 # we do not need locking (hopefully)
40 40
41 41 test_request = TestRequest.find(:first,
42 42 :order => "created_at",
43 43 :conditions => {:status=> Task::STATUS_INQUEUE})
44 44 if test_request!=nil
45 45 test_request.status = status
46 46 test_request.save!
47 47 end
48 48
49 49 test_request
50 50 end
51 51
52 52 # interfacing with form
53 53 def self.new_from_form_params(user,params)
54 54 test_request = TestRequest.new
55 55 test_request.user = user
56 56 begin
57 57 problem = Problem.find(params[:problem_id])
58 58 rescue ActiveRecord::RecordNotFound
59 59 problem = nil
60 60 end
61 61 test_request.problem = problem
62 62 if problem!=nil
63 63 test_request.submission =
64 64 Submission.find_by_user_problem_number(user.id,
65 65 problem.id,
66 66 params[:submission_number])
67 67 else
68 68 test_request.submission = nil
69 69 end
70 70
71 71 # checks if the user submits any input file
72 72 if params[:input_file]==nil or params[:input_file]==""
73 73 test_request.errors.add_to_base("No input submitted.")
74 74 test_request.input_file_name = nil
75 75 else
76 76 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
77 77 if test_request.input_file_name == nil
78 78 test_request.errors.add_to_base("No input submitted.")
79 79 end
80 80 if params[:additional_file]!=nil and params[:additional_file]!=""
81 81 save_additional_file(params[:additional_file],
82 82 "#{test_request.input_file_name}.files")
83 83 end
84 84 end
85 - test_request.submitted_at = Time.new
85 + test_request.submitted_at = Time.new.gmtime
86 86 test_request.status_inqueue
87 87 test_request
88 88 end
89 89
90 90 protected
91 91
92 92 def self.name_of(problem)
93 93 if problem!=nil
94 94 problem.name
95 95 else
96 96 "default"
97 97 end
98 98 end
99 99
100 100 def self.random_input_file_name(user,problem)
101 101 problem_name = TestRequest.name_of(problem)
102 102 begin
103 103 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
104 104 end while File.exists?(tmpname)
105 105 tmpname
106 106 end
107 107
108 108 def self.save_input_file(tempfile, user, problem)
109 109 new_file_name = random_input_file_name(user,problem)
110 110 dirname = File.dirname(new_file_name)
111 111 FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname)
112 112
113 113 # when the user did not submit any file
114 114 return nil if tempfile==""
115 115
116 116 if tempfile.instance_of?(Tempfile)
117 117 tempfile.close
118 118 FileUtils.move(tempfile.path,new_file_name)
119 119 else
120 120 File.open(new_file_name, "wb") do |f|
121 121 f.write(tempfile.read)
122 122 end
123 123 end
124 124 new_file_name
125 125 end
126 126
127 127 def self.save_additional_file(tempfile,dir)
128 128 new_file_name = "#{dir}/#{tempfile.original_filename}"
129 129 dirname = File.dirname(new_file_name)
130 130 FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname)
131 131
132 132 # when the user did not submit any file
133 133 return nil if tempfile==""
You need to be logged in to leave comments. Login now