Show More
Commit Description:
Merged online-registration branch changes r297:303 into the trunk...
Commit Description:
Merged online-registration branch changes r297:303 into the trunk git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@303 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/models/configuration.rb | 123 lines | 2.4 KiB | text/x-ruby | RubyLexer |
jittat
[web] analysis mode...
r134 require 'yaml'
jittat
[web] added mode + access control, when sites started/finished...
r122 #
# This class also contains various login of the system.
#
jittat
[web] added configurations...
r76 class Configuration < ActiveRecord::Base
jittat
[web] added mode + access control, when sites started/finished...
r122 SYSTEM_MODE_CONF_KEY = 'system.mode'
jittat
removed caching on Configuration...
r146 # set @@cache = true to only reload once.
@@cache = false
jittat
[web] added configurations...
r76 @@configurations = nil
jittat
[web] analysis mode...
r134 @@task_grading_info = nil
jittat
[web] added configurations...
r76
def self.get(key)
jittat
removed caching on Configuration...
r146 if @@cache
if @@configurations == nil
self.read_config
end
return @@configurations[key]
else
return Configuration.read_one_key(key)
jittat
[web] added configurations...
r76 end
end
def self.[](key)
self.get(key)
end
def self.reload
self.read_config
end
def self.clear
@@configurations = nil
end
jittat
Merged online-registration branch changes r297:303 into the trunk...
r158 def self.enable_caching
@@cache = true
end
jittat
[web] added mode + access control, when sites started/finished...
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
jittat
[web] fix nil problem in various place, some styling...
r129 ((user.site.started!=true) or (user.site.finished?))
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
def self.show_tasks_to?(user)
mode = get(SYSTEM_MODE_CONF_KEY)
if (mode=='contest')
jittat
[web] fix nil problem in various place, some styling...
r129 return false if (user.site!=nil) and (user.site.started!=true)
jittat
[web] added mode + access control, when sites started/finished...
r122 end
return true
end
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128
jittat
[web] analysis mode...
r134 def self.show_grading_result
return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
end
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 def self.allow_test_request(user)
mode = get(SYSTEM_MODE_CONF_KEY)
if (mode=='contest')
jittat
[web] fix nil problem in various place, some styling...
r129 return false if (user.site!=nil) and ((user.site.started!=true) or (user.site.time_left < 30.minutes))
jittat
[web] test request stops at 30 min before end, auto refresh grader process status...
r128 end
return false if mode=='analysis'
return true
end
jittat
[web] analysis mode...
r134
def self.task_grading_info
if @@task_grading_info==nil
read_grading_info
end
return @@task_grading_info
end
jittat
[web] confirm when start contest, downloading task description through apache...
r130
jittat
[web] added configurations...
r76 protected
jittat
removed caching on Configuration...
r146
def self.convert_type(val,type)
case type
when 'string'
return val
when 'integer'
return val.to_i
when 'boolean'
return (val=='true')
end
end
jittat
[web] added configurations...
r76 def self.read_config
@@configurations = {}
Configuration.find(:all).each do |conf|
key = conf.key
val = conf.value
jittat
removed caching on Configuration...
r146 @@configurations[key] = Configuration.convert_type(val,conf.value_type)
end
end
jittat
[web] added configurations...
r76
jittat
removed caching on Configuration...
r146 def self.read_one_key(key)
conf = Configuration.find_by_key(key)
jittat
start working on e-mail registration...
r155 if conf
return Configuration.convert_type(conf.value,conf.value_type)
else
return nil
end
jittat
[web] added configurations...
r76 end
jittat
[web] analysis mode...
r134
def self.read_grading_info
f = File.open(TASK_GRADING_INFO_FILENAME)
@@task_grading_info = YAML.load(f)
f.close
end
jittat
[web] added configurations...
r76
end