Description:
fixed line cut error when create list of users
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@278 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
r139:67af2726d112 - - 1 file changed: 1 inserted, 1 deleted
@@ -1,135 +1,135 | |||||
|
1 | class UserAdminController < ApplicationController |
|
1 | class UserAdminController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :admin_authorization |
|
3 | before_filter :admin_authorization |
|
4 |
|
4 | ||
|
5 | def index |
|
5 | def index |
|
6 | list |
|
6 | list |
|
7 | render :action => 'list' |
|
7 | render :action => 'list' |
|
8 | end |
|
8 | end |
|
9 |
|
9 | ||
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | :redirect_to => { :action => :list } |
|
12 | :redirect_to => { :action => :list } |
|
13 |
|
13 | ||
|
14 | def list |
|
14 | def list |
|
15 | @users = User.find(:all) |
|
15 | @users = User.find(:all) |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | def show |
|
18 | def show |
|
19 | @user = User.find(params[:id]) |
|
19 | @user = User.find(params[:id]) |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | def new |
|
22 | def new |
|
23 | @user = User.new |
|
23 | @user = User.new |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def create |
|
26 | def create |
|
27 | @user = User.new(params[:user]) |
|
27 | @user = User.new(params[:user]) |
|
28 | if @user.save |
|
28 | if @user.save |
|
29 | flash[:notice] = 'User was successfully created.' |
|
29 | flash[:notice] = 'User was successfully created.' |
|
30 | redirect_to :action => 'list' |
|
30 | redirect_to :action => 'list' |
|
31 | else |
|
31 | else |
|
32 | render :action => 'new' |
|
32 | render :action => 'new' |
|
33 | end |
|
33 | end |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | def create_from_list |
|
36 | def create_from_list |
|
37 | lines = params[:user_list] |
|
37 | lines = params[:user_list] |
|
38 | lines.split("\n").each do |line| |
|
38 | lines.split("\n").each do |line| |
|
39 | - items = line.split(',') |
|
39 | + items = line.chomp.split(',') |
|
40 | if items.length==4 |
|
40 | if items.length==4 |
|
41 | user = User.new |
|
41 | user = User.new |
|
42 | user.login = items[0] |
|
42 | user.login = items[0] |
|
43 | user.full_name = items[1] |
|
43 | user.full_name = items[1] |
|
44 | user.alias = items[2] |
|
44 | user.alias = items[2] |
|
45 | user.password = items[3] |
|
45 | user.password = items[3] |
|
46 | user.password_confirmation = items[3] |
|
46 | user.password_confirmation = items[3] |
|
47 | user.save |
|
47 | user.save |
|
48 | end |
|
48 | end |
|
49 | end |
|
49 | end |
|
50 | redirect_to :action => 'list' |
|
50 | redirect_to :action => 'list' |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 | def edit |
|
53 | def edit |
|
54 | @user = User.find(params[:id]) |
|
54 | @user = User.find(params[:id]) |
|
55 | end |
|
55 | end |
|
56 |
|
56 | ||
|
57 | def update |
|
57 | def update |
|
58 | @user = User.find(params[:id]) |
|
58 | @user = User.find(params[:id]) |
|
59 | if @user.update_attributes(params[:user]) |
|
59 | if @user.update_attributes(params[:user]) |
|
60 | flash[:notice] = 'User was successfully updated.' |
|
60 | flash[:notice] = 'User was successfully updated.' |
|
61 | redirect_to :action => 'show', :id => @user |
|
61 | redirect_to :action => 'show', :id => @user |
|
62 | else |
|
62 | else |
|
63 | render :action => 'edit' |
|
63 | render :action => 'edit' |
|
64 | end |
|
64 | end |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | def destroy |
|
67 | def destroy |
|
68 | User.find(params[:id]).destroy |
|
68 | User.find(params[:id]).destroy |
|
69 | redirect_to :action => 'list' |
|
69 | redirect_to :action => 'list' |
|
70 | end |
|
70 | end |
|
71 |
|
71 | ||
|
72 | def user_stat |
|
72 | def user_stat |
|
73 | @problems = Problem.find_available_problems |
|
73 | @problems = Problem.find_available_problems |
|
74 | @users = User.find(:all) |
|
74 | @users = User.find(:all) |
|
75 | @scorearray = Array.new |
|
75 | @scorearray = Array.new |
|
76 | @users.each do |u| |
|
76 | @users.each do |u| |
|
77 | ustat = Array.new |
|
77 | ustat = Array.new |
|
78 | ustat[0] = u.login |
|
78 | ustat[0] = u.login |
|
79 | ustat[1] = u.full_name |
|
79 | ustat[1] = u.full_name |
|
80 | @problems.each do |p| |
|
80 | @problems.each do |p| |
|
81 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
81 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
82 | if (sub!=nil) and (sub.points!=nil) |
|
82 | if (sub!=nil) and (sub.points!=nil) |
|
83 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
83 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
84 | else |
|
84 | else |
|
85 | ustat << [0,false] |
|
85 | ustat << [0,false] |
|
86 | end |
|
86 | end |
|
87 | end |
|
87 | end |
|
88 | @scorearray << ustat |
|
88 | @scorearray << ustat |
|
89 | end |
|
89 | end |
|
90 | end |
|
90 | end |
|
91 |
|
91 | ||
|
92 | def import |
|
92 | def import |
|
93 | if params[:file]=='' |
|
93 | if params[:file]=='' |
|
94 | flash[:notice] = 'Error importing no file' |
|
94 | flash[:notice] = 'Error importing no file' |
|
95 | redirect_to :action => 'list' and return |
|
95 | redirect_to :action => 'list' and return |
|
96 | end |
|
96 | end |
|
97 | import_from_file(params[:file]) |
|
97 | import_from_file(params[:file]) |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | protected |
|
100 | protected |
|
101 |
|
101 | ||
|
102 | def import_from_file(f) |
|
102 | def import_from_file(f) |
|
103 | data_hash = YAML.load(f) |
|
103 | data_hash = YAML.load(f) |
|
104 | @import_log = "" |
|
104 | @import_log = "" |
|
105 |
|
105 | ||
|
106 | country_data = data_hash[:countries] |
|
106 | country_data = data_hash[:countries] |
|
107 | site_data = data_hash[:sites] |
|
107 | site_data = data_hash[:sites] |
|
108 | user_data = data_hash[:users] |
|
108 | user_data = data_hash[:users] |
|
109 |
|
109 | ||
|
110 | # import country |
|
110 | # import country |
|
111 | countries = {} |
|
111 | countries = {} |
|
112 | country_data.each_pair do |id,country| |
|
112 | country_data.each_pair do |id,country| |
|
113 | c = Country.find_by_name(country[:name]) |
|
113 | c = Country.find_by_name(country[:name]) |
|
114 | if c!=nil |
|
114 | if c!=nil |
|
115 | countries[id] = c |
|
115 | countries[id] = c |
|
116 | @import_log << "Found #{country[:name]}\n" |
|
116 | @import_log << "Found #{country[:name]}\n" |
|
117 | else |
|
117 | else |
|
118 | countries[id] = Country.new(:name => country[:name]) |
|
118 | countries[id] = Country.new(:name => country[:name]) |
|
119 | countries[id].save |
|
119 | countries[id].save |
|
120 | @import_log << "Created #{country[:name]}\n" |
|
120 | @import_log << "Created #{country[:name]}\n" |
|
121 | end |
|
121 | end |
|
122 | end |
|
122 | end |
|
123 |
|
123 | ||
|
124 | # import sites |
|
124 | # import sites |
|
125 | sites = {} |
|
125 | sites = {} |
|
126 | site_data.each_pair do |id,site| |
|
126 | site_data.each_pair do |id,site| |
|
127 | s = Site.find_by_name(site[:name]) |
|
127 | s = Site.find_by_name(site[:name]) |
|
128 | if s!=nil |
|
128 | if s!=nil |
|
129 | @import_log << "Found #{site[:name]}\n" |
|
129 | @import_log << "Found #{site[:name]}\n" |
|
130 | else |
|
130 | else |
|
131 | s = Site.new(:name => site[:name]) |
|
131 | s = Site.new(:name => site[:name]) |
|
132 | @import_log << "Created #{site[:name]}\n" |
|
132 | @import_log << "Created #{site[:name]}\n" |
|
133 | end |
|
133 | end |
|
134 | s.password = site[:password] |
|
134 | s.password = site[:password] |
|
135 | s.country = countries[site[:country_id]] |
|
135 | s.country = countries[site[:country_id]] |
You need to be logged in to leave comments.
Login now