Description:
fixed error when submitted file is nil git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@366 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

r169:6eb47384a88d - - 1 file changed: 1 inserted, 1 deleted

@@ -1,152 +1,152
1 1 class MainController < ApplicationController
2 2
3 3 SYSTEM_MODE_CONF_KEY = 'system.mode'
4 4
5 5 before_filter :authenticate, :except => [:index, :login]
6 6 before_filter :check_viewability, :except => [:index, :login]
7 7
8 8 # COMMENTED OUT: filter in each action instead
9 9 # before_filter :verify_time_limit, :only => [:submit]
10 10
11 11 verify :method => :post, :only => [:submit],
12 12 :redirect_to => { :action => :index }
13 13
14 14 # COMMENT OUT: only need when having high load
15 15 # caches_action :index, :login
16 16
17 17 # NOTE: This method is not actually needed, 'config/routes.rb' has
18 18 # assigned action login as a default action.
19 19 def index
20 20 redirect_to :action => 'login'
21 21 end
22 22
23 23 def login
24 24 saved_notice = flash[:notice]
25 25 reset_session
26 26 flash[:notice] = saved_notice
27 27
28 28 # EXPERIMENT:
29 29 # Hide login if in single user mode and the url does not
30 30 # explicitly specify /login
31 31 #
32 32 # logger.info "PATH: #{request.path}"
33 33 # if Configuration['system.single_user_mode'] and
34 34 # request.path!='/main/login'
35 35 # @hidelogin = true
36 36 # end
37 37
38 38 @announcements = Announcement.find_for_frontpage
39 39 render :action => 'login', :layout => 'empty'
40 40 end
41 41
42 42 def list
43 43 prepare_list_information
44 44 end
45 45
46 46 def help
47 47 @user = User.find(session[:user_id])
48 48 end
49 49
50 50 def submit
51 51 user = User.find(session[:user_id])
52 52
53 53 @submission = Submission.new(params[:submission])
54 54 @submission.user = user
55 55 @submission.language_id = 0
56 - if params['file']!=''
56 + if (params['file']) and (params['file']!='')
57 57 @submission.source = params['file'].read
58 58 @submission.source_filename = params['file'].original_filename
59 59 end
60 60 @submission.submitted_at = Time.new.gmtime
61 61
62 62 if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and
63 63 user.site!=nil and user.site.finished?
64 64 @submission.errors.add_to_base "The contest is over."
65 65 prepare_list_information
66 66 render :action => 'list' and return
67 67 end
68 68
69 69 if @submission.valid?
70 70 if @submission.save == false
71 71 flash[:notice] = 'Error saving your submission'
72 72 elsif Task.create(:submission_id => @submission.id,
73 73 :status => Task::STATUS_INQUEUE) == false
74 74 flash[:notice] = 'Error adding your submission to task queue'
75 75 end
76 76 else
77 77 prepare_list_information
78 78 render :action => 'list' and return
79 79 end
80 80 redirect_to :action => 'list'
81 81 end
82 82
83 83 def source
84 84 submission = Submission.find(params[:id])
85 85 if submission.user_id == session[:user_id]
86 86 send_data(submission.source,
87 87 {:filename => submission.download_filename,
88 88 :type => 'text/plain'})
89 89 else
90 90 flash[:notice] = 'Error viewing source'
91 91 redirect_to :action => 'list'
92 92 end
93 93 end
94 94
95 95 def compiler_msg
96 96 @submission = Submission.find(params[:id])
97 97 if @submission.user_id == session[:user_id]
98 98 render :action => 'compiler_msg', :layout => 'empty'
99 99 else
100 100 flash[:notice] = 'Error viewing source'
101 101 redirect_to :action => 'list'
102 102 end
103 103 end
104 104
105 105 def submission
106 106 @user = User.find(session[:user_id])
107 107 @problems = Problem.find_available_problems
108 108 if params[:id]==nil
109 109 @problem = nil
110 110 @submissions = nil
111 111 else
112 112 @problem = Problem.find_by_name(params[:id])
113 113 if not @problem.available
114 114 redirect_to :action => 'list'
115 115 flash[:notice] = 'Error: submissions for that problem are not viewable.'
116 116 return
117 117 end
118 118 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
119 119 end
120 120 end
121 121
122 122 def result
123 123 if !Configuration.show_grading_result
124 124 redirect_to :action => 'list' and return
125 125 end
126 126 @user = User.find(session[:user_id])
127 127 @submission = Submission.find(params[:id])
128 128 if @submission.user!=@user
129 129 flash[:notice] = 'You are not allowed to view result of other users.'
130 130 redirect_to :action => 'list' and return
131 131 end
132 132 prepare_grading_result(@submission)
133 133 end
134 134
135 135 def load_output
136 136 if !Configuration.show_grading_result or params[:num]==nil
137 137 redirect_to :action => 'list' and return
138 138 end
139 139 @user = User.find(session[:user_id])
140 140 @submission = Submission.find(params[:id])
141 141 if @submission.user!=@user
142 142 flash[:notice] = 'You are not allowed to view result of other users.'
143 143 redirect_to :action => 'list' and return
144 144 end
145 145 case_num = params[:num].to_i
146 146 out_filename = output_filename(@user.login,
147 147 @submission.problem.name,
148 148 @submission.id,
149 149 case_num)
150 150 if !FileTest.exists?(out_filename)
151 151 flash[:notice] = 'Output not found.'
152 152 redirect_to :action => 'list' and return
You need to be logged in to leave comments. Login now