Show More
Commit Description:
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
Commit Description:
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@359 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
app/controllers/test_controller.rb
| 120 lines
| 3.1 KiB
| text/x-ruby
| RubyLexer
|
|
r44 | class TestController < ApplicationController | ||
|
r122 | SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
before_filter :authenticate, :check_viewability | ||||
|
r44 | |||
|
r85 | # | ||
# COMMENT OUT: filter in each action instead | ||||
# | ||||
# before_filter :verify_time_limit, :only => [:submit] | ||||
|
r79 | verify :method => :post, :only => [:submit], | ||
|
r44 | :redirect_to => { :action => :index } | ||
def index | ||||
prepare_index_information | ||||
end | ||||
def submit | ||||
@user = User.find(session[:user_id]) | ||||
|
r85 | |||
|
r86 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) | ||
if @submitted_test_request.errors.length != 0 | ||||
prepare_index_information | ||||
render :action => 'index' and return | ||||
|
r85 | end | ||
|
r128 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' | ||
if @user.site!=nil and @user.site.finished? | ||||
@submitted_test_request.errors.add_to_base('Contest is over.') | ||||
prepare_index_information | ||||
render :action => 'index' and return | ||||
end | ||||
if !Configuration.allow_test_request(@user) | ||||
prepare_index_information | ||||
flash[:notice] = 'Test request is not allowed during the last 30 minutes' | ||||
redirect_to :action => 'index' and return | ||||
end | ||||
|
r86 | end | ||
if @submitted_test_request.save | ||||
|
r44 | redirect_to :action => 'index' | ||
else | ||||
|
r86 | prepare_index_information | ||
render :action => 'index' | ||||
|
r44 | end | ||
end | ||||
def read | ||||
user = User.find(session[:user_id]) | ||||
|
r79 | begin | ||
test_request = TestRequest.find(params[:id]) | ||||
rescue | ||||
test_request = nil | ||||
end | ||||
if test_request==nil or test_request.user_id != user.id | ||||
|
r44 | flash[:notice] = 'Invalid output' | ||
redirect_to :action => 'index' | ||||
return | ||||
end | ||||
if test_request.output_file_name!=nil | ||||
data = File.open(test_request.output_file_name).read(2048) | ||||
|
r49 | if data==nil | ||
data="" | ||||
end | ||||
|
r44 | send_data(data, | ||
{:filename => 'output.txt', | ||||
:type => 'text/plain'}) | ||||
return | ||||
end | ||||
redirect_to :action => 'index' | ||||
end | ||||
|
r79 | |||
def result | ||||
@user = User.find(session[:user_id]) | ||||
begin | ||||
@test_request = TestRequest.find(params[:id]) | ||||
rescue | ||||
@test_request = nil | ||||
end | ||||
if @test_request==nil or @test_request.user_id != @user.id | ||||
flash[:notice] = 'Invalid request' | ||||
redirect_to :action => 'index' | ||||
return | ||||
end | ||||
end | ||||
|
r44 | |||
protected | ||||
def prepare_index_information | ||||
|
r86 | @user = User.find(session[:user_id]) | ||
|
r44 | @submissions = Submission.find_last_for_all_available_problems(@user.id) | ||
|
r94 | all_problems = @submissions.collect { |submission| submission.problem } | ||
@problems = [] | ||||
all_problems.each do |problem| | ||||
if problem.test_allowed | ||||
@problems << problem | ||||
end | ||||
end | ||||
|
r162 | @test_requests = [] | ||
@user.test_requests.each do |ts| | ||||
if ts.problem.available | ||||
@test_requests << ts | ||||
end | ||||
end | ||||
|
r44 | end | ||
|
r122 | def check_viewability | ||
user = User.find(session[:user_id]) | ||||
if !Configuration.show_tasks_to?(user) | ||||
redirect_to :controller => 'main', :action => 'list' | ||||
end | ||||
if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit') | ||||
redirect_to :controller => 'test', :action => 'index' | ||||
end | ||||
end | ||||
|
r44 | end | ||