Description:
added contest model
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r266:48430f9891a7 - - 23 files changed: 354 inserted, 62 deleted

@@ -0,0 +1,38
1 + class ContestManagementController < ApplicationController
2 +
3 + before_filter :admin_authorization
4 +
5 + def index
6 + end
7 +
8 + def user_stat
9 + if not Configuration.indv_contest_mode?
10 + redirect_to :action => 'index' and return
11 + end
12 +
13 + @users = User.find(:all)
14 + @start_times = {}
15 + UserContestStat.find(:all).each do |stat|
16 + @start_times[stat.user_id] = stat.started_at
17 + end
18 + end
19 +
20 + def clear_stat
21 + user = User.find(params[:id])
22 + if user.contest_stat!=nil
23 + user.contest_stat.destroy
24 + end
25 + redirect_to :action => 'user_stat'
26 + end
27 +
28 + def clear_all_stat
29 + if not Configuration.indv_contest_mode?
30 + redirect_to :action => 'index' and return
31 + end
32 +
33 + UserContestStat.delete_all()
34 + flash[:notice] = 'All start time statistic cleared.'
35 + redirect_to :action => 'index'
36 + end
37 +
38 + end
@@ -0,0 +1,2
1 + module ContestManagementHelper
2 + end
@@ -0,0 +1,2
1 + class Contest < ActiveRecord::Base
2 + end
@@ -0,0 +1,4
1 + .submitbox
2 + %b Menu:
3 + = link_to '[View user start time]', :action => 'user_stat'
4 + = link_to '[Clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
@@ -0,0 +1,21
1 + %h1 Contest management
2 +
3 + .submitbox
4 +
5 + %b Multiple contests:
6 + = "There are #{Contest.count} contests running."
7 + = "[#{link_to 'Create/Update/Delete contests', :controller => 'contests', :action => 'index'}]"
8 +
9 +
10 + %b Contest mode:
11 +
12 + - if (not Configuration.contest_mode?) and (not Configuration.indv_contest_mode?)
13 + Currently the system is not running in contest mode.
14 + - elsif Configuration.contest_mode?
15 + System running in normal contest mode.
16 + - else
17 + System running in individual contest mode.
18 + = render :partial => 'indv_contest_mode_index'
19 +
20 + %br/
21 +
@@ -0,0 +1,24
1 + %h1 Individual Contest: User start time
2 +
3 + If you want to restart contest, you may want to
4 + %b
5 + = link_to '[clear all start times]', {:action => 'clear_all_stat'}, {:confirm => 'Do you really want to clear all start time statistics?'}
6 + so that users can participate again.
7 +
8 + %table.info
9 + %tr.info-head
10 + %th Login
11 + %th Start time
12 + %th Time left
13 + %th
14 + - @users.each_with_index do |user,i|
15 + %tr{:class => 'info-' + cycle('even','odd')}
16 + %td= user.login
17 + %td
18 + - if @start_times.has_key? user.id
19 + = @start_times[user.id]
20 + - else
21 + n/a
22 + %td= format_short_duration(user.contest_time_left)
23 + %td
24 + = link_to '[reset]', {:action => 'clear_stat', :id => user.id}, :confirm => 'Are you sure?'
@@ -0,0 +1,20
1 + <h1>Editing contest</h1>
2 +
3 + <% form_for(@contest) do |f| %>
4 + <%= f.error_messages %>
5 +
6 + <p>
7 + <%= f.label :title %><br />
8 + <%= f.text_field :title %>
9 + </p>
10 + <p>
11 + <%= f.label :enabled %><br />
12 + <%= f.check_box :enabled %>
13 + </p>
14 + <p>
15 + <%= f.submit 'Update' %>
16 + </p>
17 + <% end %>
18 +
19 + <%= link_to 'Show', @contest %> |
20 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,26
1 + <h1>Listing contests</h1>
2 +
3 + <div class="submitbox">
4 + <b>Go back</b> to [<%= link_to 'contest management', :controller => 'contest_management', :action => 'index' %>]
5 + </div>
6 +
7 + <table>
8 + <tr>
9 + <th>Title</th>
10 + <th>Enabled</th>
11 + </tr>
12 +
13 + <% @contests.each do |contest| %>
14 + <tr>
15 + <td><%=h contest.title %></td>
16 + <td><%=h contest.enabled %></td>
17 + <td><%= link_to 'Show', contest %></td>
18 + <td><%= link_to 'Edit', edit_contest_path(contest) %></td>
19 + <td><%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %></td>
20 + </tr>
21 + <% end %>
22 + </table>
23 +
24 + <br />
25 +
26 + <%= link_to 'New contest', new_contest_path %>
@@ -0,0 +1,19
1 + <h1>New contest</h1>
2 +
3 + <% form_for(@contest) do |f| %>
4 + <%= f.error_messages %>
5 +
6 + <p>
7 + <%= f.label :title %><br />
8 + <%= f.text_field :title %>
9 + </p>
10 + <p>
11 + <%= f.label :enabled %><br />
12 + <%= f.check_box :enabled %>
13 + </p>
14 + <p>
15 + <%= f.submit 'Create' %>
16 + </p>
17 + <% end %>
18 +
19 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,13
1 + <p>
2 + <b>Title:</b>
3 + <%=h @contest.title %>
4 + </p>
5 +
6 + <p>
7 + <b>Enabled:</b>
8 + <%=h @contest.enabled %>
9 + </p>
10 +
11 +
12 + <%= link_to 'Edit', edit_contest_path(@contest) %> |
13 + <%= link_to 'Back', contests_path %> No newline at end of file
@@ -0,0 +1,14
1 + class CreateContests < ActiveRecord::Migration
2 + def self.up
3 + create_table :contests do |t|
4 + t.string :title
5 + t.boolean :enabled
6 +
7 + t.timestamps
8 + end
9 + end
10 +
11 + def self.down
12 + drop_table :contests
13 + end
14 + end
@@ -0,0 +1,9
1 + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 +
3 + one:
4 + title: MyString
5 + enabled: false
6 +
7 + two:
8 + title: MyString
9 + enabled: false
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class ContestManagementControllerTest < ActionController::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -0,0 +1,8
1 + require 'test_helper'
2 +
3 + class ContestTest < ActiveSupport::TestCase
4 + # Replace this with your real tests.
5 + test "the truth" do
6 + assert true
7 + end
8 + end
@@ -0,0 +1,4
1 + require 'test_helper'
2 +
3 + class ContestManagementHelperTest < ActionView::TestCase
4 + end
@@ -1,38 +1,89
1 class ContestsController < ApplicationController
1 class ContestsController < ApplicationController
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 + # GET /contests
6 + # GET /contests.xml
5 def index
7 def index
8 + @contests = Contest.all
9 +
10 + respond_to do |format|
11 + format.html # index.html.erb
12 + format.xml { render :xml => @contests }
13 + end
6 end
14 end
7
15
8 - def user_stat
16 + # GET /contests/1
9 - if not Configuration.indv_contest_mode?
17 + # GET /contests/1.xml
10 - redirect_to :action => 'index' and return
18 + def show
19 + @contest = Contest.find(params[:id])
20 +
21 + respond_to do |format|
22 + format.html # show.html.erb
23 + format.xml { render :xml => @contest }
24 + end
11 end
25 end
12
26
13 - @users = User.find(:all)
27 + # GET /contests/new
14 - @start_times = {}
28 + # GET /contests/new.xml
15 - UserContestStat.find(:all).each do |stat|
29 + def new
16 - @start_times[stat.user_id] = stat.started_at
30 + @contest = Contest.new
31 +
32 + respond_to do |format|
33 + format.html # new.html.erb
34 + format.xml { render :xml => @contest }
17 end
35 end
18 end
36 end
19
37
20 - def clear_stat
38 + # GET /contests/1/edit
21 - user = User.find(params[:id])
39 + def edit
22 - if user.contest_stat!=nil
40 + @contest = Contest.find(params[:id])
23 - user.contest_stat.destroy
24 end
41 end
25 - redirect_to :action => 'user_stat'
42 +
43 + # POST /contests
44 + # POST /contests.xml
45 + def create
46 + @contest = Contest.new(params[:contest])
47 +
48 + respond_to do |format|
49 + if @contest.save
50 + flash[:notice] = 'Contest was successfully created.'
51 + format.html { redirect_to(@contest) }
52 + format.xml { render :xml => @contest, :status => :created, :location => @contest }
53 + else
54 + format.html { render :action => "new" }
55 + format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
56 + end
57 + end
26 end
58 end
27
59
28 - def clear_all_stat
60 + # PUT /contests/1
29 - if not Configuration.indv_contest_mode?
61 + # PUT /contests/1.xml
30 - redirect_to :action => 'index' and return
62 + def update
63 + @contest = Contest.find(params[:id])
64 +
65 + respond_to do |format|
66 + if @contest.update_attributes(params[:contest])
67 + flash[:notice] = 'Contest was successfully updated.'
68 + format.html { redirect_to(@contest) }
69 + format.xml { head :ok }
70 + else
71 + format.html { render :action => "edit" }
72 + format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
73 + end
74 + end
31 end
75 end
32
76
33 - UserContestStat.delete_all()
77 + # DELETE /contests/1
34 - flash[:notice] = 'All start time statistic cleared.'
78 + # DELETE /contests/1.xml
35 - redirect_to :action => 'index'
79 + def destroy
80 + @contest = Contest.find(params[:id])
81 + @contest.destroy
82 +
83 + respond_to do |format|
84 + format.html { redirect_to(contests_url) }
85 + format.xml { head :ok }
86 + end
36 end
87 end
37
88
38 end
89 end
@@ -5,25 +5,25
5 menu_items = ''
5 menu_items = ''
6 user = User.find(session[:user_id])
6 user = User.find(session[:user_id])
7
7
8 if (user!=nil) and (session[:admin])
8 if (user!=nil) and (session[:admin])
9 # admin menu
9 # admin menu
10 menu_items << "<b>Administrative task:</b> "
10 menu_items << "<b>Administrative task:</b> "
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
13 append_to menu_items, '[Problems]', 'problems', 'index'
13 append_to menu_items, '[Problems]', 'problems', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
16 append_to menu_items, '[Graders]', 'graders', 'list'
16 append_to menu_items, '[Graders]', 'graders', 'list'
17 - append_to menu_items, '[Contests]', 'contests', 'index'
17 + append_to menu_items, '[Contests]', 'contest_management', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
20 menu_items << "<br/>"
20 menu_items << "<br/>"
21 end
21 end
22
22
23 # main page
23 # main page
24 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
24 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
26
26
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
27 if (user!=nil) and (Configuration.show_tasks_to?(user))
28 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
28 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
29 append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
29 append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
@@ -1,13 +1,15
1 ActionController::Routing::Routes.draw do |map|
1 ActionController::Routing::Routes.draw do |map|
2 + map.resources :contests
3 +
2 map.resources :announcements
4 map.resources :announcements
3 map.resources :sites
5 map.resources :sites
4
6
5 # The priority is based upon order of creation: first created -> highest priority.
7 # The priority is based upon order of creation: first created -> highest priority.
6
8
7 # Sample of regular route:
9 # Sample of regular route:
8 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
10 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
9 # Keep in mind you can assign values other than :controller and :action
11 # Keep in mind you can assign values other than :controller and :action
10
12
11 # Sample of named route:
13 # Sample of named route:
12 # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
14 # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
13 # This route can be invoked with purchase_url(:id => product.id)
15 # This route can be invoked with purchase_url(:id => product.id)
@@ -1,45 +1,60
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 # please use the migrations feature of Active Record to incrementally modify your database, and
2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 # then regenerate this schema definition.
3 # then regenerate this schema definition.
4 #
4 #
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 # to create the application database on another system, you should be using db:schema:load, not running
6 # to create the application database on another system, you should be using db:schema:load, not running
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 #
9 #
10 # It's strongly recommended to check this file into your version control system.
10 # It's strongly recommended to check this file into your version control system.
11
11
12 - ActiveRecord::Schema.define(:version => 20100124054458) do
12 + ActiveRecord::Schema.define(:version => 20100216105730) do
13
13
14 create_table "announcements", :force => true do |t|
14 create_table "announcements", :force => true do |t|
15 t.string "author"
15 t.string "author"
16 t.text "body"
16 t.text "body"
17 t.boolean "published"
17 t.boolean "published"
18 t.datetime "created_at"
18 t.datetime "created_at"
19 t.datetime "updated_at"
19 t.datetime "updated_at"
20 t.boolean "frontpage", :default => false
20 t.boolean "frontpage", :default => false
21 t.boolean "contest_only", :default => false
21 t.boolean "contest_only", :default => false
22 t.string "title"
22 t.string "title"
23 end
23 end
24
24
25 + create_table "codejom_statuses", :force => true do |t|
26 + t.integer "user_id"
27 + t.boolean "alive"
28 + t.integer "num_problems_passed"
29 + t.datetime "created_at"
30 + t.datetime "updated_at"
31 + end
32 +
25 create_table "configurations", :force => true do |t|
33 create_table "configurations", :force => true do |t|
26 t.string "key"
34 t.string "key"
27 t.string "value_type"
35 t.string "value_type"
28 t.string "value"
36 t.string "value"
29 t.datetime "created_at"
37 t.datetime "created_at"
30 t.datetime "updated_at"
38 t.datetime "updated_at"
31 t.text "description"
39 t.text "description"
32 end
40 end
33
41
42 + create_table "contests", :force => true do |t|
43 + t.string "title"
44 + t.boolean "enabled"
45 + t.datetime "created_at"
46 + t.datetime "updated_at"
47 + end
48 +
34 create_table "countries", :force => true do |t|
49 create_table "countries", :force => true do |t|
35 t.string "name"
50 t.string "name"
36 t.datetime "created_at"
51 t.datetime "created_at"
37 t.datetime "updated_at"
52 t.datetime "updated_at"
38 end
53 end
39
54
40 create_table "descriptions", :force => true do |t|
55 create_table "descriptions", :force => true do |t|
41 t.text "body"
56 t.text "body"
42 t.boolean "markdowned"
57 t.boolean "markdowned"
43 t.datetime "created_at"
58 t.datetime "created_at"
44 t.datetime "updated_at"
59 t.datetime "updated_at"
45 end
60 end
@@ -76,24 +91,26
76 end
91 end
77
92
78 create_table "problems", :force => true do |t|
93 create_table "problems", :force => true do |t|
79 t.string "name", :limit => 30
94 t.string "name", :limit => 30
80 t.string "full_name"
95 t.string "full_name"
81 t.integer "full_score"
96 t.integer "full_score"
82 t.date "date_added"
97 t.date "date_added"
83 t.boolean "available"
98 t.boolean "available"
84 t.string "url"
99 t.string "url"
85 t.integer "description_id"
100 t.integer "description_id"
86 t.boolean "test_allowed"
101 t.boolean "test_allowed"
87 t.boolean "output_only"
102 t.boolean "output_only"
103 + t.integer "level", :default => 0
104 + t.datetime "updated_at"
88 end
105 end
89
106
90 create_table "rights", :force => true do |t|
107 create_table "rights", :force => true do |t|
91 t.string "name"
108 t.string "name"
92 t.string "controller"
109 t.string "controller"
93 t.string "action"
110 t.string "action"
94 end
111 end
95
112
96 create_table "rights_roles", :id => false, :force => true do |t|
113 create_table "rights_roles", :id => false, :force => true do |t|
97 t.integer "right_id"
114 t.integer "right_id"
98 t.integer "role_id"
115 t.integer "role_id"
99 end
116 end
@@ -169,26 +186,26
169 t.integer "user_id"
186 t.integer "user_id"
170 t.integer "problem_id"
187 t.integer "problem_id"
171 t.integer "test_pair_id"
188 t.integer "test_pair_id"
172 t.integer "test_pair_number"
189 t.integer "test_pair_number"
173 t.integer "request_number"
190 t.integer "request_number"
174 t.datetime "created_at"
191 t.datetime "created_at"
175 t.datetime "updated_at"
192 t.datetime "updated_at"
176 t.boolean "submitted"
193 t.boolean "submitted"
177 end
194 end
178
195
179 create_table "test_pairs", :force => true do |t|
196 create_table "test_pairs", :force => true do |t|
180 t.integer "problem_id"
197 t.integer "problem_id"
181 - t.text "input"
198 + t.text "input", :limit => 16777215
182 - t.text "solution"
199 + t.text "solution", :limit => 16777215
183 t.datetime "created_at"
200 t.datetime "created_at"
184 t.datetime "updated_at"
201 t.datetime "updated_at"
185 t.integer "number"
202 t.integer "number"
186 end
203 end
187
204
188 create_table "test_requests", :force => true do |t|
205 create_table "test_requests", :force => true do |t|
189 t.integer "user_id"
206 t.integer "user_id"
190 t.integer "problem_id"
207 t.integer "problem_id"
191 t.integer "submission_id"
208 t.integer "submission_id"
192 t.string "input_file_name"
209 t.string "input_file_name"
193 t.string "output_file_name"
210 t.string "output_file_name"
194 t.string "running_stat"
211 t.string "running_stat"
@@ -217,17 +234,27
217 create_table "users", :force => true do |t|
234 create_table "users", :force => true do |t|
218 t.string "login", :limit => 50
235 t.string "login", :limit => 50
219 t.string "full_name"
236 t.string "full_name"
220 t.string "hashed_password"
237 t.string "hashed_password"
221 t.string "salt", :limit => 5
238 t.string "salt", :limit => 5
222 t.string "alias"
239 t.string "alias"
223 t.string "email"
240 t.string "email"
224 t.integer "site_id"
241 t.integer "site_id"
225 t.integer "country_id"
242 t.integer "country_id"
226 t.boolean "activated", :default => false
243 t.boolean "activated", :default => false
227 t.datetime "created_at"
244 t.datetime "created_at"
228 t.datetime "updated_at"
245 t.datetime "updated_at"
246 + t.string "member1_full_name"
247 + t.string "member2_full_name"
248 + t.string "member3_full_name"
249 + t.boolean "high_school"
250 + t.string "member1_school_name"
251 + t.string "member2_school_name"
252 + t.string "member3_school_name"
253 + t.string "school_name"
254 + t.string "province"
255 + t.integer "year"
229 end
256 end
230
257
231 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
258 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
232
259
233 end
260 end
@@ -1,8 +1,45
1 require 'test_helper'
1 require 'test_helper'
2
2
3 class ContestsControllerTest < ActionController::TestCase
3 class ContestsControllerTest < ActionController::TestCase
4 - # Replace this with your real tests.
4 + test "should get index" do
5 - test "the truth" do
5 + get :index
6 - assert true
6 + assert_response :success
7 + assert_not_nil assigns(:contests)
8 + end
9 +
10 + test "should get new" do
11 + get :new
12 + assert_response :success
13 + end
14 +
15 + test "should create contest" do
16 + assert_difference('Contest.count') do
17 + post :create, :contest => { }
18 + end
19 +
20 + assert_redirected_to contest_path(assigns(:contest))
21 + end
22 +
23 + test "should show contest" do
24 + get :show, :id => contests(:one).to_param
25 + assert_response :success
26 + end
27 +
28 + test "should get edit" do
29 + get :edit, :id => contests(:one).to_param
30 + assert_response :success
31 + end
32 +
33 + test "should update contest" do
34 + put :update, :id => contests(:one).to_param, :contest => { }
35 + assert_redirected_to contest_path(assigns(:contest))
36 + end
37 +
38 + test "should destroy contest" do
39 + assert_difference('Contest.count', -1) do
40 + delete :destroy, :id => contests(:one).to_param
41 + end
42 +
43 + assert_redirected_to contests_path
7 end
44 end
8 end
45 end
deleted file
deleted file
deleted file
You need to be logged in to leave comments. Login now