Description:
[web] added error page for uploading too large file git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@228 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

r109:da88b4336501 - - 2 files changed: 11 inserted, 0 deleted

@@ -0,0 +1,7
1 + = user_title_bar(@user)
2 +
3 + .announcementbox
4 + %span{:class => 'title'}
5 + Error
6 + .announcement
7 + You are uploading a file which is too large (> 2MB).
@@ -9,117 +9,121
9 9
10 10 verify :method => :post, :only => [:submit],
11 11 :redirect_to => { :action => :index }
12 12
13 13
14 14 def index
15 15 redirect_to :action => 'login'
16 16 end
17 17
18 18 def login
19 19 saved_notice = flash[:notice]
20 20 reset_session
21 21 flash[:notice] = saved_notice
22 22
23 23 render :action => 'login', :layout => 'empty'
24 24 end
25 25
26 26 def list
27 27 prepare_list_information
28 28 end
29 29
30 30 def help
31 31 @user = User.find(session[:user_id])
32 32 end
33 33
34 34 def submit
35 35 user = User.find(session[:user_id])
36 36
37 37 @submission = Submission.new(params[:submission])
38 38 @submission.user = user
39 39 @submission.language_id = 0
40 40 if params['file']!=''
41 41 @submission.source = params['file'].read
42 42 @submission.source_filename = params['file'].original_filename
43 43 end
44 44 @submission.submitted_at = Time.new
45 45
46 46 if user.site!=nil and user.site.finished?
47 47 @submission.errors.add_to_base "The contest is over."
48 48 prepare_list_information
49 49 render :action => 'list' and return
50 50 end
51 51
52 52 if @submission.valid?
53 53 if @submission.save == false
54 54 flash[:notice] = 'Error saving your submission'
55 55 elsif Task.create(:submission_id => @submission.id,
56 56 :status => Task::STATUS_INQUEUE) == false
57 57 flash[:notice] = 'Error adding your submission to task queue'
58 58 end
59 59 else
60 60 prepare_list_information
61 61 render :action => 'list' and return
62 62 end
63 63 redirect_to :action => 'list'
64 64 end
65 65
66 66 def source
67 67 submission = Submission.find(params[:id])
68 68 if submission.user_id == session[:user_id]
69 69 if submission.problem.output_only
70 70 fname = submission.source_filename
71 71 else
72 72 fname = submission.problem.name + '.' + submission.language.ext
73 73 end
74 74 send_data(submission.source,
75 75 {:filename => fname,
76 76 :type => 'text/plain'})
77 77 else
78 78 flash[:notice] = 'Error viewing source'
79 79 redirect_to :action => 'list'
80 80 end
81 81 end
82 82
83 83 def compiler_msg
84 84 @submission = Submission.find(params[:id])
85 85 if @submission.user_id == session[:user_id]
86 86 render :action => 'compiler_msg', :layout => 'empty'
87 87 else
88 88 flash[:notice] = 'Error viewing source'
89 89 redirect_to :action => 'list'
90 90 end
91 91 end
92 92
93 93 def submission
94 94 @user = User.find(session[:user_id])
95 95 @problems = Problem.find_available_problems
96 96 if params[:id]==nil
97 97 @problem = nil
98 98 @submissions = nil
99 99 else
100 100 @problem = Problem.find_by_name(params[:id])
101 101 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
102 102 end
103 103 end
104 104
105 + def error
106 + @user = User.find(session[:user_id])
107 + end
108 +
105 109 protected
106 110 def prepare_list_information
107 111 @problems = Problem.find_available_problems
108 112 @prob_submissions = Array.new
109 113 @user = User.find(session[:user_id])
110 114 @problems.each do |p|
111 115 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
112 116 if sub!=nil
113 117 @prob_submissions << { :count => sub.number, :submission => sub }
114 118 else
115 119 @prob_submissions << { :count => 0, :submission => nil }
116 120 end
117 121 end
118 122
119 123 @announcements = Announcement.find(:all,
120 124 :conditions => "published = 1",
121 125 :order => "created_at DESC")
122 126 end
123 127
124 128 end
125 129
You need to be logged in to leave comments. Login now