Description:
[web] added test_allowed flag to problems git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@181 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r94:c175b74a31f0 - - 4 files changed: 24 inserted, 10 deleted

@@ -1,89 +1,95
1 1 class TestController < ApplicationController
2 2
3 3 before_filter :authenticate
4 4
5 5 #
6 6 # COMMENT OUT: filter in each action instead
7 7 #
8 8 # before_filter :verify_time_limit, :only => [:submit]
9 9
10 10 verify :method => :post, :only => [:submit],
11 11 :redirect_to => { :action => :index }
12 12
13 13 def index
14 14 prepare_index_information
15 15 end
16 16
17 17 def submit
18 18 @user = User.find(session[:user_id])
19 19
20 20 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
21 21
22 22 if @submitted_test_request.errors.length != 0
23 23 prepare_index_information
24 24 render :action => 'index' and return
25 25 end
26 26
27 27 if @user.site!=nil and @user.site.finished?
28 28 @submitted_test_request.errors.add_to_base('Contest is over.')
29 29 prepare_index_information
30 30 render :action => 'index' and return
31 31 end
32 32
33 33 if @submitted_test_request.save
34 34 redirect_to :action => 'index'
35 35 else
36 36 prepare_index_information
37 37 render :action => 'index'
38 38 end
39 39 end
40 40
41 41 def read
42 42 user = User.find(session[:user_id])
43 43 begin
44 44 test_request = TestRequest.find(params[:id])
45 45 rescue
46 46 test_request = nil
47 47 end
48 48 if test_request==nil or test_request.user_id != user.id
49 49 flash[:notice] = 'Invalid output'
50 50 redirect_to :action => 'index'
51 51 return
52 52 end
53 53 if test_request.output_file_name!=nil
54 54 data = File.open(test_request.output_file_name).read(2048)
55 55 if data==nil
56 56 data=""
57 57 end
58 58 send_data(data,
59 59 {:filename => 'output.txt',
60 60 :type => 'text/plain'})
61 61 return
62 62 end
63 63 redirect_to :action => 'index'
64 64 end
65 65
66 66 def result
67 67 @user = User.find(session[:user_id])
68 68 begin
69 69 @test_request = TestRequest.find(params[:id])
70 70 rescue
71 71 @test_request = nil
72 72 end
73 73 if @test_request==nil or @test_request.user_id != @user.id
74 74 flash[:notice] = 'Invalid request'
75 75 redirect_to :action => 'index'
76 76 return
77 77 end
78 78 end
79 79
80 80 protected
81 81
82 82 def prepare_index_information
83 83 @user = User.find(session[:user_id])
84 84 @submissions = Submission.find_last_for_all_available_problems(@user.id)
85 - @problems = @submissions.collect { |submission| submission.problem }
85 + all_problems = @submissions.collect { |submission| submission.problem }
86 + @problems = []
87 + all_problems.each do |problem|
88 + if problem.test_allowed
89 + @problems << problem
90 + end
91 + end
86 92 @test_requests = @user.test_requests
87 93 end
88 94
89 95 end
@@ -1,33 +1,38
1 1 <%= error_messages_for 'problem' %>
2 2
3 3 <!--[form:problem]-->
4 4 <p><label for="problem_name">Name</label><br/>
5 5 <%= text_field 'problem', 'name' %></p>
6 6
7 7 <p><label for="problem_full_name">Full name</label><br/>
8 8 <%= text_field 'problem', 'full_name' %></p>
9 9
10 10 <p><label for="problem_full_score">Full score</label><br/>
11 11 <%= text_field 'problem', 'full_score' %></p>
12 12
13 13 <p><label for="problem_date_added">Date added</label><br/>
14 14 <%= date_select 'problem', 'date_added' %></p>
15 15
16 + <p><label for="problem_available">Available?</label>
17 + <%= select("problem","available",[['True',true],['False',false]]) %></p>
18 +
19 + <p><label for="problem_test_allowed">Test allowed?</label>
20 + <%= select("problem","test_allowed",[['True',true],['False',false]]) %></p>
21 +
16 22 <%= error_messages_for 'description' %>
17 23
18 24 <p><label for="description_body">Description</label><br/>
19 25 <%= text_area :description, :body, :rows => 10, :cols => 80 %></p>
20 26
21 27 <p><label for="description_markdowned">Markdowned?</label>
22 28 <%= select "description",
23 29 "markdowned",
24 30 [['True',true],['False',false]],
25 31 {:selected => (@description) ? @description.markdowned : false }
26 32 %></p>
27 33
28 34 <p><label for="problem_url">URL</label><br/>
29 35 <%= text_field 'problem', 'url' %></p>
30 36
31 - <p><label for="problem_available">Available</label><br/>
32 - <%= select("problem","available",[['True',true],['False',false]]) %></p>
37 +
33 38 <!--[eoform:problem]-->
@@ -1,42 +1,44
1 1 <% content_for :head do %>
2 2 <%= stylesheet_link_tag 'scaffold' %>
3 3 <%= stylesheet_link_tag 'problems' %>
4 4 <%= javascript_include_tag :defaults %>
5 5 <% end %>
6 6
7 7 <h1>Listing problems</h1>
8 8
9 9 <%= link_to 'New problem', :action => 'new' %>
10 10 <%= link_to 'Turn off all problems', :action => 'turn_all_off' %><br/>
11 11
12 12 <table>
13 13 <tr>
14 14 <th>Name</th>
15 15 <th>Full name</th>
16 16 <th>Full score</th>
17 17 <th>Date added</th>
18 - <th>Available</th>
18 + <th>Avail?</th>
19 + <th>Test?</th>
19 20 </tr>
20 21
21 22 <% for problem in @problems %>
22 23 <tr class="<%= (problem.available) ? "available" : "not-available" %>">
23 24 <% @problem=problem %>
24 - <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %>
25 - <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %>
26 - <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %>
27 - <td><%= problem.date_added %>
28 - <td><%= problem.available %>
25 + <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td>
26 + <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td>
27 + <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td>
28 + <td><%= problem.date_added %></td>
29 + <td><%= problem.available %></td>
30 + <td><%= problem.test_allowed %></td>
29 31
30 32 <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td>
31 33 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
32 34 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
33 35 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
34 36 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
35 37 </tr>
36 38 <% end %>
37 39 </table>
38 40
39 41
40 42 <br />
41 43
42 44 <%= link_to 'New problem', :action => 'new' %>
@@ -1,157 +1,158
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 ActiveRecord 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 => 28) do
12 + ActiveRecord::Schema.define(:version => 29) do
13 13
14 14 create_table "configurations", :force => true do |t|
15 15 t.string "key"
16 16 t.string "value_type"
17 17 t.string "value"
18 18 t.datetime "created_at"
19 19 t.datetime "updated_at"
20 20 end
21 21
22 22 create_table "descriptions", :force => true do |t|
23 23 t.text "body"
24 24 t.boolean "markdowned"
25 25 t.datetime "created_at"
26 26 t.datetime "updated_at"
27 27 end
28 28
29 29 create_table "grader_processes", :force => true do |t|
30 30 t.string "host", :limit => 20
31 31 t.integer "pid"
32 32 t.string "mode"
33 33 t.boolean "active"
34 34 t.datetime "created_at"
35 35 t.datetime "updated_at"
36 36 t.integer "task_id"
37 37 end
38 38
39 39 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
40 40
41 41 create_table "languages", :force => true do |t|
42 42 t.string "name", :limit => 10
43 43 t.string "pretty_name"
44 44 t.string "ext", :limit => 10
45 45 end
46 46
47 47 create_table "problems", :force => true do |t|
48 48 t.string "name", :limit => 30
49 49 t.string "full_name"
50 50 t.integer "full_score"
51 51 t.date "date_added"
52 52 t.boolean "available"
53 53 t.string "url"
54 54 t.integer "description_id"
55 + t.boolean "test_allowed"
55 56 end
56 57
57 58 create_table "rights", :force => true do |t|
58 59 t.string "name"
59 60 t.string "controller"
60 61 t.string "action"
61 62 end
62 63
63 64 create_table "rights_roles", :id => false, :force => true do |t|
64 65 t.integer "right_id"
65 66 t.integer "role_id"
66 67 end
67 68
68 69 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
69 70
70 71 create_table "roles", :force => true do |t|
71 72 t.string "name"
72 73 end
73 74
74 75 create_table "roles_users", :id => false, :force => true do |t|
75 76 t.integer "role_id"
76 77 t.integer "user_id"
77 78 end
78 79
79 80 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
80 81
81 82 create_table "sessions", :force => true do |t|
82 83 t.string "session_id"
83 84 t.text "data"
84 85 t.datetime "updated_at"
85 86 end
86 87
87 88 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
88 89 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
89 90
90 91 create_table "sites", :force => true do |t|
91 92 t.string "name"
92 93 t.boolean "started"
93 94 t.datetime "start_time"
94 95 t.datetime "created_at"
95 96 t.datetime "updated_at"
96 97 end
97 98
98 99 create_table "submissions", :force => true do |t|
99 100 t.integer "user_id"
100 101 t.integer "problem_id"
101 102 t.integer "language_id"
102 103 t.text "source"
103 104 t.binary "binary"
104 105 t.datetime "submitted_at"
105 106 t.datetime "compiled_at"
106 107 t.text "compiler_message"
107 108 t.datetime "graded_at"
108 109 t.integer "points"
109 110 t.text "grader_comment"
110 111 t.integer "number"
111 112 end
112 113
113 114 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
114 115 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
115 116
116 117 create_table "tasks", :force => true do |t|
117 118 t.integer "submission_id"
118 119 t.datetime "created_at"
119 120 t.integer "status"
120 121 t.datetime "updated_at"
121 122 end
122 123
123 124 create_table "test_requests", :force => true do |t|
124 125 t.integer "user_id"
125 126 t.integer "problem_id"
126 127 t.integer "submission_id"
127 128 t.string "input_file_name"
128 129 t.string "output_file_name"
129 130 t.string "running_stat"
130 131 t.integer "status"
131 132 t.datetime "updated_at"
132 133 t.datetime "submitted_at"
133 134 t.datetime "compiled_at"
134 135 t.text "compiler_message"
135 136 t.datetime "graded_at"
136 137 t.string "grader_comment"
137 138 t.datetime "created_at"
138 139 t.float "running_time"
139 140 t.string "exit_status"
140 141 t.integer "memory_usage"
141 142 end
142 143
143 144 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
144 145
145 146 create_table "users", :force => true do |t|
146 147 t.string "login", :limit => 10
147 148 t.string "full_name"
148 149 t.string "hashed_password"
149 150 t.string "salt", :limit => 5
150 151 t.string "alias"
151 152 t.string "email"
152 153 t.integer "site_id"
153 154 end
154 155
155 156 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
156 157
157 158 end
You need to be logged in to leave comments. Login now