Description:
shows contest start confirmation for indv contest
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r302:77a5c6e76df3 - - 4 files changed: 45 inserted, 4 deleted

@@ -0,0 +1,12
1 + = user_title_bar(@user)
2 +
3 + %center
4 + You will participate in contest:
5 + - @contests.each do |contest|
6 + = contest.title
7 + %br
8 +
9 + The timer will start after you click the start button.
10 +
11 + - form_tag :action => 'confirm_contest_start', :method => 'post' do
12 + = submit_tag 'Start!', :confirm => 'Are you sure?'
@@ -1,22 +1,26
1 1 class MainController < ApplicationController
2 2
3 3 before_filter :authenticate, :except => [:index, :login]
4 4 before_filter :check_viewability, :except => [:index, :login]
5 5
6 - append_before_filter :update_user_start_time, :except => [:index, :login]
6 + append_before_filter :confirm_and_update_start_time,
7 + :except => [:index,
8 + :login,
9 + :confirm_contest_start]
7 10
8 11 # to prevent log in box to be shown when user logged out of the
9 12 # system only in some tab
10 - prepend_before_filter :reject_announcement_refresh_when_logged_out, :only => [:announcements]
13 + prepend_before_filter :reject_announcement_refresh_when_logged_out,
14 + :only => [:announcements]
11 15
12 16 # COMMENTED OUT: filter in each action instead
13 17 # before_filter :verify_time_limit, :only => [:submit]
14 18
15 19 verify :method => :post, :only => [:submit],
16 20 :redirect_to => { :action => :index }
17 21
18 22 # COMMENT OUT: only need when having high load
19 23 # caches_action :index, :login
20 24
21 25 # NOTE: This method is not actually needed, 'config/routes.rb' has
22 26 # assigned action login as a default action.
@@ -174,24 +178,35
174 178
175 179 def announcements
176 180 if params.has_key? 'recent'
177 181 prepare_announcements(params[:recent])
178 182 else
179 183 prepare_announcements
180 184 end
181 185 render(:partial => 'announcement',
182 186 :collection => @announcements,
183 187 :locals => {:announcement_effect => true})
184 188 end
185 189
190 + def confirm_contest_start
191 + user = User.find(session[:user_id])
192 + if request.method == :post
193 + user.update_start_time
194 + redirect_to :action => 'list'
195 + else
196 + @contests = user.contests
197 + @user = user
198 + end
199 + end
200 +
186 201 protected
187 202
188 203 def prepare_announcements(recent=nil)
189 204 if Configuration.show_tasks_to?(@user)
190 205 @announcements = Announcement.find_published(true)
191 206 else
192 207 @announcements = Announcement.find_published
193 208 end
194 209 if recent!=nil
195 210 recent_id = recent.to_i
196 211 @announcements = @announcements.find_all { |a| a.id > recent_id }
197 212 end
@@ -325,26 +340,31
325 340 else
326 341 memory_used = -1
327 342 end
328 343
329 344 return {
330 345 :msg => "#{run_stat}\n#{time_stat}",
331 346 :running_time => seconds,
332 347 :exit_status => run_stat,
333 348 :memory_usage => memory_used
334 349 }
335 350 end
336 351
337 - def update_user_start_time
352 + def confirm_and_update_start_time
338 353 user = User.find(session[:user_id])
354 + if (Configuration.indv_contest_mode? and
355 + Configuration['contest.confirm_indv_contest_start'] and
356 + !user.contest_started?)
357 + redirect_to :action => 'confirm_contest_start' and return
358 + end
339 359 user.update_start_time
340 360 end
341 361
342 362 def reject_announcement_refresh_when_logged_out
343 363 if not session[:user_id]
344 364 render :text => 'Access forbidden', :status => 403
345 365 end
346 366
347 367 if Configuration.multicontests?
348 368 user = User.find(session[:user_id])
349 369 if user.contest_stat.forced_logout
350 370 render :text => 'Access forbidden', :status => 403
@@ -163,25 +163,28
163 163 if Configuration.contest_mode?
164 164 return false if site==nil
165 165 return site.finished?
166 166 elsif Configuration.indv_contest_mode?
167 167 return false if self.contest_stat(true)==nil
168 168 return contest_time_left == 0
169 169 else
170 170 return false
171 171 end
172 172 end
173 173
174 174 def contest_started?
175 - if Configuration.contest_mode?
175 + if Configuration.indv_contest_mode?
176 + stat = self.contest_stat
177 + return ((stat != nil) and (stat.started_at != nil))
178 + elsif Configuration.contest_mode?
176 179 return true if site==nil
177 180 return site.started
178 181 else
179 182 return true
180 183 end
181 184 end
182 185
183 186 def update_start_time
184 187 stat = self.contest_stat
185 188 if stat == nil or stat.started_at == nil
186 189 stat ||= UserContestStat.new(:user => self)
187 190 stat.started_at = Time.now.gmtime
@@ -92,24 +92,30
92 92 # the user will not be able to use test request at 30 minutes
93 93 # before the contest ends.
94 94 {
95 95 :key => 'contest.test_request.early_timeout',
96 96 :value_type => 'boolean',
97 97 :default_value => 'false'
98 98 },
99 99
100 100 {
101 101 :key => 'system.multicontests',
102 102 :value_type => 'boolean',
103 103 :default_value => 'false'
104 + },
105 +
106 + {
107 + :key => 'contest.confirm_indv_contest_start',
108 + :value_type => 'boolean',
109 + :default_value => 'false'
104 110 }
105 111 ]
106 112
107 113
108 114 def create_configuration_key(key,
109 115 value_type,
110 116 default_value,
111 117 description='')
112 118 conf = (Configuration.find_by_key(key) ||
113 119 Configuration.new(:key => key,
114 120 :value_type => value_type,
115 121 :value => default_value))
You need to be logged in to leave comments. Login now