Description:
update errors.add_to_base("x") to Rails 3 errors.add(:base,"x")
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r347:6d2339b98fac - - 6 files changed: 12 inserted, 12 deleted

@@ -48,49 +48,49
48 end
48 end
49
49
50 def list
50 def list
51 prepare_list_information
51 prepare_list_information
52 end
52 end
53
53
54 def help
54 def help
55 @user = User.find(session[:user_id])
55 @user = User.find(session[:user_id])
56 end
56 end
57
57
58 def submit
58 def submit
59 user = User.find(session[:user_id])
59 user = User.find(session[:user_id])
60
60
61 @submission = Submission.new
61 @submission = Submission.new
62 @submission.problem_id = params[:submission][:problem_id]
62 @submission.problem_id = params[:submission][:problem_id]
63 @submission.user = user
63 @submission.user = user
64 @submission.language_id = 0
64 @submission.language_id = 0
65 if (params['file']) and (params['file']!='')
65 if (params['file']) and (params['file']!='')
66 @submission.source = params['file'].read
66 @submission.source = params['file'].read
67 @submission.source_filename = params['file'].original_filename
67 @submission.source_filename = params['file'].original_filename
68 end
68 end
69 @submission.submitted_at = Time.new.gmtime
69 @submission.submitted_at = Time.new.gmtime
70
70
71 if GraderConfiguration.time_limit_mode? and user.contest_finished?
71 if GraderConfiguration.time_limit_mode? and user.contest_finished?
72 - @submission.errors.add_to_base "The contest is over."
72 + @submission.errors.add(:base,"The contest is over.")
73 prepare_list_information
73 prepare_list_information
74 render :action => 'list' and return
74 render :action => 'list' and return
75 end
75 end
76
76
77 if @submission.valid?
77 if @submission.valid?
78 if @submission.save == false
78 if @submission.save == false
79 flash[:notice] = 'Error saving your submission'
79 flash[:notice] = 'Error saving your submission'
80 elsif Task.create(:submission_id => @submission.id,
80 elsif Task.create(:submission_id => @submission.id,
81 :status => Task::STATUS_INQUEUE) == false
81 :status => Task::STATUS_INQUEUE) == false
82 flash[:notice] = 'Error adding your submission to task queue'
82 flash[:notice] = 'Error adding your submission to task queue'
83 end
83 end
84 else
84 else
85 prepare_list_information
85 prepare_list_information
86 render :action => 'list' and return
86 render :action => 'list' and return
87 end
87 end
88 redirect_to :action => 'list'
88 redirect_to :action => 'list'
89 end
89 end
90
90
91 def source
91 def source
92 submission = Submission.find(params[:id])
92 submission = Submission.find(params[:id])
93 if ((submission.user_id == session[:user_id]) and
93 if ((submission.user_id == session[:user_id]) and
94 (submission.problem != nil) and
94 (submission.problem != nil) and
95 (submission.problem.available))
95 (submission.problem.available))
96 send_data(submission.source,
96 send_data(submission.source,
@@ -5,49 +5,49
5 #
5 #
6 # COMMENT OUT: filter in each action instead
6 # COMMENT OUT: filter in each action instead
7 #
7 #
8 # before_filter :verify_time_limit, :only => [:submit]
8 # before_filter :verify_time_limit, :only => [:submit]
9
9
10 verify :method => :post, :only => [:submit],
10 verify :method => :post, :only => [:submit],
11 :redirect_to => { :action => :index }
11 :redirect_to => { :action => :index }
12
12
13 def index
13 def index
14 prepare_index_information
14 prepare_index_information
15 end
15 end
16
16
17 def submit
17 def submit
18 @user = User.find(session[:user_id])
18 @user = User.find(session[:user_id])
19
19
20 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
20 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
21
21
22 if ! @submitted_test_request.errors.empty?
22 if ! @submitted_test_request.errors.empty?
23 prepare_index_information
23 prepare_index_information
24 render :action => 'index' and return
24 render :action => 'index' and return
25 end
25 end
26
26
27 if GraderConfiguration.time_limit_mode?
27 if GraderConfiguration.time_limit_mode?
28 if @user.contest_finished?
28 if @user.contest_finished?
29 - @submitted_test_request.errors.add_to_base('Contest is over.')
29 + @submitted_test_request.errors.add(:base,'Contest is over.')
30 prepare_index_information
30 prepare_index_information
31 render :action => 'index' and return
31 render :action => 'index' and return
32 end
32 end
33
33
34 if !GraderConfiguration.allow_test_request(@user)
34 if !GraderConfiguration.allow_test_request(@user)
35 prepare_index_information
35 prepare_index_information
36 flash[:notice] = 'Test request is not allowed during the last 30 minutes'
36 flash[:notice] = 'Test request is not allowed during the last 30 minutes'
37 redirect_to :action => 'index' and return
37 redirect_to :action => 'index' and return
38 end
38 end
39 end
39 end
40
40
41 if @submitted_test_request.save
41 if @submitted_test_request.save
42 redirect_to :action => 'index'
42 redirect_to :action => 'index'
43 else
43 else
44 prepare_index_information
44 prepare_index_information
45 render :action => 'index'
45 render :action => 'index'
46 end
46 end
47 end
47 end
48
48
49 def read
49 def read
50 user = User.find(session[:user_id])
50 user = User.find(session[:user_id])
51 begin
51 begin
52 test_request = TestRequest.find(params[:id])
52 test_request = TestRequest.find(params[:id])
53 rescue
53 rescue
@@ -41,49 +41,49
41 redirect_to :action => 'index'
41 redirect_to :action => 'index'
42 end
42 end
43
43
44 def new
44 def new
45 @user = User.new
45 @user = User.new
46 render :action => 'new', :layout => 'empty'
46 render :action => 'new', :layout => 'empty'
47 end
47 end
48
48
49 def register
49 def register
50 if(params[:cancel])
50 if(params[:cancel])
51 redirect_to :controller => 'main', :action => 'login'
51 redirect_to :controller => 'main', :action => 'login'
52 return
52 return
53 end
53 end
54 @user = User.new(params[:user])
54 @user = User.new(params[:user])
55 @user.password_confirmation = @user.password = User.random_password
55 @user.password_confirmation = @user.password = User.random_password
56 @user.activated = false
56 @user.activated = false
57 if (@user.valid?) and (@user.save)
57 if (@user.valid?) and (@user.save)
58 if send_confirmation_email(@user)
58 if send_confirmation_email(@user)
59 render :action => 'new_splash', :layout => 'empty'
59 render :action => 'new_splash', :layout => 'empty'
60 else
60 else
61 @admin_email = GraderConfiguration['system.admin_email']
61 @admin_email = GraderConfiguration['system.admin_email']
62 render :action => 'email_error', :layout => 'empty'
62 render :action => 'email_error', :layout => 'empty'
63 end
63 end
64 else
64 else
65 - @user.errors.add_to_base("Email cannot be blank") if @user.email==''
65 + @user.errors.add(:base,"Email cannot be blank") if @user.email==''
66 render :action => 'new', :layout => 'empty'
66 render :action => 'new', :layout => 'empty'
67 end
67 end
68 end
68 end
69
69
70 def confirm
70 def confirm
71 login = params[:login]
71 login = params[:login]
72 key = params[:activation]
72 key = params[:activation]
73 @user = User.find_by_login(login)
73 @user = User.find_by_login(login)
74 if (@user) and (@user.verify_activation_key(key))
74 if (@user) and (@user.verify_activation_key(key))
75 if @user.valid? # check uniquenss of email
75 if @user.valid? # check uniquenss of email
76 @user.activated = true
76 @user.activated = true
77 @user.save
77 @user.save
78 @result = :successful
78 @result = :successful
79 else
79 else
80 @result = :email_used
80 @result = :email_used
81 end
81 end
82 else
82 else
83 @result = :failed
83 @result = :failed
84 end
84 end
85 render :action => 'confirm', :layout => 'empty'
85 render :action => 'confirm', :layout => 'empty'
86 end
86 end
87
87
88 def forget
88 def forget
89 render :action => 'forget', :layout => 'empty'
89 render :action => 'forget', :layout => 'empty'
@@ -23,92 +23,92
23 org_problem)
23 org_problem)
24
24
25 if !problem.errors.empty?
25 if !problem.errors.empty?
26 return problem, 'Error importing'
26 return problem, 'Error importing'
27 end
27 end
28
28
29 problem.full_score = 100
29 problem.full_score = 100
30 problem.date_added = Time.new
30 problem.date_added = Time.new
31 problem.test_allowed = true
31 problem.test_allowed = true
32 problem.output_only = false
32 problem.output_only = false
33 problem.available = false
33 problem.available = false
34
34
35 if not problem.save
35 if not problem.save
36 return problem, 'Error importing'
36 return problem, 'Error importing'
37 end
37 end
38
38
39 import_to_db = params.has_key? :import_to_db
39 import_to_db = params.has_key? :import_to_db
40
40
41 importer = TestdataImporter.new(problem)
41 importer = TestdataImporter.new(problem)
42
42
43 if not importer.import_from_file(import_params[:file],
43 if not importer.import_from_file(import_params[:file],
44 import_params[:time_limit],
44 import_params[:time_limit],
45 import_params[:memory_limit],
45 import_params[:memory_limit],
46 import_to_db)
46 import_to_db)
47 - problem.errors.add_to_base('Import error.')
47 + problem.errors.add(:base,'Import error.')
48 end
48 end
49
49
50 return problem, importer.log_msg
50 return problem, importer.log_msg
51 end
51 end
52
52
53 def self.download_file_basedir
53 def self.download_file_basedir
54 return "#{Rails.root}/data/tasks"
54 return "#{Rails.root}/data/tasks"
55 end
55 end
56
56
57 protected
57 protected
58
58
59 def self.to_i_or_default(st, default)
59 def self.to_i_or_default(st, default)
60 if st!=''
60 if st!=''
61 result = st.to_i
61 result = st.to_i
62 end
62 end
63 result ||= default
63 result ||= default
64 end
64 end
65
65
66 def self.to_f_or_default(st, default)
66 def self.to_f_or_default(st, default)
67 if st!=''
67 if st!=''
68 result = st.to_f
68 result = st.to_f
69 end
69 end
70 result ||= default
70 result ||= default
71 end
71 end
72
72
73 def self.extract_params_and_check(params, problem)
73 def self.extract_params_and_check(params, problem)
74 time_limit = Problem.to_f_or_default(params[:time_limit],
74 time_limit = Problem.to_f_or_default(params[:time_limit],
75 DEFAULT_TIME_LIMIT)
75 DEFAULT_TIME_LIMIT)
76 memory_limit = Problem.to_i_or_default(params[:memory_limit],
76 memory_limit = Problem.to_i_or_default(params[:memory_limit],
77 DEFAULT_MEMORY_LIMIT)
77 DEFAULT_MEMORY_LIMIT)
78
78
79 if time_limit<=0 or time_limit >60
79 if time_limit<=0 or time_limit >60
80 - problem.errors.add_to_base('Time limit out of range.')
80 + problem.errors.add(:base,'Time limit out of range.')
81 end
81 end
82
82
83 if memory_limit==0 and params[:memory_limit]!='0'
83 if memory_limit==0 and params[:memory_limit]!='0'
84 - problem.errors.add_to_base('Memory limit format errors.')
84 + problem.errors.add(:base,'Memory limit format errors.')
85 elsif memory_limit<=0 or memory_limit >512
85 elsif memory_limit<=0 or memory_limit >512
86 - problem.errors.add_to_base('Memory limit out of range.')
86 + problem.errors.add(:base,'Memory limit out of range.')
87 end
87 end
88
88
89 if params[:file]==nil or params[:file]==''
89 if params[:file]==nil or params[:file]==''
90 - problem.errors.add_to_base('No testdata file.')
90 + problem.errors.add(:base,'No testdata file.')
91 end
91 end
92
92
93 file = params[:file]
93 file = params[:file]
94
94
95 if !problem.errors.empty?
95 if !problem.errors.empty?
96 return nil, problem
96 return nil, problem
97 end
97 end
98
98
99 problem.name = params[:name]
99 problem.name = params[:name]
100 if params[:full_name]!=''
100 if params[:full_name]!=''
101 problem.full_name = params[:full_name]
101 problem.full_name = params[:full_name]
102 else
102 else
103 problem.full_name = params[:name]
103 problem.full_name = params[:name]
104 end
104 end
105
105
106 return [{
106 return [{
107 :time_limit => time_limit,
107 :time_limit => time_limit,
108 :memory_limit => memory_limit,
108 :memory_limit => memory_limit,
109 :file => file
109 :file => file
110 },
110 },
111 problem]
111 problem]
112 end
112 end
113
113
114 end
114 end
@@ -49,54 +49,54
49 test_request
49 test_request
50 end
50 end
51
51
52 # interfacing with form
52 # interfacing with form
53 def self.new_from_form_params(user,params)
53 def self.new_from_form_params(user,params)
54 test_request = TestRequest.new
54 test_request = TestRequest.new
55 test_request.user = user
55 test_request.user = user
56 begin
56 begin
57 problem = Problem.find(params[:problem_id])
57 problem = Problem.find(params[:problem_id])
58 rescue ActiveRecord::RecordNotFound
58 rescue ActiveRecord::RecordNotFound
59 problem = nil
59 problem = nil
60 end
60 end
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(: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.adds(: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.gmtime
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
@@ -277,47 +277,47
277 def assign_default_contest
277 def assign_default_contest
278 # have to catch error when migrating (because self.site is not available).
278 # have to catch error when migrating (because self.site is not available).
279 begin
279 begin
280 if self.contests.length == 0
280 if self.contests.length == 0
281 default_contest = Contest.find_by_name(GraderConfiguration['contest.default_contest_name'])
281 default_contest = Contest.find_by_name(GraderConfiguration['contest.default_contest_name'])
282 if default_contest
282 if default_contest
283 self.contests = [default_contest]
283 self.contests = [default_contest]
284 end
284 end
285 end
285 end
286 rescue
286 rescue
287 end
287 end
288 end
288 end
289
289
290 def password_required?
290 def password_required?
291 self.hashed_password.blank? || !self.password.blank?
291 self.hashed_password.blank? || !self.password.blank?
292 end
292 end
293
293
294 def self.encrypt(string,salt)
294 def self.encrypt(string,salt)
295 Digest::SHA1.hexdigest(salt + string)
295 Digest::SHA1.hexdigest(salt + string)
296 end
296 end
297
297
298 def uniqueness_of_email_from_activated_users
298 def uniqueness_of_email_from_activated_users
299 user = User.activated_users.find_by_email(self.email)
299 user = User.activated_users.find_by_email(self.email)
300 if user and (user.login != self.login)
300 if user and (user.login != self.login)
301 - self.errors.add_to_base("Email has already been taken")
301 + self.errors.add(:base,"Email has already been taken")
302 end
302 end
303 end
303 end
304
304
305 def enough_time_interval_between_same_email_registrations
305 def enough_time_interval_between_same_email_registrations
306 return if !self.new_record?
306 return if !self.new_record?
307 return if self.activated
307 return if self.activated
308 open_user = User.find_by_email(self.email,
308 open_user = User.find_by_email(self.email,
309 :order => 'created_at DESC')
309 :order => 'created_at DESC')
310 if open_user and open_user.created_at and
310 if open_user and open_user.created_at and
311 (open_user.created_at > Time.now.gmtime - 5.minutes)
311 (open_user.created_at > Time.now.gmtime - 5.minutes)
312 - self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
312 + self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
313 end
313 end
314 end
314 end
315
315
316 def email_validation?
316 def email_validation?
317 begin
317 begin
318 return VALIDATE_USER_EMAILS
318 return VALIDATE_USER_EMAILS
319 rescue
319 rescue
320 return false
320 return false
321 end
321 end
322 end
322 end
323 end
323 end
You need to be logged in to leave comments. Login now