# HG changeset patch # User jittat # Date 2009-12-10 07:33:40 # Node ID 9bf8e38c29115d01b92c80d5696512263deff428 # Parent ffd23bd6817d84a2a21b809ce85d99d3d328ac99 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 diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -156,6 +156,14 @@ render :action => 'import' and return end + old_problem = Problem.find_by_name(@problem.name) + if old_problem!=nil + old_problem.full_name = @problem.full_name + @problem = old_problem + + flash[:notice] = "The test data has been replaced for problem #{@problem.name}" + end + @problem.save @log = import_log end diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -101,7 +101,7 @@ end @test_requests = [] @user.test_requests.each do |ts| - if ts.problem.available + if ts.problem and ts.problem.available @test_requests << ts end end diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -3,8 +3,9 @@ belongs_to :description validates_presence_of :name + validates_format_of :name, :with => /^\w+$/ validates_presence_of :full_name - + def self.find_available_problems find(:all, :conditions => {:available => true}, :order => "date_added DESC") end diff --git a/app/views/graders/list.html.haml b/app/views/graders/list.html.haml --- a/app/views/graders/list.html.haml +++ b/app/views/graders/list.html.haml @@ -4,6 +4,9 @@ %h1 Grader information += link_to '[Refresh]', :action => 'list' +%br/ + .submitbox .item Grader control: diff --git a/lib/testdata_importer.rb b/lib/testdata_importer.rb --- a/lib/testdata_importer.rb +++ b/lib/testdata_importer.rb @@ -42,7 +42,7 @@ elsif ext=='.tar' cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}" elsif ext=='.zip' - cmd = "unzip #{testdata_filename} -d #{extract_dir}" + cmd = "unzip -o #{testdata_filename} -d #{extract_dir}" else return nil end