Description:
[web] added support for output only problems
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@188 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r99:ab383e0b489e - - 5 files changed: 65 inserted, 22 deleted
@@ -0,0 +1,11 | |||||
|
|
1 | + class AddSupportsForOutputOnlyProblems < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + add_column :submissions, :source_filename, :string | ||
|
|
4 | + add_column :problems, :output_only, :boolean | ||
|
|
5 | + end | ||
|
|
6 | + | ||
|
|
7 | + def self.down | ||
|
|
8 | + remove_column :submissions, :source_filename | ||
|
|
9 | + add_column :problems, :output_only, :boolean | ||
|
|
10 | + end | ||
|
|
11 | + end |
@@ -33,7 +33,10 | |||||
|
33 | @submission = Submission.new(params[:submission]) |
|
33 | @submission = Submission.new(params[:submission]) |
|
34 | @submission.user = user |
|
34 | @submission.user = user |
|
35 | @submission.language_id = 0 |
|
35 | @submission.language_id = 0 |
|
36 | - @submission.source = params['file'].read if params['file']!='' |
|
36 | + if params['file']!='' |
|
|
37 | + @submission.source = params['file'].read | ||
|
|
38 | + @submission.source_filename = params['file'].original_filename | ||
|
|
39 | + end | ||
|
37 | @submission.submitted_at = Time.new |
|
40 | @submission.submitted_at = Time.new |
|
38 |
|
41 | ||
|
39 | if user.site!=nil and user.site.finished? |
|
42 | if user.site!=nil and user.site.finished? |
@@ -4,11 +4,14 | |||||
|
4 | belongs_to :problem |
|
4 | belongs_to :problem |
|
5 | belongs_to :user |
|
5 | belongs_to :user |
|
6 |
|
6 | ||
|
|
7 | + before_validation :assign_problem | ||
|
|
8 | + before_validation :assign_language | ||
|
|
9 | + | ||
|
7 | validates_presence_of :source |
|
10 | validates_presence_of :source |
|
8 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
11 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
9 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
12 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
|
13 | + validate :must_have_valid_problem | ||
|
10 | validate :must_specify_language |
|
14 | validate :must_specify_language |
|
11 | - validate :must_have_valid_problem |
|
||
|
12 |
|
15 | ||
|
13 | before_save :assign_latest_number_if_new_recond |
|
16 | before_save :assign_latest_number_if_new_recond |
|
14 |
|
17 | ||
@@ -97,30 +100,40 | |||||
|
97 | end |
|
100 | end |
|
98 | end |
|
101 | end |
|
99 |
|
102 | ||
|
|
103 | + def assign_problem | ||
|
|
104 | + if self.problem_id!=-1 | ||
|
|
105 | + begin | ||
|
|
106 | + self.problem = Problem.find(self.problem_id) | ||
|
|
107 | + rescue ActiveRecord::RecordNotFound | ||
|
|
108 | + self.problem = nil | ||
|
|
109 | + end | ||
|
|
110 | + else | ||
|
|
111 | + self.problem = Submission.find_problem_in_source(self.source) | ||
|
|
112 | + end | ||
|
|
113 | + end | ||
|
|
114 | + | ||
|
|
115 | + def assign_language | ||
|
|
116 | + self.language = Submission.find_language_in_source(self.source) | ||
|
|
117 | + end | ||
|
|
118 | + | ||
|
100 | # validation codes |
|
119 | # validation codes |
|
101 | def must_specify_language |
|
120 | def must_specify_language |
|
102 | return if self.source==nil |
|
121 | return if self.source==nil |
|
103 | - self.language = Submission.find_language_in_source(self.source) |
|
122 | + |
|
104 | - errors.add('source',"must specify programming language") unless self.language!=nil |
|
123 | + # for output_only tasks |
|
|
124 | + return if self.problem!=nil and self.problem.output_only | ||
|
|
125 | + | ||
|
|
126 | + if self.language==nil | ||
|
|
127 | + errors.add('source',"must specify programming language") unless self.language!=nil | ||
|
|
128 | + end | ||
|
105 | end |
|
129 | end |
|
106 |
|
130 | ||
|
107 | def must_have_valid_problem |
|
131 | def must_have_valid_problem |
|
108 | return if self.source==nil |
|
132 | return if self.source==nil |
|
109 |
- if self.problem |
|
133 | + if self.problem==nil |
|
110 | - begin |
|
||
|
111 | - problem = Problem.find(self.problem_id) |
|
||
|
112 | - rescue ActiveRecord::RecordNotFound |
|
||
|
113 | - problem = nil |
|
||
|
114 | - end |
|
||
|
115 | - else |
|
||
|
116 | - problem = Submission.find_problem_in_source(self.source) |
|
||
|
117 | - end |
|
||
|
118 | - if problem==nil |
|
||
|
119 | errors.add('problem',"must be specified.") |
|
134 | errors.add('problem',"must be specified.") |
|
120 | - elsif (!problem.available) and (self.new_record?) |
|
135 | + elsif (!self.problem.available) and (self.new_record?) |
|
121 | errors.add('problem',"must be valid.") |
|
136 | errors.add('problem',"must be valid.") |
|
122 | - else |
|
||
|
123 | - self.problem = problem |
|
||
|
124 | end |
|
137 | end |
|
125 | end |
|
138 | end |
|
126 |
|
139 |
@@ -13,11 +13,25 | |||||
|
13 | <p><label for="problem_date_added">Date added</label><br/> |
|
13 | <p><label for="problem_date_added">Date added</label><br/> |
|
14 | <%= date_select 'problem', 'date_added' %></p> |
|
14 | <%= date_select 'problem', 'date_added' %></p> |
|
15 |
|
15 | ||
|
16 | - <p><label for="problem_available">Available?</label> |
|
16 | + <% |
|
17 | - <%= select("problem","available",[['True',true],['False',false]]) %></p> |
|
17 | + # TODO: these should be put in model Problem, but I can't think of |
|
|
18 | + # nice default values for them. These values look fine only | ||
|
|
19 | + # in this case (of lazily adding new problems). | ||
|
|
20 | + @problem.available = true if @problem!=nil and @problem.available==nil | ||
|
|
21 | + @problem.test_allowed = true if @problem!=nil and @problem.test_allowed==nil | ||
|
|
22 | + @problem.output_only = false if @problem!=nil and @problem.output_only==nil | ||
|
|
23 | + %> | ||
|
18 |
|
24 | ||
|
19 | - <p><label for="problem_test_allowed">Test allowed?</label> |
|
25 | + <p> |
|
20 | - <%= select("problem","test_allowed",[['True',true],['False',false]]) %></p> |
|
26 | + <label for="problem_available">Available?</label> |
|
|
27 | + <%= check_box :problem, :available %> | ||
|
|
28 | + | ||
|
|
29 | + <label for="problem_test_allowed">Test allowed?</label> | ||
|
|
30 | + <%= check_box :problem, :test_allowed %> | ||
|
|
31 | + | ||
|
|
32 | + <label for="problem_output_only">Output only?</label> | ||
|
|
33 | + <%= check_box :problem, :output_only %> | ||
|
|
34 | + </p> | ||
|
21 |
|
35 | ||
|
22 | <%= error_messages_for 'description' %> |
|
36 | <%= error_messages_for 'description' %> |
|
23 |
|
37 |
@@ -9,7 +9,7 | |||||
|
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 => 3 |
|
12 | + ActiveRecord::Schema.define(:version => 31) 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" |
@@ -61,6 +61,7 | |||||
|
61 | t.string "url" |
|
61 | t.string "url" |
|
62 | t.integer "description_id" |
|
62 | t.integer "description_id" |
|
63 | t.boolean "test_allowed" |
|
63 | t.boolean "test_allowed" |
|
|
64 | + t.boolean "output_only" | ||
|
64 | end |
|
65 | end |
|
65 |
|
66 | ||
|
66 | create_table "rights", :force => true do |t| |
|
67 | create_table "rights", :force => true do |t| |
@@ -117,6 +118,7 | |||||
|
117 | t.integer "points" |
|
118 | t.integer "points" |
|
118 | t.text "grader_comment" |
|
119 | t.text "grader_comment" |
|
119 | t.integer "number" |
|
120 | t.integer "number" |
|
|
121 | + t.string "source_filename" | ||
|
120 | end |
|
122 | end |
|
121 |
|
123 | ||
|
122 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
124 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
You need to be logged in to leave comments.
Login now