Description:
- fix pdf loading fail
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r634:56cf4357ce2a - - 4 files changed: 11 inserted, 4 deleted

@@ -67,49 +67,49
67 67 @problem = Problem.find(params[:id])
68 68 @description = @problem.description
69 69 end
70 70
71 71 def update
72 72 @problem = Problem.find(params[:id])
73 73 @description = @problem.description
74 74 if @description.nil? and params[:description][:body]!=''
75 75 @description = Description.new(params[:description])
76 76 if !@description.save
77 77 flash[:notice] = 'Error saving description'
78 78 render :action => 'edit' and return
79 79 end
80 80 @problem.description = @description
81 81 elsif @description
82 82 if !@description.update_attributes(params[:description])
83 83 flash[:notice] = 'Error saving description'
84 84 render :action => 'edit' and return
85 85 end
86 86 end
87 87 if params[:file] and params[:file].content_type != 'application/pdf'
88 88 flash[:notice] = 'Error: Uploaded file is not PDF'
89 89 render :action => 'edit' and return
90 90 end
91 - if @problem.update_attributes(params[:problem])
91 + if @problem.update_attributes(problem_params)
92 92 flash[:notice] = 'Problem was successfully updated.'
93 93 unless params[:file] == nil or params[:file] == ''
94 94 flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.'
95 95 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
96 96 if not FileTest.exists? out_dirname
97 97 Dir.mkdir out_dirname
98 98 end
99 99
100 100 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
101 101 if FileTest.exists? out_filename
102 102 File.delete out_filename
103 103 end
104 104
105 105 File.open(out_filename,"wb") do |file|
106 106 file.write(params[:file].read)
107 107 end
108 108 @problem.description_filename = "#{@problem.name}.pdf"
109 109 @problem.save
110 110 end
111 111 redirect_to :action => 'show', :id => @problem
112 112 else
113 113 render :action => 'edit'
114 114 end
115 115 end
@@ -264,25 +264,31
264 264 end
265 265
266 266 def set_available(avail)
267 267 problems = get_problems_from_params
268 268 problems.each do |p|
269 269 p.available = avail
270 270 p.save
271 271 end
272 272 end
273 273
274 274 def get_problems_from_params
275 275 problems = []
276 276 params.keys.each do |k|
277 277 if k.index('prob-')==0
278 278 name, id, order = k.split('-')
279 279 problems << Problem.find(id)
280 280 end
281 281 end
282 282 problems
283 283 end
284 284
285 285 def get_problems_stat
286 286 end
287 287
288 + private
289 +
290 + def problem_params
291 + params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description)
288 292 end
293 +
294 + end
@@ -97,49 +97,49
97 97
98 98 user = User.find_by_login(login)
99 99 if (user)
100 100 user.full_name = full_name
101 101 user.password = password
102 102 user.remark = remark
103 103 else
104 104 user = User.new({:login => login,
105 105 :full_name => full_name,
106 106 :password => password,
107 107 :password_confirmation => password,
108 108 :alias => user_alias,
109 109 :remark => remark})
110 110 end
111 111 user.activated = true
112 112 user.save
113 113
114 114 if added_random_password
115 115 note << "'#{login}' (+)"
116 116 else
117 117 note << login
118 118 end
119 119 end
120 120 end
121 - flash[:notice] = 'User(s) ' + note.join(', ') +
121 + flash[:success] = 'User(s) ' + note.join(', ') +
122 122 ' were successfully created. ' +
123 123 '( (+) - created with random passwords.)'
124 124 redirect_to :action => 'index'
125 125 end
126 126
127 127 def edit
128 128 @user = User.find(params[:id])
129 129 end
130 130
131 131 def update
132 132 @user = User.find(params[:id])
133 133 if @user.update_attributes(user_params)
134 134 flash[:notice] = 'User was successfully updated.'
135 135 redirect_to :action => 'show', :id => @user
136 136 else
137 137 render :action => 'edit'
138 138 end
139 139 end
140 140
141 141 def destroy
142 142 User.find(params[:id]).destroy
143 143 redirect_to :action => 'index'
144 144 end
145 145
@@ -1,29 +1,30
1 1 <%= error_messages_for 'problem' %>
2 2
3 3 <!--[form:problem]-->
4 4 <p><label for="problem_name">Name</label><br/>
5 - <%= text_field 'problem', 'name' %></p>
5 + <%= text_field 'problem', 'name' %> Do not directly edit the problem name, unless you know what you are doing. If you want to change the name, use the name change button in the problem management menu instead.
6 + </p>
6 7
7 8 <p><label for="problem_full_name">Full name</label><br/>
8 9 <%= text_field 'problem', 'full_name' %></p>
9 10
10 11 <p><label for="problem_full_score">Full score</label><br/>
11 12 <%= text_field 'problem', 'full_score' %></p>
12 13
13 14 <p><label for="problem_date_added">Date added</label><br/>
14 15 <%= date_select 'problem', 'date_added' %></p>
15 16
16 17 <%
17 18 # TODO: these should be put in model Problem, but I can't think of
18 19 # nice default values for them. These values look fine only
19 20 # in this case (of lazily adding new problems).
20 21 @problem.available = true if @problem!=nil and @problem.available==nil
21 22 @problem.test_allowed = true if @problem!=nil and @problem.test_allowed==nil
22 23 @problem.output_only = false if @problem!=nil and @problem.output_only==nil
23 24 %>
24 25
25 26 <p>
26 27 <label for="problem_available">Available?</label>
27 28 <%= check_box :problem, :available %>
28 29
29 30 <label for="problem_test_allowed">Test allowed?</label>
@@ -1,24 +1,24
1 1 <% for column in Problem.content_columns %>
2 2 <p>
3 3 <b><%= column.human_name %>:</b>
4 4 <%=h @problem.send(column.name) %>
5 5 </p>
6 6 <% end %>
7 7
8 8 <p>
9 9 <b>Description:</b><br/>
10 10 <% if @problem.description!=nil %>
11 11 <% if @problem.description.markdowned %>
12 12 <%= markdown(@problem.description.body) %>
13 13 <% else %>
14 14 <pre>
15 15 <%= @problem.description.body %>
16 16 </pre>
17 17 <% end %>
18 18 <% else %>
19 19 (not available)
20 20 <% end %>
21 21 </p>
22 22
23 23 <%= link_to 'Edit', :action => 'edit', :id => @problem %> |
24 - <%= link_to 'Back', :action => 'list' %>
24 + <%= link_to 'Back', problems_path %>
You need to be logged in to leave comments. Login now