Description:
Merge pull request #6 from nattee/master update mail functionality. Update syntax for mail gem (we might need mor...
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r361:fae81d234a8a - - 8 files changed: 116 inserted, 10 deleted

@@ -0,0 +1,18
1 +
2 +
3 + = form_tag({action: :user_stat_max }) do
4 + .submitbox
5 + %table
6 + %tr
7 + %td{colspan: 6, style: 'font-weight: bold'} Query maximum score in submission range
8 + %tr
9 + %td{style: 'width: 120px; font-weight: bold'} Submission ID:
10 + %td{align: 'right'} From:
11 + %td= text_field_tag 'since_id', params[:since_id], style: 'width:40px'
12 + %td To:
13 + %td= text_field_tag 'until_id', params[:until_id], style: 'width:40px'
14 + %td= submit_tag 'query'
15 + %tr
16 + %td
17 + %td{colspan: 5} Leave blank for uncondition
18 +
@@ -0,0 +1,44
1 + %h1 User grading results
2 + %h2 Show max scores in submission range
3 +
4 + - if @problem and @problem.errors
5 + =error_messages_for 'problem'
6 +
7 + = render partial: 'submission_range'
8 +
9 + - if @log
10 + %h3 Import log
11 + %pre.import-log
12 + = @log
13 +
14 + %p= link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat
15 +
16 + %table.info
17 + %thead
18 + %tr.info-head
19 + %th User
20 + %th Name
21 + %th Activated?
22 + %th Logged in
23 + %th Contest(s)
24 + - @problems.each do |p|
25 + %th= p.name
26 + %th Total
27 + %th Passed
28 + %tbody
29 + - @scorearray.each do |sc|
30 + %tr{class: cycle('info-even','info-odd')}
31 + - total,num_passed = 0,0
32 + - sc.each_index do |i|
33 + - if i == 0
34 + %td= sc[i].login
35 + %td= sc[i].full_name
36 + %td= sc[i].activated
37 + %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no'
38 + %td= sc[i].contests.collect {|c| c.name}.join(', ')
39 + - else
40 + %td= sc[i][0]
41 + - total += sc[i][0]
42 + - num_passed += 1 if sc[i][1]
43 + %td= total
44 + %td= num_passed
@@ -120,30 +120,51
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
139 + @scorearray << ustat
140 + end
141 + end
142 +
143 + def user_stat_max
144 + @problems = Problem.find_available_problems
145 + @users = User.find(:all, :include => [:contests, :contest_stat])
146 + @scorearray = Array.new
147 + #set up range from param
148 + since_id = params.fetch(:since_id, 0).to_i
149 + until_id = params.fetch(:until_id, 0).to_i
150 + @users.each do |u|
151 + ustat = Array.new
152 + ustat[0] = u
153 + @problems.each do |p|
154 + max_points = 0
155 + Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
156 + max_points = sub.points if sub and sub.points and (sub.points > max_points)
157 + end
158 + ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
138 end
159 end
139 @scorearray << ustat
160 @scorearray << ustat
140 end
161 end
141 end
162 end
142
163
143 def import
164 def import
144 if params[:file]==''
165 if params[:file]==''
145 flash[:notice] = 'Error importing no file'
166 flash[:notice] = 'Error importing no file'
146 redirect_to :action => 'list' and return
167 redirect_to :action => 'list' and return
147 end
168 end
148 import_from_file(params[:file])
169 import_from_file(params[:file])
149 end
170 end
@@ -120,37 +120,37
120 contest_name = GraderConfiguration['contest.name']
120 contest_name = GraderConfiguration['contest.name']
121 activation_url = url_for(:action => 'confirm',
121 activation_url = url_for(:action => 'confirm',
122 :login => user.login,
122 :login => user.login,
123 :activation => user.activation_key)
123 :activation => user.activation_key)
124 home_url = url_for(:controller => 'main', :action => 'index')
124 home_url = url_for(:controller => 'main', :action => 'index')
125 mail_subject = "[#{contest_name}] Confirmation"
125 mail_subject = "[#{contest_name}] Confirmation"
126 mail_body = t('registration.email_body', {
126 mail_body = t('registration.email_body', {
127 :full_name => user.full_name,
127 :full_name => user.full_name,
128 :contest_name => contest_name,
128 :contest_name => contest_name,
129 :login => user.login,
129 :login => user.login,
130 :password => user.password,
130 :password => user.password,
131 :activation_url => activation_url,
131 :activation_url => activation_url,
132 - :admin_email => admin_email
132 + :admin_email => GraderConfiguration['system.admin_email']
133 })
133 })
134
134
135 logger.info mail_body
135 logger.info mail_body
136
136
137 send_mail(user.email, mail_subject, mail_body)
137 send_mail(user.email, mail_subject, mail_body)
138 end
138 end
139
139
140 def send_new_password_email(user)
140 def send_new_password_email(user)
141 contest_name = GraderConfiguration['contest.name']
141 contest_name = GraderConfiguration['contest.name']
142 mail_subject = "[#{contest_name}] Password recovery"
142 mail_subject = "[#{contest_name}] Password recovery"
143 mail_body = t('registration.password_retrieval.email_body', {
143 mail_body = t('registration.password_retrieval.email_body', {
144 :full_name => user.full_name,
144 :full_name => user.full_name,
145 :contest_name => contest_name,
145 :contest_name => contest_name,
146 :login => user.login,
146 :login => user.login,
147 :password => user.password,
147 :password => user.password,
148 - :admin_email => admin_email
148 + :admin_email => GraderConfiguration['system.admin_email']
149 })
149 })
150
150
151 logger.info mail_body
151 logger.info mail_body
152
152
153 send_mail(user.email, mail_subject, mail_body)
153 send_mail(user.email, mail_subject, mail_body)
154 end
154 end
155
155
156 end
156 end
@@ -104,25 +104,25
104
104
105 contest_name = GraderConfiguration['contest.name']
105 contest_name = GraderConfiguration['contest.name']
106
106
107 #
107 #
108 # build real title bar
108 # build real title bar
109 result = <<TITLEBAR
109 result = <<TITLEBAR
110 <div class="title">
110 <div class="title">
111 <table>
111 <table>
112 #{header}
112 #{header}
113 <tr>
113 <tr>
114 <td class="left-col">
114 <td class="left-col">
115 #{user.full_name}<br/>
115 #{user.full_name}<br/>
116 - #{t 'title_bar.current_time'} #{format_short_time(Time.new)}
116 + #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)}
117 #{time_left}
117 #{time_left}
118 <br/>
118 <br/>
119 </td>
119 </td>
120 <td class="right-col">#{contest_name}</td>
120 <td class="right-col">#{contest_name}</td>
121 </tr>
121 </tr>
122 </table>
122 </table>
123 </div>
123 </div>
124 TITLEBAR
124 TITLEBAR
125 result.html_safe
125 result.html_safe
126 end
126 end
127
127
128 def markdown(text)
128 def markdown(text)
@@ -25,24 +25,31
25
25
26 def self.find_all_last_by_problem(problem_id)
26 def self.find_all_last_by_problem(problem_id)
27 # need to put in SQL command, maybe there's a better way
27 # need to put in SQL command, maybe there's a better way
28 Submission.find_by_sql("SELECT * FROM submissions " +
28 Submission.find_by_sql("SELECT * FROM submissions " +
29 "WHERE id = " +
29 "WHERE id = " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
31 "WHERE subs.user_id = submissions.user_id AND " +
31 "WHERE subs.user_id = submissions.user_id AND " +
32 "problem_id = " + problem_id.to_s + " " +
32 "problem_id = " + problem_id.to_s + " " +
33 "GROUP BY user_id) " +
33 "GROUP BY user_id) " +
34 "ORDER BY user_id")
34 "ORDER BY user_id")
35 end
35 end
36
36
37 + def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
38 + records = Submission.where(problem_id: problem_id,user_id: user_id)
39 + records = records.where('id >= ?',since_id) if since_id > 0
40 + records = records.where('id <= ?',until_id) if until_id > 0
41 + records.all
42 + end
43 +
37 def self.find_last_for_all_available_problems(user_id)
44 def self.find_last_for_all_available_problems(user_id)
38 submissions = Array.new
45 submissions = Array.new
39 problems = Problem.find_available_problems
46 problems = Problem.find_available_problems
40 problems.each do |problem|
47 problems.each do |problem|
41 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
48 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
42 submissions << sub if sub!=nil
49 submissions << sub if sub!=nil
43 end
50 end
44 submissions
51 submissions
45 end
52 end
46
53
47 def self.find_by_user_problem_number(user_id, problem_id, number)
54 def self.find_by_user_problem_number(user_id, problem_id, number)
48 Submission.find(:first,
55 Submission.find(:first,
@@ -1,13 +1,18
1 <h1>User grading results</h1>
1 <h1>User grading results</h1>
2 + <h2>Show scores from latest submission</h2>
3 +
4 + <%= render 'submission_range' %>
5 +
6 + <p>Latest scores</p>
2
7
3 <table class="info">
8 <table class="info">
4 <tr class="info-head">
9 <tr class="info-head">
5 <th>User</th>
10 <th>User</th>
6 <th>Name</th>
11 <th>Name</th>
7 <th>Activated?</th>
12 <th>Activated?</th>
8 <th>Logged in</th>
13 <th>Logged in</th>
9 <th>Contest(s)</th>
14 <th>Contest(s)</th>
10 <% @problems.each do |p| %>
15 <% @problems.each do |p| %>
11 <th><%= p.name %></th>
16 <th><%= p.name %></th>
12 <% end %>
17 <% end %>
13 <th>Total</th>
18 <th>Total</th>
@@ -13,18 +13,29
13 --------------------------
13 --------------------------
14 "
14 "
15 return true
15 return true
16 end
16 end
17
17
18 mail = Mail.new do
18 mail = Mail.new do
19 from mail_from
19 from mail_from
20 to mail_to
20 to mail_to
21 subject mail_subject
21 subject mail_subject
22 body mail_body
22 body mail_body
23 end
23 end
24
24
25 - mail.delivery_settings = { :address => smtp_server }
25 + mail_option = {
26 + :address => smtp_server,
27 + # :domain => nil,
28 + # :port => 25,
29 + # :user_name => nil,
30 + # :password => nil,
31 + # :authentication=>'plain',
32 + # :enable_starttls_auto => true
33 + }
34 +
35 + mail.delivery_method :smtp, mail_option
36 +
26 mail.deliver
37 mail.deliver
27 end
38 end
28
39
29 end
40 end
30
41
You need to be logged in to leave comments. Login now