Description:
[web] uploading output-only submission
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@189 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
r100:2ce8f9387085 - - 2 files changed: 8 inserted, 0 deleted
@@ -17,97 +17,101 | |||||
|
17 |
|
17 | ||
|
18 | def login |
|
18 | def login |
|
19 | saved_notice = flash[:notice] |
|
19 | saved_notice = flash[:notice] |
|
20 | reset_session |
|
20 | reset_session |
|
21 | flash[:notice] = saved_notice |
|
21 | flash[:notice] = saved_notice |
|
22 |
|
22 | ||
|
23 | render :action => 'login', :layout => 'empty' |
|
23 | render :action => 'login', :layout => 'empty' |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def list |
|
26 | def list |
|
27 | prepare_list_information |
|
27 | prepare_list_information |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def submit |
|
30 | def submit |
|
31 | user = User.find(session[:user_id]) |
|
31 | user = User.find(session[:user_id]) |
|
32 |
|
32 | ||
|
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 | if params['file']!='' |
|
36 | if params['file']!='' |
|
37 | @submission.source = params['file'].read |
|
37 | @submission.source = params['file'].read |
|
38 | @submission.source_filename = params['file'].original_filename |
|
38 | @submission.source_filename = params['file'].original_filename |
|
39 | end |
|
39 | end |
|
40 | @submission.submitted_at = Time.new |
|
40 | @submission.submitted_at = Time.new |
|
41 |
|
41 | ||
|
42 | if user.site!=nil and user.site.finished? |
|
42 | if user.site!=nil and user.site.finished? |
|
43 | @submission.errors.add_to_base "The contest is over." |
|
43 | @submission.errors.add_to_base "The contest is over." |
|
44 | prepare_list_information |
|
44 | prepare_list_information |
|
45 | render :action => 'list' and return |
|
45 | render :action => 'list' and return |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | if @submission.valid? |
|
48 | if @submission.valid? |
|
49 | if @submission.save == false |
|
49 | if @submission.save == false |
|
50 | flash[:notice] = 'Error saving your submission' |
|
50 | flash[:notice] = 'Error saving your submission' |
|
51 | elsif Task.create(:submission_id => @submission.id, |
|
51 | elsif Task.create(:submission_id => @submission.id, |
|
52 | :status => Task::STATUS_INQUEUE) == false |
|
52 | :status => Task::STATUS_INQUEUE) == false |
|
53 | flash[:notice] = 'Error adding your submission to task queue' |
|
53 | flash[:notice] = 'Error adding your submission to task queue' |
|
54 | end |
|
54 | end |
|
55 | else |
|
55 | else |
|
56 | prepare_list_information |
|
56 | prepare_list_information |
|
57 | render :action => 'list' and return |
|
57 | render :action => 'list' and return |
|
58 | end |
|
58 | end |
|
59 | redirect_to :action => 'list' |
|
59 | redirect_to :action => 'list' |
|
60 | end |
|
60 | end |
|
61 |
|
61 | ||
|
62 | def source |
|
62 | def source |
|
63 | submission = Submission.find(params[:id]) |
|
63 | submission = Submission.find(params[:id]) |
|
64 | if submission.user_id == session[:user_id] |
|
64 | if submission.user_id == session[:user_id] |
|
|
65 | + if submission.problem.output_only | ||
|
|
66 | + fname = submission.source_filename | ||
|
|
67 | + else | ||
|
65 | fname = submission.problem.name + '.' + submission.language.ext |
|
68 | fname = submission.problem.name + '.' + submission.language.ext |
|
|
69 | + end | ||
|
66 | send_data(submission.source, |
|
70 | send_data(submission.source, |
|
67 | {:filename => fname, |
|
71 | {:filename => fname, |
|
68 | :type => 'text/plain'}) |
|
72 | :type => 'text/plain'}) |
|
69 | else |
|
73 | else |
|
70 | flash[:notice] = 'Error viewing source' |
|
74 | flash[:notice] = 'Error viewing source' |
|
71 | redirect_to :action => 'list' |
|
75 | redirect_to :action => 'list' |
|
72 | end |
|
76 | end |
|
73 | end |
|
77 | end |
|
74 |
|
78 | ||
|
75 | def compiler_msg |
|
79 | def compiler_msg |
|
76 | @submission = Submission.find(params[:id]) |
|
80 | @submission = Submission.find(params[:id]) |
|
77 | if @submission.user_id == session[:user_id] |
|
81 | if @submission.user_id == session[:user_id] |
|
78 | render :action => 'compiler_msg', :layout => 'empty' |
|
82 | render :action => 'compiler_msg', :layout => 'empty' |
|
79 | else |
|
83 | else |
|
80 | flash[:notice] = 'Error viewing source' |
|
84 | flash[:notice] = 'Error viewing source' |
|
81 | redirect_to :action => 'list' |
|
85 | redirect_to :action => 'list' |
|
82 | end |
|
86 | end |
|
83 | end |
|
87 | end |
|
84 |
|
88 | ||
|
85 | def submission |
|
89 | def submission |
|
86 | @user = User.find(session[:user_id]) |
|
90 | @user = User.find(session[:user_id]) |
|
87 | @problems = Problem.find_available_problems |
|
91 | @problems = Problem.find_available_problems |
|
88 | if params[:id]==nil |
|
92 | if params[:id]==nil |
|
89 | @problem = nil |
|
93 | @problem = nil |
|
90 | @submissions = nil |
|
94 | @submissions = nil |
|
91 | else |
|
95 | else |
|
92 | @problem = Problem.find_by_name(params[:id]) |
|
96 | @problem = Problem.find_by_name(params[:id]) |
|
93 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
97 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
94 | end |
|
98 | end |
|
95 | end |
|
99 | end |
|
96 |
|
100 | ||
|
97 | protected |
|
101 | protected |
|
98 | def prepare_list_information |
|
102 | def prepare_list_information |
|
99 | @problems = Problem.find_available_problems |
|
103 | @problems = Problem.find_available_problems |
|
100 | @prob_submissions = Array.new |
|
104 | @prob_submissions = Array.new |
|
101 | @user = User.find(session[:user_id]) |
|
105 | @user = User.find(session[:user_id]) |
|
102 | @problems.each do |p| |
|
106 | @problems.each do |p| |
|
103 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
107 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
104 | if sub!=nil |
|
108 | if sub!=nil |
|
105 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
109 | @prob_submissions << { :count => sub.number, :submission => sub } |
|
106 | else |
|
110 | else |
|
107 | @prob_submissions << { :count => 0, :submission => nil } |
|
111 | @prob_submissions << { :count => 0, :submission => nil } |
|
108 | end |
|
112 | end |
|
109 | end |
|
113 | end |
|
110 |
|
114 | ||
|
111 | @announcements = Announcement.find(:all, |
|
115 | @announcements = Announcement.find(:all, |
|
112 | :conditions => "published = 1", |
|
116 | :conditions => "published = 1", |
|
113 | :order => "created_at DESC") |
|
117 | :order => "created_at DESC") |
@@ -54,51 +54,55 | |||||
|
54 |
|
54 | ||
|
55 | def update |
|
55 | def update |
|
56 | @problem = Problem.find(params[:id]) |
|
56 | @problem = Problem.find(params[:id]) |
|
57 | @description = @problem.description |
|
57 | @description = @problem.description |
|
58 | if @description == nil and params[:description][:body]!='' |
|
58 | if @description == nil and params[:description][:body]!='' |
|
59 | @description = Description.new(params[:description]) |
|
59 | @description = Description.new(params[:description]) |
|
60 | if !@description.save |
|
60 | if !@description.save |
|
61 | flash[:notice] = 'Error saving description' |
|
61 | flash[:notice] = 'Error saving description' |
|
62 | render :action => 'edit' and return |
|
62 | render :action => 'edit' and return |
|
63 | end |
|
63 | end |
|
64 | @problem.description = @description |
|
64 | @problem.description = @description |
|
65 | elsif @description!=nil |
|
65 | elsif @description!=nil |
|
66 | if !@description.update_attributes(params[:description]) |
|
66 | if !@description.update_attributes(params[:description]) |
|
67 | flash[:notice] = 'Error saving description' |
|
67 | flash[:notice] = 'Error saving description' |
|
68 | render :action => 'edit' and return |
|
68 | render :action => 'edit' and return |
|
69 | end |
|
69 | end |
|
70 | end |
|
70 | end |
|
71 | if @problem.update_attributes(params[:problem]) |
|
71 | if @problem.update_attributes(params[:problem]) |
|
72 | flash[:notice] = 'Problem was successfully updated.' |
|
72 | flash[:notice] = 'Problem was successfully updated.' |
|
73 | redirect_to :action => 'show', :id => @problem |
|
73 | redirect_to :action => 'show', :id => @problem |
|
74 | else |
|
74 | else |
|
75 | render :action => 'edit' |
|
75 | render :action => 'edit' |
|
76 | end |
|
76 | end |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | def destroy |
|
79 | def destroy |
|
80 | Problem.find(params[:id]).destroy |
|
80 | Problem.find(params[:id]).destroy |
|
81 | redirect_to :action => 'list' |
|
81 | redirect_to :action => 'list' |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | def toggle_avail |
|
84 | def toggle_avail |
|
85 | problem = Problem.find(params[:id]) |
|
85 | problem = Problem.find(params[:id]) |
|
86 | problem.available = !(problem.available) |
|
86 | problem.available = !(problem.available) |
|
87 | problem.save |
|
87 | problem.save |
|
88 | redirect_to :action => 'list' |
|
88 | redirect_to :action => 'list' |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | def turn_all_off |
|
91 | def turn_all_off |
|
92 | Problem.find(:all, |
|
92 | Problem.find(:all, |
|
93 | :conditions => "available = 1").each do |problem| |
|
93 | :conditions => "available = 1").each do |problem| |
|
94 | problem.available = false |
|
94 | problem.available = false |
|
95 | problem.save |
|
95 | problem.save |
|
96 | end |
|
96 | end |
|
97 | redirect_to :action => 'list' |
|
97 | redirect_to :action => 'list' |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | def stat |
|
100 | def stat |
|
101 | @problem = Problem.find(params[:id]) |
|
101 | @problem = Problem.find(params[:id]) |
|
|
102 | + if !@problem.available | ||
|
|
103 | + redirect_to :controller => 'main', :action => 'list' | ||
|
|
104 | + else | ||
|
102 | @submissions = Submission.find_all_last_by_problem(params[:id]) |
|
105 | @submissions = Submission.find_all_last_by_problem(params[:id]) |
|
103 | end |
|
106 | end |
|
104 | end |
|
107 | end |
|
|
108 | + end |
You need to be logged in to leave comments.
Login now