Description:
manages problems in contests
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r279:973f76ab730e - - 10 files changed: 74 inserted, 3 deleted

@@ -0,0 +1,9
1 + class AddNameToContests < ActiveRecord::Migration
2 + def self.up
3 + add_column :contests, :name, :string
4 + end
5 +
6 + def self.down
7 + remove_column :contests, :name
8 + end
9 + end
@@ -133,24 +133,26
133 else
133 else
134 @submissions = Submission.find_all_last_by_problem(params[:id])
134 @submissions = Submission.find_all_last_by_problem(params[:id])
135 end
135 end
136 end
136 end
137
137
138 def manage
138 def manage
139 @problems = Problem.find(:all, :order => 'date_added DESC')
139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 end
140 end
141
141
142 def do_manage
142 def do_manage
143 if params.has_key? 'change_date_added'
143 if params.has_key? 'change_date_added'
144 change_date_added
144 change_date_added
145 + else params.has_key? 'add_to_contest'
146 + add_to_contest
145 end
147 end
146 redirect_to :action => 'manage'
148 redirect_to :action => 'manage'
147 end
149 end
148
150
149 def import
151 def import
150 @allow_test_pair_import = allow_test_pair_import?
152 @allow_test_pair_import = allow_test_pair_import?
151 end
153 end
152
154
153 def do_import
155 def do_import
154 old_problem = Problem.find_by_name(params[:name])
156 old_problem = Problem.find_by_name(params[:name])
155 if !allow_test_pair_import? and params.has_key? :import_to_db
157 if !allow_test_pair_import? and params.has_key? :import_to_db
156 params.delete :import_to_db
158 params.delete :import_to_db
@@ -159,47 +161,66
159 old_problem)
161 old_problem)
160
162
161 if @problem.errors.length != 0
163 if @problem.errors.length != 0
162 render :action => 'import' and return
164 render :action => 'import' and return
163 end
165 end
164
166
165 if old_problem!=nil
167 if old_problem!=nil
166 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
168 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
167 end
169 end
168 @log = import_log
170 @log = import_log
169 end
171 end
170
172
173 + def remove_contest
174 + problem = Problem.find(params[:id])
175 + contest = Contest.find(params[:contest_id])
176 + if problem!=nil and contest!=nil
177 + problem.contests.delete(contest)
178 + end
179 + redirect_to :action => 'manage'
180 + end
181 +
171 ##################################
182 ##################################
172 protected
183 protected
173
184
174 def allow_test_pair_import?
185 def allow_test_pair_import?
175 if defined? ALLOW_TEST_PAIR_IMPORT
186 if defined? ALLOW_TEST_PAIR_IMPORT
176 return ALLOW_TEST_PAIR_IMPORT
187 return ALLOW_TEST_PAIR_IMPORT
177 else
188 else
178 return false
189 return false
179 end
190 end
180 end
191 end
181
192
182 def change_date_added
193 def change_date_added
183 problems = get_problems_from_params
194 problems = get_problems_from_params
184 year = params[:date_added][:year].to_i
195 year = params[:date_added][:year].to_i
185 month = params[:date_added][:month].to_i
196 month = params[:date_added][:month].to_i
186 day = params[:date_added][:day].to_i
197 day = params[:date_added][:day].to_i
187 date = Date.new(year,month,day)
198 date = Date.new(year,month,day)
188 problems.each do |p|
199 problems.each do |p|
189 p.date_added = date
200 p.date_added = date
190 p.save
201 p.save
191 end
202 end
192 end
203 end
193
204
205 + def add_to_contest
206 + problems = get_problems_from_params
207 + contest = Contest.find(params[:contest][:id])
208 + if contest!=nil and contest.enabled
209 + problems.each do |p|
210 + p.contests << contest
211 + end
212 + end
213 + end
214 +
194 def get_problems_from_params
215 def get_problems_from_params
195 problems = []
216 problems = []
196 params.keys.each do |k|
217 params.keys.each do |k|
197 if k.index('prob-')==0
218 if k.index('prob-')==0
198 name, id = k.split('-')
219 name, id = k.split('-')
199 problems << Problem.find(id)
220 problems << Problem.find(id)
200 end
221 end
201 end
222 end
202 problems
223 problems
203 end
224 end
204
225
205 end
226 end
@@ -1,19 +1,23
1 <h1>Editing contest</h1>
1 <h1>Editing contest</h1>
2
2
3 <% form_for(@contest) do |f| %>
3 <% form_for(@contest) do |f| %>
4 <%= f.error_messages %>
4 <%= f.error_messages %>
5
5
6 <table>
6 <table>
7 <tr>
7 <tr>
8 + <td><%= f.label :name %></td>
9 + <td><%= f.text_field :name %></td>
10 + </tr>
11 + <tr>
8 <td><%= f.label :title %></td>
12 <td><%= f.label :title %></td>
9 <td><%= f.text_field :title %></td>
13 <td><%= f.text_field :title %></td>
10 </tr>
14 </tr>
11 <tr>
15 <tr>
12 <td></td>
16 <td></td>
13 <td>
17 <td>
14 <%= f.check_box :enabled %>
18 <%= f.check_box :enabled %>
15 <%= f.label :enabled %>
19 <%= f.label :enabled %>
16 </td>
20 </td>
17 </tr>
21 </tr>
18 </table>
22 </table>
19 <p>
23 <p>
@@ -1,31 +1,33
1 <% content_for :head do %>
1 <% content_for :head do %>
2 <%= javascript_include_tag :defaults %>
2 <%= javascript_include_tag :defaults %>
3 <% end %>
3 <% end %>
4
4
5 <h1>Listing contests</h1>
5 <h1>Listing contests</h1>
6
6
7 <div class="infobox">
7 <div class="infobox">
8 <b>Go back to:</b> [<%= link_to 'contest management', :controller => 'contest_management', :action => 'index' %>]
8 <b>Go back to:</b> [<%= link_to 'contest management', :controller => 'contest_management', :action => 'index' %>]
9 </div>
9 </div>
10
10
11 <table>
11 <table>
12 <tr>
12 <tr>
13 + <th>Name</th>
13 <th>Title</th>
14 <th>Title</th>
14 <th>Enabled</th>
15 <th>Enabled</th>
15 </tr>
16 </tr>
16
17
17 <% @contests.each do |contest| %>
18 <% @contests.each do |contest| %>
18 <% @contest = contest %>
19 <% @contest = contest %>
19 <tr>
20 <tr>
21 + <td><%= in_place_editor_field :contest, :name, {}, :rows => 1 %></td>
20 <td><%= in_place_editor_field :contest, :title, {}, :rows => 1 %></td>
22 <td><%= in_place_editor_field :contest, :title, {}, :rows => 1 %></td>
21 <td><%= in_place_editor_field :contest, :enabled, {}, :rows => 1 %></td>
23 <td><%= in_place_editor_field :contest, :enabled, {}, :rows => 1 %></td>
22 <td><%= link_to 'Show', contest %></td>
24 <td><%= link_to 'Show', contest %></td>
23 <td><%= link_to 'Edit', edit_contest_path(contest) %></td>
25 <td><%= link_to 'Edit', edit_contest_path(contest) %></td>
24 <td><%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %></td>
26 <td><%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %></td>
25 </tr>
27 </tr>
26 <% end %>
28 <% end %>
27 </table>
29 </table>
28
30
29 <br />
31 <br />
30
32
31 <%= link_to 'New contest', new_contest_path %>
33 <%= link_to 'New contest', new_contest_path %>
@@ -1,19 +1,23
1 <h1>New contest</h1>
1 <h1>New contest</h1>
2
2
3 <% form_for(@contest) do |f| %>
3 <% form_for(@contest) do |f| %>
4 <%= f.error_messages %>
4 <%= f.error_messages %>
5
5
6 <p>
6 <p>
7 + <%= f.label :name %><br />
8 + <%= f.text_field :name %>
9 + </p>
10 + <p>
7 <%= f.label :title %><br />
11 <%= f.label :title %><br />
8 <%= f.text_field :title %>
12 <%= f.text_field :title %>
9 </p>
13 </p>
10 <p>
14 <p>
11 <%= f.label :enabled %><br />
15 <%= f.label :enabled %><br />
12 <%= f.check_box :enabled %>
16 <%= f.check_box :enabled %>
13 </p>
17 </p>
14 <p>
18 <p>
15 <%= f.submit 'Create' %>
19 <%= f.submit 'Create' %>
16 </p>
20 </p>
17 <% end %>
21 <% end %>
18
22
19 - <%= link_to 'Back', contests_path %> No newline at end of file
23 + <%= link_to 'Back', contests_path %>
@@ -23,36 +23,45
23 <%= submit_tag "Create" %>
23 <%= submit_tag "Create" %>
24 <% end %>
24 <% end %>
25 </div>
25 </div>
26
26
27 <table>
27 <table>
28 <tr>
28 <tr>
29 <th>Name</th>
29 <th>Name</th>
30 <th>Full name</th>
30 <th>Full name</th>
31 <th>Full score</th>
31 <th>Full score</th>
32 <th>Date added</th>
32 <th>Date added</th>
33 <th>Avail?</th>
33 <th>Avail?</th>
34 <th>Test?</th>
34 <th>Test?</th>
35 + <% if Configuration.multicontests? %>
36 + <th>Contests</th>
37 + <% end %>
35 </tr>
38 </tr>
36
39
37 <% for problem in @problems %>
40 <% for problem in @problems %>
38 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
41 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
39 <% @problem=problem %>
42 <% @problem=problem %>
40 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
43 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
41 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
44 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
42 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
45 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
43 <td><%= problem.date_added %></td>
46 <td><%= problem.date_added %></td>
44 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
47 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
45 <td><%= problem.test_allowed %></td>
48 <td><%= problem.test_allowed %></td>
46
49
50 + <% if Configuration.multicontests? %>
51 + <td>
52 + <%= problem.contests.collect { |c| c.name }.join(', ') %>
53 + </td>
54 + <% end %>
55 +
47 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
56 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
48 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
57 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
49 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
58 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
50 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
59 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
51 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
60 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
52 </tr>
61 </tr>
53 <% end %>
62 <% end %>
54 </table>
63 </table>
55
64
56 <br />
65 <br />
57
66
58 <%= link_to '[New problem]', :action => 'new' %>
67 <%= link_to '[New problem]', :action => 'new' %>
@@ -7,26 +7,38
7 %p= link_to '[Back to problem list]', :action => 'list'
7 %p= link_to '[Back to problem list]', :action => 'list'
8
8
9 - form_tag :action=>'do_manage' do
9 - form_tag :action=>'do_manage' do
10 .submitbox
10 .submitbox
11 What do you want to do?
11 What do you want to do?
12 %br/
12 %br/
13 %ul
13 %ul
14 %li
14 %li
15 Change date added to
15 Change date added to
16 = select_date Date.current, :prefix => 'date_added'
16 = select_date Date.current, :prefix => 'date_added'
17 &nbsp;&nbsp;&nbsp;
17 &nbsp;&nbsp;&nbsp;
18 = submit_tag 'Change', :name => 'change_date_added'
18 = submit_tag 'Change', :name => 'change_date_added'
19 +
20 + - if Configuration.multicontests?
21 + %li
22 + Add to
23 + = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
24 + = submit_tag 'Add', :name => 'add_to_contest'
25 +
19 %table
26 %table
20 %tr
27 %tr
21 %th/
28 %th/
22 %th Name
29 %th Name
23 %th Full name
30 %th Full name
24 %th Date added
31 %th Date added
32 + - if Configuration.multicontests?
33 + %th Contests
25
34
26 - for problem in @problems
35 - for problem in @problems
27 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
36 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
28 %td= check_box_tag "prob-#{problem.id}"
37 %td= check_box_tag "prob-#{problem.id}"
29 %td= problem.name
38 %td= problem.name
30 %td= problem.full_name
39 %td= problem.full_name
31 %td= problem.date_added
40 %td= problem.date_added
32 -
41 + - if Configuration.multicontests?
42 + %td
43 + - problem.contests.each do |contest|
44 + = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
@@ -1,24 +1,24
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 => 20100219014840) do
12 + ActiveRecord::Schema.define(:version => 20100303095700) 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
@@ -27,24 +27,25
27 t.string "value_type"
27 t.string "value_type"
28 t.string "value"
28 t.string "value"
29 t.datetime "created_at"
29 t.datetime "created_at"
30 t.datetime "updated_at"
30 t.datetime "updated_at"
31 t.text "description"
31 t.text "description"
32 end
32 end
33
33
34 create_table "contests", :force => true do |t|
34 create_table "contests", :force => true do |t|
35 t.string "title"
35 t.string "title"
36 t.boolean "enabled"
36 t.boolean "enabled"
37 t.datetime "created_at"
37 t.datetime "created_at"
38 t.datetime "updated_at"
38 t.datetime "updated_at"
39 + t.string "name"
39 end
40 end
40
41
41 create_table "contests_problems", :id => false, :force => true do |t|
42 create_table "contests_problems", :id => false, :force => true do |t|
42 t.integer "contest_id"
43 t.integer "contest_id"
43 t.integer "problem_id"
44 t.integer "problem_id"
44 end
45 end
45
46
46 create_table "contests_users", :id => false, :force => true do |t|
47 create_table "contests_users", :id => false, :force => true do |t|
47 t.integer "contest_id"
48 t.integer "contest_id"
48 t.integer "user_id"
49 t.integer "user_id"
49 end
50 end
50
51
@@ -86,24 +86,30
86 :value_type => 'boolean',
86 :value_type => 'boolean',
87 :default_value => 'true',
87 :default_value => 'true',
88 :description => 'If this option is true, users can change their settings'
88 :description => 'If this option is true, users can change their settings'
89 },
89 },
90
90
91 # If Configuration['contest.test_request.early_timeout'] is true
91 # If Configuration['contest.test_request.early_timeout'] is true
92 # the user will not be able to use test request at 30 minutes
92 # the user will not be able to use test request at 30 minutes
93 # before the contest ends.
93 # before the contest ends.
94 {
94 {
95 :key => 'contest.test_request.early_timeout',
95 :key => 'contest.test_request.early_timeout',
96 :value_type => 'boolean',
96 :value_type => 'boolean',
97 :default_value => 'false'
97 :default_value => 'false'
98 + },
99 +
100 + {
101 + :key => 'system.multicontests',
102 + :value_type => 'boolean',
103 + :default_value => 'false'
98 }
104 }
99 ]
105 ]
100
106
101
107
102 def create_configuration_key(key,
108 def create_configuration_key(key,
103 value_type,
109 value_type,
104 default_value,
110 default_value,
105 description='')
111 description='')
106 conf = (Configuration.find_by_key(key) ||
112 conf = (Configuration.find_by_key(key) ||
107 Configuration.new(:key => key,
113 Configuration.new(:key => key,
108 :value_type => value_type,
114 :value_type => value_type,
109 :value => default_value))
115 :value => default_value))
@@ -1,13 +1,16
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
2
3 contest_a:
3 contest_a:
4 + name: contest_a
4 title: Contest A
5 title: Contest A
5 enabled: true
6 enabled: true
6
7
7 contest_b:
8 contest_b:
9 + name: contest_b
8 title: Contest B
10 title: Contest B
9 enabled: true
11 enabled: true
10
12
11 contest_c:
13 contest_c:
14 + name: contest_c
12 title: Contest C
15 title: Contest C
13 enabled: false
16 enabled: false
You need to be logged in to leave comments. Login now