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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r169:6eb47384a88d - - 1 file changed: 1 inserted, 1 deleted
@@ -8,97 +8,97 | |||||
|
8 | # COMMENTED OUT: filter in each action instead |
|
8 | # COMMENTED OUT: filter in each action instead |
|
9 | # before_filter :verify_time_limit, :only => [:submit] |
|
9 | # before_filter :verify_time_limit, :only => [:submit] |
|
10 |
|
10 | ||
|
11 | verify :method => :post, :only => [:submit], |
|
11 | verify :method => :post, :only => [:submit], |
|
12 | :redirect_to => { :action => :index } |
|
12 | :redirect_to => { :action => :index } |
|
13 |
|
13 | ||
|
14 | # COMMENT OUT: only need when having high load |
|
14 | # COMMENT OUT: only need when having high load |
|
15 | # caches_action :index, :login |
|
15 | # caches_action :index, :login |
|
16 |
|
16 | ||
|
17 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
17 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
18 | # assigned action login as a default action. |
|
18 | # assigned action login as a default action. |
|
19 | def index |
|
19 | def index |
|
20 | redirect_to :action => 'login' |
|
20 | redirect_to :action => 'login' |
|
21 | end |
|
21 | end |
|
22 |
|
22 | ||
|
23 | def login |
|
23 | def login |
|
24 | saved_notice = flash[:notice] |
|
24 | saved_notice = flash[:notice] |
|
25 | reset_session |
|
25 | reset_session |
|
26 | flash[:notice] = saved_notice |
|
26 | flash[:notice] = saved_notice |
|
27 |
|
27 | ||
|
28 | # EXPERIMENT: |
|
28 | # EXPERIMENT: |
|
29 | # Hide login if in single user mode and the url does not |
|
29 | # Hide login if in single user mode and the url does not |
|
30 | # explicitly specify /login |
|
30 | # explicitly specify /login |
|
31 | # |
|
31 | # |
|
32 | # logger.info "PATH: #{request.path}" |
|
32 | # logger.info "PATH: #{request.path}" |
|
33 | # if Configuration['system.single_user_mode'] and |
|
33 | # if Configuration['system.single_user_mode'] and |
|
34 | # request.path!='/main/login' |
|
34 | # request.path!='/main/login' |
|
35 | # @hidelogin = true |
|
35 | # @hidelogin = true |
|
36 | # end |
|
36 | # end |
|
37 |
|
37 | ||
|
38 | @announcements = Announcement.find_for_frontpage |
|
38 | @announcements = Announcement.find_for_frontpage |
|
39 | render :action => 'login', :layout => 'empty' |
|
39 | render :action => 'login', :layout => 'empty' |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def list |
|
42 | def list |
|
43 | prepare_list_information |
|
43 | prepare_list_information |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | def help |
|
46 | def help |
|
47 | @user = User.find(session[:user_id]) |
|
47 | @user = User.find(session[:user_id]) |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def submit |
|
50 | def submit |
|
51 | user = User.find(session[:user_id]) |
|
51 | user = User.find(session[:user_id]) |
|
52 |
|
52 | ||
|
53 | @submission = Submission.new(params[:submission]) |
|
53 | @submission = Submission.new(params[:submission]) |
|
54 | @submission.user = user |
|
54 | @submission.user = user |
|
55 | @submission.language_id = 0 |
|
55 | @submission.language_id = 0 |
|
56 | - if params['file']!='' |
|
56 | + if (params['file']) and (params['file']!='') |
|
57 | @submission.source = params['file'].read |
|
57 | @submission.source = params['file'].read |
|
58 | @submission.source_filename = params['file'].original_filename |
|
58 | @submission.source_filename = params['file'].original_filename |
|
59 | end |
|
59 | end |
|
60 | @submission.submitted_at = Time.new.gmtime |
|
60 | @submission.submitted_at = Time.new.gmtime |
|
61 |
|
61 | ||
|
62 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
62 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
63 | user.site!=nil and user.site.finished? |
|
63 | user.site!=nil and user.site.finished? |
|
64 | @submission.errors.add_to_base "The contest is over." |
|
64 | @submission.errors.add_to_base "The contest is over." |
|
65 | prepare_list_information |
|
65 | prepare_list_information |
|
66 | render :action => 'list' and return |
|
66 | render :action => 'list' and return |
|
67 | end |
|
67 | end |
|
68 |
|
68 | ||
|
69 | if @submission.valid? |
|
69 | if @submission.valid? |
|
70 | if @submission.save == false |
|
70 | if @submission.save == false |
|
71 | flash[:notice] = 'Error saving your submission' |
|
71 | flash[:notice] = 'Error saving your submission' |
|
72 | elsif Task.create(:submission_id => @submission.id, |
|
72 | elsif Task.create(:submission_id => @submission.id, |
|
73 | :status => Task::STATUS_INQUEUE) == false |
|
73 | :status => Task::STATUS_INQUEUE) == false |
|
74 | flash[:notice] = 'Error adding your submission to task queue' |
|
74 | flash[:notice] = 'Error adding your submission to task queue' |
|
75 | end |
|
75 | end |
|
76 | else |
|
76 | else |
|
77 | prepare_list_information |
|
77 | prepare_list_information |
|
78 | render :action => 'list' and return |
|
78 | render :action => 'list' and return |
|
79 | end |
|
79 | end |
|
80 | redirect_to :action => 'list' |
|
80 | redirect_to :action => 'list' |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | def source |
|
83 | def source |
|
84 | submission = Submission.find(params[:id]) |
|
84 | submission = Submission.find(params[:id]) |
|
85 | if submission.user_id == session[:user_id] |
|
85 | if submission.user_id == session[:user_id] |
|
86 | send_data(submission.source, |
|
86 | send_data(submission.source, |
|
87 | {:filename => submission.download_filename, |
|
87 | {:filename => submission.download_filename, |
|
88 | :type => 'text/plain'}) |
|
88 | :type => 'text/plain'}) |
|
89 | else |
|
89 | else |
|
90 | flash[:notice] = 'Error viewing source' |
|
90 | flash[:notice] = 'Error viewing source' |
|
91 | redirect_to :action => 'list' |
|
91 | redirect_to :action => 'list' |
|
92 | end |
|
92 | end |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | def compiler_msg |
|
95 | def compiler_msg |
|
96 | @submission = Submission.find(params[:id]) |
|
96 | @submission = Submission.find(params[:id]) |
|
97 | if @submission.user_id == session[:user_id] |
|
97 | if @submission.user_id == session[:user_id] |
|
98 | render :action => 'compiler_msg', :layout => 'empty' |
|
98 | render :action => 'compiler_msg', :layout => 'empty' |
|
99 | else |
|
99 | else |
|
100 | flash[:notice] = 'Error viewing source' |
|
100 | flash[:notice] = 'Error viewing source' |
|
101 | redirect_to :action => 'list' |
|
101 | redirect_to :action => 'list' |
|
102 | end |
|
102 | end |
|
103 | end |
|
103 | end |
|
104 |
|
104 |
You need to be logged in to leave comments.
Login now