Description:
fixed form_tag bug in views
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r340:f512a445945b - - 2 files changed: 12 inserted, 12 deleted

@@ -108,97 +108,97
108
108
109 def update
109 def update
110 @user = User.find(params[:id])
110 @user = User.find(params[:id])
111 if @user.update_attributes(params[:user])
111 if @user.update_attributes(params[:user])
112 flash[:notice] = 'User was successfully updated.'
112 flash[:notice] = 'User was successfully updated.'
113 redirect_to :action => 'show', :id => @user
113 redirect_to :action => 'show', :id => @user
114 else
114 else
115 render :action => 'edit'
115 render :action => 'edit'
116 end
116 end
117 end
117 end
118
118
119 def destroy
119 def destroy
120 User.find(params[:id]).destroy
120 User.find(params[:id]).destroy
121 redirect_to :action => 'list'
121 redirect_to :action => 'list'
122 end
122 end
123
123
124 def user_stat
124 def user_stat
125 @problems = Problem.find_available_problems
125 @problems = Problem.find_available_problems
126 @users = User.find(:all, :include => [:contests, :contest_stat])
126 @users = User.find(:all, :include => [:contests, :contest_stat])
127 @scorearray = Array.new
127 @scorearray = Array.new
128 @users.each do |u|
128 @users.each do |u|
129 ustat = Array.new
129 ustat = Array.new
130 ustat[0] = u
130 ustat[0] = u
131 @problems.each do |p|
131 @problems.each do |p|
132 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
132 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
133 if (sub!=nil) and (sub.points!=nil)
133 if (sub!=nil) and (sub.points!=nil)
134 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
134 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
135 else
135 else
136 ustat << [0,false]
136 ustat << [0,false]
137 end
137 end
138 end
138 end
139 @scorearray << ustat
139 @scorearray << ustat
140 end
140 end
141 end
141 end
142
142
143 def import
143 def import
144 if params[:file]==''
144 if params[:file]==''
145 flash[:notice] = 'Error importing no file'
145 flash[:notice] = 'Error importing no file'
146 redirect_to :action => 'list' and return
146 redirect_to :action => 'list' and return
147 end
147 end
148 import_from_file(params[:file])
148 import_from_file(params[:file])
149 end
149 end
150
150
151 def random_all_passwords
151 def random_all_passwords
152 users = User.find(:all)
152 users = User.find(:all)
153 @prefix = params[:prefix] || ''
153 @prefix = params[:prefix] || ''
154 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
154 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
155 @changed = false
155 @changed = false
156 - if request.request_method == :post
156 + if request.request_method == 'POST'
157 @non_admin_users.each do |user|
157 @non_admin_users.each do |user|
158 password = random_password
158 password = random_password
159 user.password = password
159 user.password = password
160 user.password_confirmation = password
160 user.password_confirmation = password
161 user.save
161 user.save
162 end
162 end
163 @changed = true
163 @changed = true
164 end
164 end
165 end
165 end
166
166
167 # contest management
167 # contest management
168
168
169 def contests
169 def contests
170 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
170 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
171 @contests = Contest.enabled
171 @contests = Contest.enabled
172 end
172 end
173
173
174 def assign_from_list
174 def assign_from_list
175 contest_id = params[:users_contest_id]
175 contest_id = params[:users_contest_id]
176 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
176 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
177 contest = Contest.find(params[:new_contest][:id])
177 contest = Contest.find(params[:new_contest][:id])
178 if !contest
178 if !contest
179 flash[:notice] = 'Error: no contest'
179 flash[:notice] = 'Error: no contest'
180 redirect_to :action => 'contests', :id =>contest_id
180 redirect_to :action => 'contests', :id =>contest_id
181 end
181 end
182
182
183 note = []
183 note = []
184 users.each do |u|
184 users.each do |u|
185 u.contests = [contest]
185 u.contests = [contest]
186 note << u.login
186 note << u.login
187 end
187 end
188 flash[:notice] = 'User(s) ' + note.join(', ') +
188 flash[:notice] = 'User(s) ' + note.join(', ') +
189 " were successfully reassigned to #{contest.title}."
189 " were successfully reassigned to #{contest.title}."
190 redirect_to :action => 'contests', :id =>contest.id
190 redirect_to :action => 'contests', :id =>contest.id
191 end
191 end
192
192
193 def add_to_contest
193 def add_to_contest
194 user = User.find(params[:id])
194 user = User.find(params[:id])
195 contest = Contest.find(params[:contest_id])
195 contest = Contest.find(params[:contest_id])
196 if user and contest
196 if user and contest
197 user.contests << contest
197 user.contests << contest
198 end
198 end
199 redirect_to :action => 'list'
199 redirect_to :action => 'list'
200 end
200 end
201
201
202 def remove_from_contest
202 def remove_from_contest
203 user = User.find(params[:id])
203 user = User.find(params[:id])
204 contest = Contest.find(params[:contest_id])
204 contest = Contest.find(params[:contest_id])
@@ -1,39 +1,39
1 %h1 Random user passwords
1 %h1 Random user passwords
2
2
3 - -if @changed
3 + - if @changed
4 %p
4 %p
5 %b Done!
5 %b Done!
6 Here's a new password list.
6 Here's a new password list.
7 Go back to
7 Go back to
8 = (link_to '[user list]', :action => 'index') + '.'
8 = (link_to '[user list]', :action => 'index') + '.'
9 %br/
9 %br/
10 %table
10 %table
11 %tr
11 %tr
12 %th Login
12 %th Login
13 %th Fullname
13 %th Fullname
14 %th Password
14 %th Password
15 - -for u in @non_admin_users
15 + - for u in @non_admin_users
16 %tr
16 %tr
17 %td= u.login
17 %td= u.login
18 %td= u.full_name
18 %td= u.full_name
19 %td
19 %td
20 %tt= u.password
20 %tt= u.password
21
21
22 - -else
22 + - else
23 - -if @prefix!=''
23 + - if @prefix!=''
24 Current prefix:
24 Current prefix:
25 = @prefix
25 = @prefix
26 - -form_tag((url_for :action => 'random_all_passwords'), :method => 'get') do
26 + = form_tag((url_for :action => 'random_all_passwords'), :method => 'get') do
27 Change prefix
27 Change prefix
28 - =text_field_tag 'prefix'
28 + = text_field_tag 'prefix'
29 - =submit_tag 'Change'
29 + = submit_tag 'Change'
30
30
31 This will change passwords of the following users.
31 This will change passwords of the following users.
32 %ul
32 %ul
33 - -for u in @non_admin_users
33 + - for u in @non_admin_users
34 %li= u.login
34 %li= u.login
35
35
36 - -form_tag((url_for :action => 'random_all_passwords'), :method => 'post') do
36 + = form_tag((url_for :action => 'random_all_passwords'), :method => 'post') do
37 - =hidden_field_tag 'prefix', @prefix
37 + = hidden_field_tag 'prefix', @prefix
38 Are you sure?
38 Are you sure?
39 - =submit_tag 'Go ahead'
39 + = submit_tag 'Go ahead'
You need to be logged in to leave comments. Login now