Description:
fixed error in config index
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r316:fdc96046b715 - - 2 files changed: 5 inserted, 5 deleted

@@ -1,68 +1,72
1 require 'yaml'
1 require 'yaml'
2
2
3 #
3 #
4 # This class also contains various login of the system.
4 # This class also contains various login of the system.
5 #
5 #
6 class Configuration < ActiveRecord::Base
6 class Configuration < ActiveRecord::Base
7
7
8 SYSTEM_MODE_CONF_KEY = 'system.mode'
8 SYSTEM_MODE_CONF_KEY = 'system.mode'
9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
10 MULTICONTESTS_KEY = 'system.multicontests'
10 MULTICONTESTS_KEY = 'system.multicontests'
11 CONTEST_TIME_LIMIT_KEY = 'contest.time_limit'
11 CONTEST_TIME_LIMIT_KEY = 'contest.time_limit'
12
12
13 cattr_accessor :config_cache
13 cattr_accessor :config_cache
14 cattr_accessor :task_grading_info_cache
14 cattr_accessor :task_grading_info_cache
15 cattr_accessor :contest_time_str
15 cattr_accessor :contest_time_str
16 cattr_accessor :contest_time
16 cattr_accessor :contest_time
17
17
18 Configuration.config_cache = nil
18 Configuration.config_cache = nil
19 Configuration.task_grading_info_cache = nil
19 Configuration.task_grading_info_cache = nil
20
20
21 + def self.config_cached?
22 + (defined? CONFIGURATION_CACHE_ENABLED) and (CONFIGURATION_CACHE_ENABLED)
23 + end
24 +
21 def self.get(key)
25 def self.get(key)
22 if Configuration.config_cached?
26 if Configuration.config_cached?
23 if Configuration.config_cache == nil
27 if Configuration.config_cache == nil
24 self.read_config
28 self.read_config
25 end
29 end
26 return Configuration.config_cache[key]
30 return Configuration.config_cache[key]
27 else
31 else
28 return Configuration.read_one_key(key)
32 return Configuration.read_one_key(key)
29 end
33 end
30 end
34 end
31
35
32 def self.[](key)
36 def self.[](key)
33 self.get(key)
37 self.get(key)
34 end
38 end
35
39
36 def self.reload
40 def self.reload
37 self.read_config
41 self.read_config
38 end
42 end
39
43
40 def self.clear
44 def self.clear
41 Configuration.config_cache = nil
45 Configuration.config_cache = nil
42 end
46 end
43
47
44 #
48 #
45 # View decision
49 # View decision
46 #
50 #
47 def self.show_submitbox_to?(user)
51 def self.show_submitbox_to?(user)
48 mode = get(SYSTEM_MODE_CONF_KEY)
52 mode = get(SYSTEM_MODE_CONF_KEY)
49 return false if mode=='analysis'
53 return false if mode=='analysis'
50 if (mode=='contest')
54 if (mode=='contest')
51 return false if (user.site!=nil) and
55 return false if (user.site!=nil) and
52 ((user.site.started!=true) or (user.site.finished?))
56 ((user.site.started!=true) or (user.site.finished?))
53 end
57 end
54 return true
58 return true
55 end
59 end
56
60
57 def self.show_tasks_to?(user)
61 def self.show_tasks_to?(user)
58 if time_limit_mode?
62 if time_limit_mode?
59 return false if not user.contest_started?
63 return false if not user.contest_started?
60 end
64 end
61 return true
65 return true
62 end
66 end
63
67
64 def self.show_grading_result
68 def self.show_grading_result
65 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
69 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
66 end
70 end
67
71
68 def self.allow_test_request(user)
72 def self.allow_test_request(user)
@@ -87,90 +91,86
87 def self.standard_mode?
91 def self.standard_mode?
88 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
92 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
89 end
93 end
90
94
91 def self.contest_mode?
95 def self.contest_mode?
92 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
96 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
93 end
97 end
94
98
95 def self.indv_contest_mode?
99 def self.indv_contest_mode?
96 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
100 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
97 end
101 end
98
102
99 def self.multicontests?
103 def self.multicontests?
100 return get(MULTICONTESTS_KEY) == true
104 return get(MULTICONTESTS_KEY) == true
101 end
105 end
102
106
103 def self.time_limit_mode?
107 def self.time_limit_mode?
104 mode = get(SYSTEM_MODE_CONF_KEY)
108 mode = get(SYSTEM_MODE_CONF_KEY)
105 return ((mode == 'contest') or (mode == 'indv-contest'))
109 return ((mode == 'contest') or (mode == 'indv-contest'))
106 end
110 end
107
111
108 def self.analysis_mode?
112 def self.analysis_mode?
109 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
113 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
110 end
114 end
111
115
112 def self.contest_time_limit
116 def self.contest_time_limit
113 contest_time_str = Configuration[CONTEST_TIME_LIMIT_KEY]
117 contest_time_str = Configuration[CONTEST_TIME_LIMIT_KEY]
114
118
115 if not defined? Configuration.contest_time_str
119 if not defined? Configuration.contest_time_str
116 Configuration.contest_time_str = nil
120 Configuration.contest_time_str = nil
117 end
121 end
118
122
119 if Configuration.contest_time_str != contest_time_str
123 if Configuration.contest_time_str != contest_time_str
120 Configuration.contest_time_str = contest_time_str
124 Configuration.contest_time_str = contest_time_str
121 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
125 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
122 h = tmatch[1].to_i
126 h = tmatch[1].to_i
123 m = tmatch[2].to_i
127 m = tmatch[2].to_i
124
128
125 Configuration.contest_time = h.hour + m.minute
129 Configuration.contest_time = h.hour + m.minute
126 else
130 else
127 Configuration.contest_time = nil
131 Configuration.contest_time = nil
128 end
132 end
129 end
133 end
130 return Configuration.contest_time
134 return Configuration.contest_time
131 end
135 end
132
136
133 protected
137 protected
134
138
135 - def self.config_cached?
136 - (defined? CONFIGURATION_CACHE_ENABLED) and (CONFIGURATION_CACHE_ENABLED)
137 - end
138 -
139 def self.convert_type(val,type)
139 def self.convert_type(val,type)
140 case type
140 case type
141 when 'string'
141 when 'string'
142 return val
142 return val
143
143
144 when 'integer'
144 when 'integer'
145 return val.to_i
145 return val.to_i
146
146
147 when 'boolean'
147 when 'boolean'
148 return (val=='true')
148 return (val=='true')
149 end
149 end
150 end
150 end
151
151
152 def self.read_config
152 def self.read_config
153 Configuration.config_cache = {}
153 Configuration.config_cache = {}
154 Configuration.find(:all).each do |conf|
154 Configuration.find(:all).each do |conf|
155 key = conf.key
155 key = conf.key
156 val = conf.value
156 val = conf.value
157 Configuration.config_cache[key] = Configuration.convert_type(val,conf.value_type)
157 Configuration.config_cache[key] = Configuration.convert_type(val,conf.value_type)
158 end
158 end
159 end
159 end
160
160
161 def self.read_one_key(key)
161 def self.read_one_key(key)
162 conf = Configuration.find_by_key(key)
162 conf = Configuration.find_by_key(key)
163 if conf
163 if conf
164 return Configuration.convert_type(conf.value,conf.value_type)
164 return Configuration.convert_type(conf.value,conf.value_type)
165 else
165 else
166 return nil
166 return nil
167 end
167 end
168 end
168 end
169
169
170 def self.read_grading_info
170 def self.read_grading_info
171 f = File.open(TASK_GRADING_INFO_FILENAME)
171 f = File.open(TASK_GRADING_INFO_FILENAME)
172 Configuration.task_grading_info_cache = YAML.load(f)
172 Configuration.task_grading_info_cache = YAML.load(f)
173 f.close
173 f.close
174 end
174 end
175
175
176 end
176 end
@@ -1,32 +1,32
1 - content_for :head do
1 - content_for :head do
2 = javascript_include_tag :defaults
2 = javascript_include_tag :defaults
3
3
4 %h1 System configuration
4 %h1 System configuration
5
5
6 %table.info
6 %table.info
7 %tr.info-head
7 %tr.info-head
8 %th Key
8 %th Key
9 %th Type
9 %th Type
10 %th Value
10 %th Value
11 %th Description
11 %th Description
12 - @configurations.each do |conf|
12 - @configurations.each do |conf|
13 - @configuration = conf
13 - @configuration = conf
14 %tr{:class => cycle("info-odd", "info-even")}
14 %tr{:class => cycle("info-odd", "info-even")}
15 %td
15 %td
16 = in_place_editor_field :configuration, :key, {}, :rows=>1
16 = in_place_editor_field :configuration, :key, {}, :rows=>1
17 %td
17 %td
18 = in_place_editor_field :configuration, :value_type, {}, :rows=>1
18 = in_place_editor_field :configuration, :value_type, {}, :rows=>1
19 %td
19 %td
20 = in_place_editor_field :configuration, :value, {}, :rows=>1
20 = in_place_editor_field :configuration, :value, {}, :rows=>1
21 %td= conf.description
21 %td= conf.description
22
22
23 - - if Configuration.cache?
23 + - if Configuration.config_cached?
24 %br/
24 %br/
25 Your config is saved, but it does not automatically take effect.
25 Your config is saved, but it does not automatically take effect.
26 %br/
26 %br/
27 If you have one mongrel process running, you can
27 If you have one mongrel process running, you can
28 = link_to '[click]', :action => 'reload'
28 = link_to '[click]', :action => 'reload'
29 here to reload.
29 here to reload.
30 %br/
30 %br/
31 If you have more than one process running, you should restart
31 If you have more than one process running, you should restart
32 them manually.
32 them manually.
You need to be logged in to leave comments. Login now