Description:
import problem replaced old one, fixed small problems problem validates name to have no space, test interface can deal with broken dependecies on problems. git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@436 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

r205:9bf8e38c2911 - - 5 files changed: 15 inserted, 3 deleted

@@ -147,24 +147,32
147 end
147 end
148
148
149 def import
149 def import
150 end
150 end
151
151
152 def do_import
152 def do_import
153 @problem, import_log = Problem.new_from_import_form_params(params)
153 @problem, import_log = Problem.new_from_import_form_params(params)
154
154
155 if @problem.errors.length != 0
155 if @problem.errors.length != 0
156 render :action => 'import' and return
156 render :action => 'import' and return
157 end
157 end
158
158
159 + old_problem = Problem.find_by_name(@problem.name)
160 + if old_problem!=nil
161 + old_problem.full_name = @problem.full_name
162 + @problem = old_problem
163 +
164 + flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
165 + end
166 +
159 @problem.save
167 @problem.save
160 @log = import_log
168 @log = import_log
161 end
169 end
162
170
163 ##################################
171 ##################################
164 protected
172 protected
165
173
166 def change_date_added
174 def change_date_added
167 problems = get_problems_from_params
175 problems = get_problems_from_params
168 year = params[:date_added][:year].to_i
176 year = params[:date_added][:year].to_i
169 month = params[:date_added][:month].to_i
177 month = params[:date_added][:month].to_i
170 day = params[:date_added][:day].to_i
178 day = params[:date_added][:day].to_i
@@ -92,25 +92,25
92 def prepare_index_information
92 def prepare_index_information
93 @user = User.find(session[:user_id])
93 @user = User.find(session[:user_id])
94 @submissions = Submission.find_last_for_all_available_problems(@user.id)
94 @submissions = Submission.find_last_for_all_available_problems(@user.id)
95 all_problems = @submissions.collect { |submission| submission.problem }
95 all_problems = @submissions.collect { |submission| submission.problem }
96 @problems = []
96 @problems = []
97 all_problems.each do |problem|
97 all_problems.each do |problem|
98 if problem.test_allowed
98 if problem.test_allowed
99 @problems << problem
99 @problems << problem
100 end
100 end
101 end
101 end
102 @test_requests = []
102 @test_requests = []
103 @user.test_requests.each do |ts|
103 @user.test_requests.each do |ts|
104 - if ts.problem.available
104 + if ts.problem and ts.problem.available
105 @test_requests << ts
105 @test_requests << ts
106 end
106 end
107 end
107 end
108 end
108 end
109
109
110 def check_viewability
110 def check_viewability
111 user = User.find(session[:user_id])
111 user = User.find(session[:user_id])
112 if !Configuration.show_tasks_to?(user)
112 if !Configuration.show_tasks_to?(user)
113 redirect_to :controller => 'main', :action => 'list'
113 redirect_to :controller => 'main', :action => 'list'
114 end
114 end
115 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
115 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
116 redirect_to :controller => 'test', :action => 'index'
116 redirect_to :controller => 'test', :action => 'index'
@@ -1,19 +1,20
1 class Problem < ActiveRecord::Base
1 class Problem < ActiveRecord::Base
2
2
3 belongs_to :description
3 belongs_to :description
4
4
5 validates_presence_of :name
5 validates_presence_of :name
6 + validates_format_of :name, :with => /^\w+$/
6 validates_presence_of :full_name
7 validates_presence_of :full_name
7 -
8 +
8 def self.find_available_problems
9 def self.find_available_problems
9 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
10 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
10 end
11 end
11
12
12 def self.new_from_import_form_params(params)
13 def self.new_from_import_form_params(params)
13 problem = Problem.new
14 problem = Problem.new
14
15
15 # form error checking
16 # form error checking
16
17
17 time_limit_s = params[:time_limit]
18 time_limit_s = params[:time_limit]
18 memory_limit_s = params[:memory_limit]
19 memory_limit_s = params[:memory_limit]
19
20
@@ -1,18 +1,21
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'graders'
2 = stylesheet_link_tag 'graders'
3 <meta http-equiv ="refresh" content="60"/>
3 <meta http-equiv ="refresh" content="60"/>
4
4
5 %h1 Grader information
5 %h1 Grader information
6
6
7 + = link_to '[Refresh]', :action => 'list'
8 + %br/
9 +
7 .submitbox
10 .submitbox
8 .item
11 .item
9 Grader control:
12 Grader control:
10 .item
13 .item
11 - form_for :clear, nil, :url => {:action => 'start_grading'} do |f|
14 - form_for :clear, nil, :url => {:action => 'start_grading'} do |f|
12 = submit_tag 'Start graders in grading env'
15 = submit_tag 'Start graders in grading env'
13 .item
16 .item
14 - form_for :clear, nil, :url => {:action => 'start_exam'} do |f|
17 - form_for :clear, nil, :url => {:action => 'start_exam'} do |f|
15 = submit_tag 'Start graders in exam env'
18 = submit_tag 'Start graders in exam env'
16 .item
19 .item
17 - form_for :clear, nil, :url => {:action => 'stop_all'} do |f|
20 - form_for :clear, nil, :url => {:action => 'stop_all'} do |f|
18 = submit_tag 'Stop all running graders'
21 = submit_tag 'Stop all running graders'
@@ -33,25 +33,25
33
33
34 extract_dir = File.join(GraderScript.raw_dir, problem_name)
34 extract_dir = File.join(GraderScript.raw_dir, problem_name)
35 begin
35 begin
36 Dir.mkdir extract_dir
36 Dir.mkdir extract_dir
37 rescue Errno::EEXIST
37 rescue Errno::EEXIST
38 end
38 end
39
39
40 if ext=='.tar.gz' or ext=='.tgz'
40 if ext=='.tar.gz' or ext=='.tgz'
41 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
41 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
42 elsif ext=='.tar'
42 elsif ext=='.tar'
43 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
43 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
44 elsif ext=='.zip'
44 elsif ext=='.zip'
45 - cmd = "unzip #{testdata_filename} -d #{extract_dir}"
45 + cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
46 else
46 else
47 return nil
47 return nil
48 end
48 end
49
49
50 system(cmd)
50 system(cmd)
51
51
52 files = Dir["#{extract_dir}/**/1*.in"]
52 files = Dir["#{extract_dir}/**/1*.in"]
53 return nil if files.length==0
53 return nil if files.length==0
54
54
55 return File.dirname(files[0])
55 return File.dirname(files[0])
56 end
56 end
57
57
You need to be logged in to leave comments. Login now