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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r99:ab383e0b489e - - 5 files changed: 64 inserted, 21 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
@@ -24,25 +24,28
24 24 end
25 25
26 26 def list
27 27 prepare_list_information
28 28 end
29 29
30 30 def submit
31 31 user = User.find(session[:user_id])
32 32
33 33 @submission = Submission.new(params[:submission])
34 34 @submission.user = user
35 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 40 @submission.submitted_at = Time.new
38 41
39 42 if user.site!=nil and user.site.finished?
40 43 @submission.errors.add_to_base "The contest is over."
41 44 prepare_list_information
42 45 render :action => 'list' and return
43 46 end
44 47
45 48 if @submission.valid?
46 49 if @submission.save == false
47 50 flash[:notice] = 'Error saving your submission'
48 51 elsif Task.create(:submission_id => @submission.id,
@@ -1,23 +1,26
1 1 class Submission < ActiveRecord::Base
2 2
3 3 belongs_to :language
4 4 belongs_to :problem
5 5 belongs_to :user
6 6
7 + before_validation :assign_problem
8 + before_validation :assign_language
9 +
7 10 validates_presence_of :source
8 11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
9 12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 + validate :must_have_valid_problem
10 14 validate :must_specify_language
11 - validate :must_have_valid_problem
12 15
13 16 before_save :assign_latest_number_if_new_recond
14 17
15 18 def self.find_last_by_user_and_problem(user_id, problem_id)
16 19 last_sub = find(:first,
17 20 :conditions => {:user_id => user_id,
18 21 :problem_id => problem_id},
19 22 :order => 'number DESC')
20 23 return last_sub
21 24 end
22 25
23 26 def self.find_all_last_by_problem(problem_id)
@@ -88,47 +91,57
88 91 end
89 92 end
90 93
91 94 def self.find_problem_in_source(source)
92 95 prob_opt = find_option_in_source(/^TASK:/,source)
93 96 if problem = Problem.find_by_name(prob_opt)
94 97 return problem
95 98 else
96 99 return nil
97 100 end
98 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 119 # validation codes
101 120 def must_specify_language
102 121 return if self.source==nil
103 - self.language = Submission.find_language_in_source(self.source)
122 +
123 + # for output_only tasks
124 + return if self.problem!=nil and self.problem.output_only
125 +
126 + if self.language==nil
104 127 errors.add('source',"must specify programming language") unless self.language!=nil
105 128 end
129 + end
106 130
107 131 def must_have_valid_problem
108 132 return if self.source==nil
109 - if self.problem_id!=-1
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
133 + if self.problem==nil
119 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 136 errors.add('problem',"must be valid.")
122 - else
123 - self.problem = problem
124 137 end
125 138 end
126 139
127 140 # callbacks
128 141 def assign_latest_number_if_new_recond
129 142 return if !self.new_record?
130 143 latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id)
131 144 self.number = (latest==nil) ? 1 : latest.number + 1;
132 145 end
133 146
134 147 end
@@ -4,29 +4,43
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>
16 + <%
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>
20 - <%= select("problem","test_allowed",[['True',true],['False',false]]) %></p>
25 + <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 36 <%= error_messages_for 'description' %>
23 37
24 38 <p><label for="description_body">Description</label><br/>
25 39 <%= text_area :description, :body, :rows => 10, :cols => 80 %></p>
26 40
27 41 <p><label for="description_markdowned">Markdowned?</label>
28 42 <%= select "description",
29 43 "markdowned",
30 44 [['True',true],['False',false]],
31 45 {:selected => (@description) ? @description.markdowned : false }
32 46 %></p>
@@ -1,24 +1,24
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 => 30) do
12 + ActiveRecord::Schema.define(:version => 31) 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 end
21 21
22 22 create_table "configurations", :force => true do |t|
23 23 t.string "key"
24 24 t.string "value_type"
@@ -52,24 +52,25
52 52 t.string "ext", :limit => 10
53 53 end
54 54
55 55 create_table "problems", :force => true do |t|
56 56 t.string "name", :limit => 30
57 57 t.string "full_name"
58 58 t.integer "full_score"
59 59 t.date "date_added"
60 60 t.boolean "available"
61 61 t.string "url"
62 62 t.integer "description_id"
63 63 t.boolean "test_allowed"
64 + t.boolean "output_only"
64 65 end
65 66
66 67 create_table "rights", :force => true do |t|
67 68 t.string "name"
68 69 t.string "controller"
69 70 t.string "action"
70 71 end
71 72
72 73 create_table "rights_roles", :id => false, :force => true do |t|
73 74 t.integer "right_id"
74 75 t.integer "role_id"
75 76 end
@@ -108,24 +109,25
108 109 t.integer "user_id"
109 110 t.integer "problem_id"
110 111 t.integer "language_id"
111 112 t.text "source"
112 113 t.binary "binary"
113 114 t.datetime "submitted_at"
114 115 t.datetime "compiled_at"
115 116 t.text "compiler_message"
116 117 t.datetime "graded_at"
117 118 t.integer "points"
118 119 t.text "grader_comment"
119 120 t.integer "number"
121 + t.string "source_filename"
120 122 end
121 123
122 124 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
123 125 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
124 126
125 127 create_table "tasks", :force => true do |t|
126 128 t.integer "submission_id"
127 129 t.datetime "created_at"
128 130 t.integer "status"
129 131 t.datetime "updated_at"
130 132 end
131 133
You need to be logged in to leave comments. Login now