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
@@ -1,205 +1,226
1 1 class ProblemsController < ApplicationController
2 2
3 3 before_filter :authenticate, :authorization
4 4
5 5 in_place_edit_for :problem, :name
6 6 in_place_edit_for :problem, :full_name
7 7 in_place_edit_for :problem, :full_score
8 8
9 9 def index
10 10 list
11 11 render :action => 'list'
12 12 end
13 13
14 14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 15 verify :method => :post, :only => [ :destroy,
16 16 :create, :quick_create,
17 17 :do_manage,
18 18 :do_import,
19 19 :update ],
20 20 :redirect_to => { :action => :list }
21 21
22 22 def list
23 23 @problems = Problem.find(:all, :order => 'date_added DESC')
24 24 end
25 25
26 26 def show
27 27 @problem = Problem.find(params[:id])
28 28 end
29 29
30 30 def new
31 31 @problem = Problem.new
32 32 @description = nil
33 33 end
34 34
35 35 def create
36 36 @problem = Problem.new(params[:problem])
37 37 @description = Description.new(params[:description])
38 38 if @description.body!=''
39 39 if !@description.save
40 40 render :action => new and return
41 41 end
42 42 else
43 43 @description = nil
44 44 end
45 45 @problem.description = @description
46 46 if @problem.save
47 47 flash[:notice] = 'Problem was successfully created.'
48 48 redirect_to :action => 'list'
49 49 else
50 50 render :action => 'new'
51 51 end
52 52 end
53 53
54 54 def quick_create
55 55 @problem = Problem.new(params[:problem])
56 56 @problem.full_name = @problem.name if @problem.full_name == ''
57 57 @problem.full_score = 100
58 58 @problem.available = false
59 59 @problem.test_allowed = true
60 60 @problem.output_only = false
61 61 @problem.date_added = Time.new
62 62 if @problem.save
63 63 flash[:notice] = 'Problem was successfully created.'
64 64 redirect_to :action => 'list'
65 65 else
66 66 flash[:notice] = 'Error saving problem'
67 67 redirect_to :action => 'list'
68 68 end
69 69 end
70 70
71 71 def edit
72 72 @problem = Problem.find(params[:id])
73 73 @description = @problem.description
74 74 end
75 75
76 76 def update
77 77 @problem = Problem.find(params[:id])
78 78 @description = @problem.description
79 79 if @description == nil and params[:description][:body]!=''
80 80 @description = Description.new(params[:description])
81 81 if !@description.save
82 82 flash[:notice] = 'Error saving description'
83 83 render :action => 'edit' and return
84 84 end
85 85 @problem.description = @description
86 86 elsif @description!=nil
87 87 if !@description.update_attributes(params[:description])
88 88 flash[:notice] = 'Error saving description'
89 89 render :action => 'edit' and return
90 90 end
91 91 end
92 92 if @problem.update_attributes(params[:problem])
93 93 flash[:notice] = 'Problem was successfully updated.'
94 94 redirect_to :action => 'show', :id => @problem
95 95 else
96 96 render :action => 'edit'
97 97 end
98 98 end
99 99
100 100 def destroy
101 101 Problem.find(params[:id]).destroy
102 102 redirect_to :action => 'list'
103 103 end
104 104
105 105 def toggle
106 106 @problem = Problem.find(params[:id])
107 107 @problem.available = !(@problem.available)
108 108 @problem.save
109 109 end
110 110
111 111 def turn_all_off
112 112 Problem.find(:all,
113 113 :conditions => "available = 1").each do |problem|
114 114 problem.available = false
115 115 problem.save
116 116 end
117 117 redirect_to :action => 'list'
118 118 end
119 119
120 120 def turn_all_on
121 121 Problem.find(:all,
122 122 :conditions => "available = 0").each do |problem|
123 123 problem.available = true
124 124 problem.save
125 125 end
126 126 redirect_to :action => 'list'
127 127 end
128 128
129 129 def stat
130 130 @problem = Problem.find(params[:id])
131 131 if !@problem.available
132 132 redirect_to :controller => 'main', :action => 'list'
133 133 else
134 134 @submissions = Submission.find_all_last_by_problem(params[:id])
135 135 end
136 136 end
137 137
138 138 def manage
139 139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 140 end
141 141
142 142 def do_manage
143 143 if params.has_key? 'change_date_added'
144 144 change_date_added
145 + else params.has_key? 'add_to_contest'
146 + add_to_contest
145 147 end
146 148 redirect_to :action => 'manage'
147 149 end
148 150
149 151 def import
150 152 @allow_test_pair_import = allow_test_pair_import?
151 153 end
152 154
153 155 def do_import
154 156 old_problem = Problem.find_by_name(params[:name])
155 157 if !allow_test_pair_import? and params.has_key? :import_to_db
156 158 params.delete :import_to_db
157 159 end
158 160 @problem, import_log = Problem.create_from_import_form_params(params,
159 161 old_problem)
160 162
161 163 if @problem.errors.length != 0
162 164 render :action => 'import' and return
163 165 end
164 166
165 167 if old_problem!=nil
166 168 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
167 169 end
168 170 @log = import_log
169 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 183 protected
173 184
174 185 def allow_test_pair_import?
175 186 if defined? ALLOW_TEST_PAIR_IMPORT
176 187 return ALLOW_TEST_PAIR_IMPORT
177 188 else
178 189 return false
179 190 end
180 191 end
181 192
182 193 def change_date_added
183 194 problems = get_problems_from_params
184 195 year = params[:date_added][:year].to_i
185 196 month = params[:date_added][:month].to_i
186 197 day = params[:date_added][:day].to_i
187 198 date = Date.new(year,month,day)
188 199 problems.each do |p|
189 200 p.date_added = date
190 201 p.save
191 202 end
192 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 215 def get_problems_from_params
195 216 problems = []
196 217 params.keys.each do |k|
197 218 if k.index('prob-')==0
198 219 name, id = k.split('-')
199 220 problems << Problem.find(id)
200 221 end
201 222 end
202 223 problems
203 224 end
204 225
205 226 end
@@ -1,25 +1,29
1 1 <h1>Editing contest</h1>
2 2
3 3 <% form_for(@contest) do |f| %>
4 4 <%= f.error_messages %>
5 5
6 6 <table>
7 7 <tr>
8 + <td><%= f.label :name %></td>
9 + <td><%= f.text_field :name %></td>
10 + </tr>
11 + <tr>
8 12 <td><%= f.label :title %></td>
9 13 <td><%= f.text_field :title %></td>
10 14 </tr>
11 15 <tr>
12 16 <td></td>
13 17 <td>
14 18 <%= f.check_box :enabled %>
15 19 <%= f.label :enabled %>
16 20 </td>
17 21 </tr>
18 22 </table>
19 23 <p>
20 24 <%= f.submit 'Update' %>
21 25 </p>
22 26 <% end %>
23 27
24 28 <%= link_to 'Show', @contest %> |
25 29 <%= link_to 'Back', contests_path %>
@@ -1,31 +1,33
1 1 <% content_for :head do %>
2 2 <%= javascript_include_tag :defaults %>
3 3 <% end %>
4 4
5 5 <h1>Listing contests</h1>
6 6
7 7 <div class="infobox">
8 8 <b>Go back to:</b> [<%= link_to 'contest management', :controller => 'contest_management', :action => 'index' %>]
9 9 </div>
10 10
11 11 <table>
12 12 <tr>
13 + <th>Name</th>
13 14 <th>Title</th>
14 15 <th>Enabled</th>
15 16 </tr>
16 17
17 18 <% @contests.each do |contest| %>
18 19 <% @contest = contest %>
19 20 <tr>
21 + <td><%= in_place_editor_field :contest, :name, {}, :rows => 1 %></td>
20 22 <td><%= in_place_editor_field :contest, :title, {}, :rows => 1 %></td>
21 23 <td><%= in_place_editor_field :contest, :enabled, {}, :rows => 1 %></td>
22 24 <td><%= link_to 'Show', contest %></td>
23 25 <td><%= link_to 'Edit', edit_contest_path(contest) %></td>
24 26 <td><%= link_to 'Destroy', contest, :confirm => 'Are you sure?', :method => :delete %></td>
25 27 </tr>
26 28 <% end %>
27 29 </table>
28 30
29 31 <br />
30 32
31 33 <%= link_to 'New contest', new_contest_path %>
@@ -1,19 +1,23
1 1 <h1>New contest</h1>
2 2
3 3 <% form_for(@contest) do |f| %>
4 4 <%= f.error_messages %>
5 5
6 6 <p>
7 + <%= f.label :name %><br />
8 + <%= f.text_field :name %>
9 + </p>
10 + <p>
7 11 <%= f.label :title %><br />
8 12 <%= f.text_field :title %>
9 13 </p>
10 14 <p>
11 15 <%= f.label :enabled %><br />
12 16 <%= f.check_box :enabled %>
13 17 </p>
14 18 <p>
15 19 <%= f.submit 'Create' %>
16 20 </p>
17 21 <% end %>
18 22
19 - <%= link_to 'Back', contests_path %> No newline at end of file
23 + <%= link_to 'Back', contests_path %>
@@ -1,58 +1,67
1 1 <% content_for :head do %>
2 2 <%= stylesheet_link_tag 'problems' %>
3 3 <%= javascript_include_tag :defaults %>
4 4 <% end %>
5 5
6 6 <h1>Listing problems</h1>
7 7
8 8 <p>
9 9 <%= link_to '[New problem]', :action => 'new' %>
10 10 <%= link_to '[Manage problems]', :action => 'manage' %>
11 11 <%= link_to '[Import problems]', :action => 'import' %>
12 12 <%= link_to '[Turn off all problems]', :action => 'turn_all_off' %>
13 13 <%= link_to '[Turn on all problems]', :action => 'turn_all_on' %>
14 14 </p>
15 15
16 16 <div class="submitbox">
17 17 <% form_tag :action => 'quick_create' do %>
18 18 <b>Quick New:</b>
19 19 <label for="problem_name">Name</label>
20 20 <%= text_field 'problem', 'name' %> |
21 21 <label for="problem_full_name">Full name</label>
22 22 <%= text_field 'problem', 'full_name' %>
23 23 <%= submit_tag "Create" %>
24 24 <% end %>
25 25 </div>
26 26
27 27 <table>
28 28 <tr>
29 29 <th>Name</th>
30 30 <th>Full name</th>
31 31 <th>Full score</th>
32 32 <th>Date added</th>
33 33 <th>Avail?</th>
34 34 <th>Test?</th>
35 + <% if Configuration.multicontests? %>
36 + <th>Contests</th>
37 + <% end %>
35 38 </tr>
36 39
37 40 <% for problem in @problems %>
38 41 <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>">
39 42 <% @problem=problem %>
40 43 <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
41 44 <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
42 45 <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
43 46 <td><%= problem.date_added %></td>
44 47 <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td>
45 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 56 <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td>
48 57 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
49 58 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
50 59 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
51 60 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
52 61 </tr>
53 62 <% end %>
54 63 </table>
55 64
56 65 <br />
57 66
58 67 <%= link_to '[New problem]', :action => 'new' %>
@@ -1,32 +1,44
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'problems'
3 3 = javascript_include_tag :defaults
4 4
5 5 %h1 Manage problems
6 6
7 7 %p= link_to '[Back to problem list]', :action => 'list'
8 8
9 9 - form_tag :action=>'do_manage' do
10 10 .submitbox
11 11 What do you want to do?
12 12 %br/
13 13 %ul
14 14 %li
15 15 Change date added to
16 16 = select_date Date.current, :prefix => 'date_added'
17 17 &nbsp;&nbsp;&nbsp;
18 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 26 %table
20 27 %tr
21 28 %th/
22 29 %th Name
23 30 %th Full name
24 31 %th Date added
32 + - if Configuration.multicontests?
33 + %th Contests
25 34
26 35 - for problem in @problems
27 36 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
28 37 %td= check_box_tag "prob-#{problem.id}"
29 38 %td= problem.name
30 39 %td= problem.full_name
31 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,230 +1,231
1 1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 3 # then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 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 14 create_table "announcements", :force => true do |t|
15 15 t.string "author"
16 16 t.text "body"
17 17 t.boolean "published"
18 18 t.datetime "created_at"
19 19 t.datetime "updated_at"
20 20 t.boolean "frontpage", :default => false
21 21 t.boolean "contest_only", :default => false
22 22 t.string "title"
23 23 end
24 24
25 25 create_table "configurations", :force => true do |t|
26 26 t.string "key"
27 27 t.string "value_type"
28 28 t.string "value"
29 29 t.datetime "created_at"
30 30 t.datetime "updated_at"
31 31 t.text "description"
32 32 end
33 33
34 34 create_table "contests", :force => true do |t|
35 35 t.string "title"
36 36 t.boolean "enabled"
37 37 t.datetime "created_at"
38 38 t.datetime "updated_at"
39 + t.string "name"
39 40 end
40 41
41 42 create_table "contests_problems", :id => false, :force => true do |t|
42 43 t.integer "contest_id"
43 44 t.integer "problem_id"
44 45 end
45 46
46 47 create_table "contests_users", :id => false, :force => true do |t|
47 48 t.integer "contest_id"
48 49 t.integer "user_id"
49 50 end
50 51
51 52 create_table "countries", :force => true do |t|
52 53 t.string "name"
53 54 t.datetime "created_at"
54 55 t.datetime "updated_at"
55 56 end
56 57
57 58 create_table "descriptions", :force => true do |t|
58 59 t.text "body"
59 60 t.boolean "markdowned"
60 61 t.datetime "created_at"
61 62 t.datetime "updated_at"
62 63 end
63 64
64 65 create_table "grader_processes", :force => true do |t|
65 66 t.string "host", :limit => 20
66 67 t.integer "pid"
67 68 t.string "mode"
68 69 t.boolean "active"
69 70 t.datetime "created_at"
70 71 t.datetime "updated_at"
71 72 t.integer "task_id"
72 73 t.string "task_type"
73 74 t.boolean "terminated"
74 75 end
75 76
76 77 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
77 78
78 79 create_table "languages", :force => true do |t|
79 80 t.string "name", :limit => 10
80 81 t.string "pretty_name"
81 82 t.string "ext", :limit => 10
82 83 t.string "common_ext"
83 84 end
84 85
85 86 create_table "messages", :force => true do |t|
86 87 t.integer "sender_id"
87 88 t.integer "receiver_id"
88 89 t.integer "replying_message_id"
89 90 t.text "body"
90 91 t.boolean "replied"
91 92 t.datetime "created_at"
92 93 t.datetime "updated_at"
93 94 end
94 95
95 96 create_table "problems", :force => true do |t|
96 97 t.string "name", :limit => 30
97 98 t.string "full_name"
98 99 t.integer "full_score"
99 100 t.date "date_added"
100 101 t.boolean "available"
101 102 t.string "url"
102 103 t.integer "description_id"
103 104 t.boolean "test_allowed"
104 105 t.boolean "output_only"
105 106 t.string "description_filename"
106 107 end
107 108
108 109 create_table "rights", :force => true do |t|
109 110 t.string "name"
110 111 t.string "controller"
111 112 t.string "action"
112 113 end
113 114
114 115 create_table "rights_roles", :id => false, :force => true do |t|
115 116 t.integer "right_id"
116 117 t.integer "role_id"
117 118 end
118 119
119 120 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
120 121
121 122 create_table "roles", :force => true do |t|
122 123 t.string "name"
123 124 end
124 125
125 126 create_table "roles_users", :id => false, :force => true do |t|
126 127 t.integer "role_id"
127 128 t.integer "user_id"
128 129 end
129 130
130 131 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
131 132
132 133 create_table "sessions", :force => true do |t|
133 134 t.string "session_id"
134 135 t.text "data"
135 136 t.datetime "updated_at"
136 137 end
137 138
138 139 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
139 140 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
140 141
141 142 create_table "sites", :force => true do |t|
142 143 t.string "name"
143 144 t.boolean "started"
144 145 t.datetime "start_time"
145 146 t.datetime "created_at"
146 147 t.datetime "updated_at"
147 148 t.integer "country_id"
148 149 t.string "password"
149 150 end
150 151
151 152 create_table "submissions", :force => true do |t|
152 153 t.integer "user_id"
153 154 t.integer "problem_id"
154 155 t.integer "language_id"
155 156 t.text "source"
156 157 t.binary "binary"
157 158 t.datetime "submitted_at"
158 159 t.datetime "compiled_at"
159 160 t.text "compiler_message"
160 161 t.datetime "graded_at"
161 162 t.integer "points"
162 163 t.text "grader_comment"
163 164 t.integer "number"
164 165 t.string "source_filename"
165 166 end
166 167
167 168 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
168 169 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
169 170
170 171 create_table "tasks", :force => true do |t|
171 172 t.integer "submission_id"
172 173 t.datetime "created_at"
173 174 t.integer "status"
174 175 t.datetime "updated_at"
175 176 end
176 177
177 178 create_table "test_pairs", :force => true do |t|
178 179 t.integer "problem_id"
179 180 t.text "input", :limit => 16777215
180 181 t.text "solution", :limit => 16777215
181 182 t.datetime "created_at"
182 183 t.datetime "updated_at"
183 184 end
184 185
185 186 create_table "test_requests", :force => true do |t|
186 187 t.integer "user_id"
187 188 t.integer "problem_id"
188 189 t.integer "submission_id"
189 190 t.string "input_file_name"
190 191 t.string "output_file_name"
191 192 t.string "running_stat"
192 193 t.integer "status"
193 194 t.datetime "updated_at"
194 195 t.datetime "submitted_at"
195 196 t.datetime "compiled_at"
196 197 t.text "compiler_message"
197 198 t.datetime "graded_at"
198 199 t.string "grader_comment"
199 200 t.datetime "created_at"
200 201 t.float "running_time"
201 202 t.string "exit_status"
202 203 t.integer "memory_usage"
203 204 end
204 205
205 206 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
206 207
207 208 create_table "user_contest_stats", :force => true do |t|
208 209 t.integer "user_id"
209 210 t.datetime "started_at"
210 211 t.datetime "created_at"
211 212 t.datetime "updated_at"
212 213 end
213 214
214 215 create_table "users", :force => true do |t|
215 216 t.string "login", :limit => 50
216 217 t.string "full_name"
217 218 t.string "hashed_password"
218 219 t.string "salt", :limit => 5
219 220 t.string "alias"
220 221 t.string "email"
221 222 t.integer "site_id"
222 223 t.integer "country_id"
223 224 t.boolean "activated", :default => false
224 225 t.datetime "created_at"
225 226 t.datetime "updated_at"
226 227 end
227 228
228 229 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
229 230
230 231 end
@@ -1,178 +1,184
1 1 CONFIGURATIONS =
2 2 [
3 3 {
4 4 :key => 'system.single_user_mode',
5 5 :value_type => 'boolean',
6 6 :default_value => 'false',
7 7 :description => 'Only admins can log in to the system when running under single user mode.'
8 8 },
9 9
10 10 {
11 11 :key => 'ui.front.title',
12 12 :value_type => 'string',
13 13 :default_value => 'Grader'
14 14 },
15 15
16 16 {
17 17 :key => 'ui.front.welcome_message',
18 18 :value_type => 'string',
19 19 :default_value => 'Welcome!'
20 20 },
21 21
22 22 {
23 23 :key => 'ui.show_score',
24 24 :value_type => 'boolean',
25 25 :default_value => 'true'
26 26 },
27 27
28 28 {
29 29 :key => 'contest.time_limit',
30 30 :value_type => 'string',
31 31 :default_value => 'unlimited',
32 32 :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits.'
33 33 },
34 34
35 35 {
36 36 :key => 'system.mode',
37 37 :value_type => 'string',
38 38 :default_value => 'standard',
39 39 :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".'
40 40 },
41 41
42 42 {
43 43 :key => 'contest.name',
44 44 :value_type => 'string',
45 45 :default_value => 'Grader',
46 46 :description => 'This name will be shown on the user header bar.'
47 47 },
48 48
49 49 {
50 50 :key => 'contest.multisites',
51 51 :value_type => 'boolean',
52 52 :default_value => 'false',
53 53 :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.'
54 54 },
55 55
56 56 {
57 57 :key => 'system.online_registration',
58 58 :value_type => 'boolean',
59 59 :default_value => 'false',
60 60 :description => 'This option enables online registration.'
61 61 },
62 62
63 63 # If Configuration['system.online_registration'] is true, the
64 64 # system allows online registration, and will use these
65 65 # information for sending confirmation emails.
66 66 {
67 67 :key => 'system.online_registration.smtp',
68 68 :value_type => 'string',
69 69 :default_value => 'smtp.somehost.com'
70 70 },
71 71
72 72 {
73 73 :key => 'system.online_registration.from',
74 74 :value_type => 'string',
75 75 :default_value => 'your.email@address'
76 76 },
77 77
78 78 {
79 79 :key => 'system.admin_email',
80 80 :value_type => 'string',
81 81 :default_value => 'admin@admin.email'
82 82 },
83 83
84 84 {
85 85 :key => 'system.user_setting_enabled',
86 86 :value_type => 'boolean',
87 87 :default_value => 'true',
88 88 :description => 'If this option is true, users can change their settings'
89 89 },
90 90
91 91 # If Configuration['contest.test_request.early_timeout'] is true
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 + },
99 +
100 + {
101 + :key => 'system.multicontests',
102 + :value_type => 'boolean',
103 + :default_value => 'false'
98 104 }
99 105 ]
100 106
101 107
102 108 def create_configuration_key(key,
103 109 value_type,
104 110 default_value,
105 111 description='')
106 112 conf = (Configuration.find_by_key(key) ||
107 113 Configuration.new(:key => key,
108 114 :value_type => value_type,
109 115 :value => default_value))
110 116 conf.description = description
111 117 conf.save
112 118 end
113 119
114 120 def seed_config
115 121 CONFIGURATIONS.each do |conf|
116 122 if conf.has_key? :description
117 123 desc = conf[:description]
118 124 else
119 125 desc = ''
120 126 end
121 127 create_configuration_key(conf[:key],
122 128 conf[:value_type],
123 129 conf[:default_value],
124 130 desc)
125 131 end
126 132 end
127 133
128 134 def seed_roles
129 135 return if Role.find_by_name('admin')
130 136
131 137 role = Role.create(:name => 'admin')
132 138 user_admin_right = Right.create(:name => 'user_admin',
133 139 :controller => 'user_admin',
134 140 :action => 'all')
135 141 problem_admin_right = Right.create(:name=> 'problem_admin',
136 142 :controller => 'problems',
137 143 :action => 'all')
138 144
139 145 graders_right = Right.create(:name => 'graders_admin',
140 146 :controller => 'graders',
141 147 :action => 'all')
142 148
143 149 role.rights << user_admin_right;
144 150 role.rights << problem_admin_right;
145 151 role.rights << graders_right;
146 152 role.save
147 153 end
148 154
149 155 def seed_root
150 156 return if User.find_by_login('root')
151 157
152 158 root = User.new(:login => 'root',
153 159 :full_name => 'Administrator',
154 160 :alias => 'root')
155 161 root.password = 'ioionrails';
156 162
157 163 class << root
158 164 public :encrypt_new_password
159 165 def valid?
160 166 true
161 167 end
162 168 end
163 169
164 170 root.encrypt_new_password
165 171
166 172 root.roles << Role.find_by_name('admin')
167 173
168 174 root.activated = true
169 175 root.save
170 176 end
171 177
172 178 def seed_users_and_roles
173 179 seed_roles
174 180 seed_root
175 181 end
176 182
177 183 seed_config
178 184 seed_users_and_roles
@@ -1,13 +1,16
1 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2
3 3 contest_a:
4 + name: contest_a
4 5 title: Contest A
5 6 enabled: true
6 7
7 8 contest_b:
9 + name: contest_b
8 10 title: Contest B
9 11 enabled: true
10 12
11 13 contest_c:
14 + name: contest_c
12 15 title: Contest C
13 16 enabled: false
You need to be logged in to leave comments. Login now