Description:
fix utf8 for java
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r462:c960ef68f0b1 - - 2 files changed: 3 inserted, 1 deleted
@@ -42,49 +42,50 | |||
|
42 | 42 | # request.path!='/main/login' |
|
43 | 43 | # @hidelogin = true |
|
44 | 44 | # end |
|
45 | 45 | |
|
46 | 46 | @announcements = Announcement.find_for_frontpage |
|
47 | 47 | render :action => 'login', :layout => 'empty' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def list |
|
51 | 51 | prepare_list_information |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def help |
|
55 | 55 | @user = User.find(session[:user_id]) |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def submit |
|
59 | 59 | user = User.find(session[:user_id]) |
|
60 | 60 | |
|
61 | 61 | @submission = Submission.new |
|
62 | 62 | @submission.problem_id = params[:submission][:problem_id] |
|
63 | 63 | @submission.user = user |
|
64 | 64 | @submission.language_id = 0 |
|
65 | 65 | if (params['file']) and (params['file']!='') |
|
66 | - @submission.source = params['file'].read | |
|
66 | + @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) | |
|
67 | + @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') | |
|
67 | 68 | @submission.source_filename = params['file'].original_filename |
|
68 | 69 | end |
|
69 | 70 | @submission.submitted_at = Time.new.gmtime |
|
70 | 71 | @submission.ip_address = request.remote_ip |
|
71 | 72 | |
|
72 | 73 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
73 | 74 | @submission.errors.add_to_base "The contest is over." |
|
74 | 75 | prepare_list_information |
|
75 | 76 | render :action => 'list' and return |
|
76 | 77 | end |
|
77 | 78 | |
|
78 | 79 | if @submission.valid? |
|
79 | 80 | if @submission.save == false |
|
80 | 81 | flash[:notice] = 'Error saving your submission' |
|
81 | 82 | elsif Task.create(:submission_id => @submission.id, |
|
82 | 83 | :status => Task::STATUS_INQUEUE) == false |
|
83 | 84 | flash[:notice] = 'Error adding your submission to task queue' |
|
84 | 85 | end |
|
85 | 86 | else |
|
86 | 87 | prepare_list_information |
|
87 | 88 | render :action => 'list' and return |
|
88 | 89 | end |
|
89 | 90 | redirect_to :action => 'list' |
|
90 | 91 | end |
@@ -103,48 +103,49 | |||
|
103 | 103 | send_new_password_email(user) |
|
104 | 104 | flash[:notice] = 'New password has been mailed to you.' |
|
105 | 105 | end |
|
106 | 106 | else |
|
107 | 107 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
108 | 108 | end |
|
109 | 109 | redirect_to :action => 'forget' |
|
110 | 110 | end |
|
111 | 111 | |
|
112 | 112 | def profile |
|
113 | 113 | @user = User.find(params[:id]) |
|
114 | 114 | @submission = Submission.includes(:problem).where(user_id: params[:id]) |
|
115 | 115 | |
|
116 | 116 | range = 120 |
|
117 | 117 | @histogram = { data: Array.new(range,0), summary: {} } |
|
118 | 118 | @summary = {count: 0, solve: 0, attempt: 0} |
|
119 | 119 | problem = Hash.new(0) |
|
120 | 120 | |
|
121 | 121 | @submission.find_each do |sub| |
|
122 | 122 | #histogram |
|
123 | 123 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
124 | 124 | @histogram[:data][d.to_i] += 1 if d < range |
|
125 | 125 | |
|
126 | 126 | @summary[:count] += 1 |
|
127 | + next unless sub.problem | |
|
127 | 128 | problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max |
|
128 | 129 | end |
|
129 | 130 | |
|
130 | 131 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
131 | 132 | @summary[:attempt] = problem.count |
|
132 | 133 | problem.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
133 | 134 | end |
|
134 | 135 | |
|
135 | 136 | protected |
|
136 | 137 | |
|
137 | 138 | def verify_online_registration |
|
138 | 139 | if !GraderConfiguration['system.online_registration'] |
|
139 | 140 | redirect_to :controller => 'main', :action => 'login' |
|
140 | 141 | end |
|
141 | 142 | end |
|
142 | 143 | |
|
143 | 144 | def send_confirmation_email(user) |
|
144 | 145 | contest_name = GraderConfiguration['contest.name'] |
|
145 | 146 | activation_url = url_for(:action => 'confirm', |
|
146 | 147 | :login => user.login, |
|
147 | 148 | :activation => user.activation_key) |
|
148 | 149 | home_url = url_for(:controller => 'main', :action => 'index') |
|
149 | 150 | mail_subject = "[#{contest_name}] Confirmation" |
|
150 | 151 | mail_body = t('registration.email_body', { |
You need to be logged in to leave comments.
Login now