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: 14 inserted, 2 deleted

@@ -135,48 +135,56
135 135 end
136 136 end
137 137
138 138 def manage
139 139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 140 end
141 141
142 142 def do_manage
143 143 if params.has_key? 'change_date_added'
144 144 change_date_added
145 145 end
146 146 redirect_to :action => 'manage'
147 147 end
148 148
149 149 def import
150 150 end
151 151
152 152 def do_import
153 153 @problem, import_log = Problem.new_from_import_form_params(params)
154 154
155 155 if @problem.errors.length != 0
156 156 render :action => 'import' and return
157 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 167 @problem.save
160 168 @log = import_log
161 169 end
162 170
163 171 ##################################
164 172 protected
165 173
166 174 def change_date_added
167 175 problems = get_problems_from_params
168 176 year = params[:date_added][:year].to_i
169 177 month = params[:date_added][:month].to_i
170 178 day = params[:date_added][:day].to_i
171 179 date = Date.new(year,month,day)
172 180 problems.each do |p|
173 181 p.date_added = date
174 182 p.save
175 183 end
176 184 end
177 185
178 186 def get_problems_from_params
179 187 problems = []
180 188 params.keys.each do |k|
181 189 if k.index('prob-')==0
182 190 name, id = k.split('-')
@@ -80,41 +80,41
80 80 rescue
81 81 @test_request = nil
82 82 end
83 83 if @test_request==nil or @test_request.user_id != @user.id
84 84 flash[:notice] = 'Invalid request'
85 85 redirect_to :action => 'index'
86 86 return
87 87 end
88 88 end
89 89
90 90 protected
91 91
92 92 def prepare_index_information
93 93 @user = User.find(session[:user_id])
94 94 @submissions = Submission.find_last_for_all_available_problems(@user.id)
95 95 all_problems = @submissions.collect { |submission| submission.problem }
96 96 @problems = []
97 97 all_problems.each do |problem|
98 98 if problem.test_allowed
99 99 @problems << problem
100 100 end
101 101 end
102 102 @test_requests = []
103 103 @user.test_requests.each do |ts|
104 - if ts.problem.available
104 + if ts.problem and ts.problem.available
105 105 @test_requests << ts
106 106 end
107 107 end
108 108 end
109 109
110 110 def check_viewability
111 111 user = User.find(session[:user_id])
112 112 if !Configuration.show_tasks_to?(user)
113 113 redirect_to :controller => 'main', :action => 'list'
114 114 end
115 115 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
116 116 redirect_to :controller => 'test', :action => 'index'
117 117 end
118 118 end
119 119
120 120 end
@@ -1,29 +1,30
1 1 class Problem < ActiveRecord::Base
2 2
3 3 belongs_to :description
4 4
5 5 validates_presence_of :name
6 + validates_format_of :name, :with => /^\w+$/
6 7 validates_presence_of :full_name
7 8
8 9 def self.find_available_problems
9 10 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
10 11 end
11 12
12 13 def self.new_from_import_form_params(params)
13 14 problem = Problem.new
14 15
15 16 # form error checking
16 17
17 18 time_limit_s = params[:time_limit]
18 19 memory_limit_s = params[:memory_limit]
19 20
20 21 time_limit_s = '1' if time_limit_s==''
21 22 memory_limit_s = '32' if memory_limit_s==''
22 23
23 24 time_limit = time_limit_s.to_i
24 25 memory_limit = memory_limit_s.to_i
25 26
26 27 if time_limit==0 and time_limit_s!='0'
27 28 problem.errors.add_to_base('Time limit format errors.')
28 29 elsif time_limit<=0 or time_limit >60
29 30 problem.errors.add_to_base('Time limit out of range.')
@@ -1,30 +1,33
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'graders'
3 3 <meta http-equiv ="refresh" content="60"/>
4 4
5 5 %h1 Grader information
6 6
7 + = link_to '[Refresh]', :action => 'list'
8 + %br/
9 +
7 10 .submitbox
8 11 .item
9 12 Grader control:
10 13 .item
11 14 - form_for :clear, nil, :url => {:action => 'start_grading'} do |f|
12 15 = submit_tag 'Start graders in grading env'
13 16 .item
14 17 - form_for :clear, nil, :url => {:action => 'start_exam'} do |f|
15 18 = submit_tag 'Start graders in exam env'
16 19 .item
17 20 - form_for :clear, nil, :url => {:action => 'stop_all'} do |f|
18 21 = submit_tag 'Stop all running graders'
19 22 .item
20 23 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
21 24 = submit_tag 'Clear all data'
22 25 %br{:style => 'clear:both'}/
23 26
24 27 - if @last_task
25 28 Last task:
26 29 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
27 30
28 31 %br/
29 32
30 33 - if @last_test_request
@@ -21,49 +21,49
21 21 protected
22 22
23 23 def self.long_ext(filename)
24 24 i = filename.index('.')
25 25 len = filename.length
26 26 return filename.slice(i..len)
27 27 end
28 28
29 29 def self.extract(problem_name, tempfile)
30 30 testdata_filename = TestdataImporter.save_testdata_file(problem_name,
31 31 tempfile)
32 32 ext = TestdataImporter.long_ext(tempfile.original_filename)
33 33
34 34 extract_dir = File.join(GraderScript.raw_dir, problem_name)
35 35 begin
36 36 Dir.mkdir extract_dir
37 37 rescue Errno::EEXIST
38 38 end
39 39
40 40 if ext=='.tar.gz' or ext=='.tgz'
41 41 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
42 42 elsif ext=='.tar'
43 43 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
44 44 elsif ext=='.zip'
45 - cmd = "unzip #{testdata_filename} -d #{extract_dir}"
45 + cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
46 46 else
47 47 return nil
48 48 end
49 49
50 50 system(cmd)
51 51
52 52 files = Dir["#{extract_dir}/**/1*.in"]
53 53 return nil if files.length==0
54 54
55 55 return File.dirname(files[0])
56 56 end
57 57
58 58 def self.save_testdata_file(problem_name, tempfile)
59 59 ext = TestdataImporter.long_ext(tempfile.original_filename)
60 60 testdata_filename = File.join(Dir.tmpdir,"#{problem_name}#{ext}")
61 61
62 62 return nil if tempfile==""
63 63
64 64 if tempfile.instance_of?(Tempfile)
65 65 tempfile.close
66 66 FileUtils.move(tempfile.path,testdata_filename)
67 67 else
68 68 File.open(testdata_filename, "wb") do |f|
69 69 f.write(tempfile.read)
You need to be logged in to leave comments. Login now