Show More
Commit Description:
[web] test request stops at 30 min before end, auto refresh grader process status...
Commit Description:
[web] test request stops at 30 min before end, auto refresh grader process status
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@258 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb
| 79 lines
| 1.6 KiB
| text/x-ruby
| RubyLexer
|
|
r122 | # | ||
# This class also contains various login of the system. | ||||
# | ||||
|
r76 | class Configuration < ActiveRecord::Base | ||
|
r122 | SYSTEM_MODE_CONF_KEY = 'system.mode' | ||
|
r76 | @@configurations = nil | ||
def self.get(key) | ||||
if @@configurations == nil | ||||
self.read_config | ||||
end | ||||
return @@configurations[key] | ||||
end | ||||
def self.[](key) | ||||
self.get(key) | ||||
end | ||||
def self.reload | ||||
self.read_config | ||||
end | ||||
def self.clear | ||||
@@configurations = nil | ||||
end | ||||
|
r122 | # | ||
# View decision | ||||
# | ||||
def self.show_submitbox_to?(user) | ||||
mode = get(SYSTEM_MODE_CONF_KEY) | ||||
return false if mode=='analysis' | ||||
if (mode=='contest') | ||||
return false if (user.site!=nil) and | ||||
((user.site.started==false) or (user.site.finished?)) | ||||
end | ||||
return true | ||||
end | ||||
def self.show_tasks_to?(user) | ||||
mode = get(SYSTEM_MODE_CONF_KEY) | ||||
if (mode=='contest') | ||||
return false if (user.site!=nil) and (user.site.started==false) | ||||
end | ||||
return true | ||||
end | ||||
|
r128 | |||
def self.allow_test_request(user) | ||||
mode = get(SYSTEM_MODE_CONF_KEY) | ||||
if (mode=='contest') | ||||
return false if (user.site!=nil) and ((user.site.started==false) or | ||||
(user.site.time_left < 30.minutes)) | ||||
end | ||||
return false if mode=='analysis' | ||||
return true | ||||
end | ||||
|
r122 | |||
|
r76 | protected | ||
def self.read_config | ||||
@@configurations = {} | ||||
Configuration.find(:all).each do |conf| | ||||
key = conf.key | ||||
val = conf.value | ||||
case conf.value_type | ||||
when 'string' | ||||
@@configurations[key] = val | ||||
when 'integer' | ||||
@@configurations[key] = val.to_i | ||||
when 'boolean' | ||||
@@configurations[key] = (val=='true') | ||||
end | ||||
end | ||||
end | ||||
end | ||||