Description:
moved to ror 2.0.2, add user rel to model submission git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@3 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r1:82d71b81c3b0 - - 7 files changed: 5 inserted, 10 deleted

@@ -1,68 +1,66
1 class ProblemsController < ApplicationController
1 class ProblemsController < ApplicationController
2
2
3 before_filter :authenticate, :authorization
3 before_filter :authenticate, :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 - @problem_pages, @problems = paginate(:problems,
15 + @problems = Problem.find(:all, :order => 'date_added DESC')
16 - :per_page => 10,
17 - :order => 'date_added DESC')
18 end
16 end
19
17
20 def show
18 def show
21 @problem = Problem.find(params[:id])
19 @problem = Problem.find(params[:id])
22 end
20 end
23
21
24 def new
22 def new
25 @problem = Problem.new
23 @problem = Problem.new
26 end
24 end
27
25
28 def create
26 def create
29 @problem = Problem.new(params[:problem])
27 @problem = Problem.new(params[:problem])
30 if @problem.save
28 if @problem.save
31 flash[:notice] = 'Problem was successfully created.'
29 flash[:notice] = 'Problem was successfully created.'
32 redirect_to :action => 'list'
30 redirect_to :action => 'list'
33 else
31 else
34 render :action => 'new'
32 render :action => 'new'
35 end
33 end
36 end
34 end
37
35
38 def edit
36 def edit
39 @problem = Problem.find(params[:id])
37 @problem = Problem.find(params[:id])
40 end
38 end
41
39
42 def update
40 def update
43 @problem = Problem.find(params[:id])
41 @problem = Problem.find(params[:id])
44 if @problem.update_attributes(params[:problem])
42 if @problem.update_attributes(params[:problem])
45 flash[:notice] = 'Problem was successfully updated.'
43 flash[:notice] = 'Problem was successfully updated.'
46 redirect_to :action => 'show', :id => @problem
44 redirect_to :action => 'show', :id => @problem
47 else
45 else
48 render :action => 'edit'
46 render :action => 'edit'
49 end
47 end
50 end
48 end
51
49
52 def destroy
50 def destroy
53 Problem.find(params[:id]).destroy
51 Problem.find(params[:id]).destroy
54 redirect_to :action => 'list'
52 redirect_to :action => 'list'
55 end
53 end
56
54
57 def toggle_avail
55 def toggle_avail
58 problem = Problem.find(params[:id])
56 problem = Problem.find(params[:id])
59 problem.available = !(problem.available)
57 problem.available = !(problem.available)
60 problem.save
58 problem.save
61 redirect_to :action => 'list'
59 redirect_to :action => 'list'
62 end
60 end
63
61
64 def stat
62 def stat
65 @problem = Problem.find(params[:id])
63 @problem = Problem.find(params[:id])
66 @submissions = Submission.find_last_by_problem(params[:id])
64 @submissions = Submission.find_last_by_problem(params[:id])
67 end
65 end
68 end
66 end
@@ -1,73 +1,73
1 class UserAdminController < ApplicationController
1 class UserAdminController < ApplicationController
2
2
3 before_filter :authenticate, :authorization
3 before_filter :authenticate, :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 - @user_pages, @users = paginate :users, :per_page => 50
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 edit
36 def edit
37 @user = User.find(params[:id])
37 @user = User.find(params[:id])
38 end
38 end
39
39
40 def update
40 def update
41 @user = User.find(params[:id])
41 @user = User.find(params[:id])
42 if @user.update_attributes(params[:user])
42 if @user.update_attributes(params[:user])
43 flash[:notice] = 'User was successfully updated.'
43 flash[:notice] = 'User was successfully updated.'
44 redirect_to :action => 'show', :id => @user
44 redirect_to :action => 'show', :id => @user
45 else
45 else
46 render :action => 'edit'
46 render :action => 'edit'
47 end
47 end
48 end
48 end
49
49
50 def destroy
50 def destroy
51 User.find(params[:id]).destroy
51 User.find(params[:id]).destroy
52 redirect_to :action => 'list'
52 redirect_to :action => 'list'
53 end
53 end
54
54
55 def user_stat
55 def user_stat
56 @problems = Problem.find_available_problems
56 @problems = Problem.find_available_problems
57 @users = User.find(:all)
57 @users = User.find(:all)
58 @scorearray = Array.new
58 @scorearray = Array.new
59 @users.each do |u|
59 @users.each do |u|
60 ustat = Array.new
60 ustat = Array.new
61 ustat[0] = u.login
61 ustat[0] = u.login
62 @problems.each do |p|
62 @problems.each do |p|
63 c, sub = Submission.find_by_user_and_problem(u.id,p.id)
63 c, sub = Submission.find_by_user_and_problem(u.id,p.id)
64 if c!=0
64 if c!=0
65 ustat << sub.points
65 ustat << sub.points
66 else
66 else
67 ustat << 0
67 ustat << 0
68 end
68 end
69 end
69 end
70 @scorearray << ustat
70 @scorearray << ustat
71 end
71 end
72 end
72 end
73 end
73 end
@@ -1,64 +1,65
1 class Submission < ActiveRecord::Base
1 class Submission < ActiveRecord::Base
2
2
3 belongs_to :language
3 belongs_to :language
4 belongs_to :problem
4 belongs_to :problem
5 + belongs_to :user
5
6
6 def self.find_by_user_and_problem(user_id, problem_id)
7 def self.find_by_user_and_problem(user_id, problem_id)
7 subcount = count(:conditions => "user_id = #{user_id} AND problem_id = #{problem_id}")
8 subcount = count(:conditions => "user_id = #{user_id} AND problem_id = #{problem_id}")
8 if subcount != 0
9 if subcount != 0
9 last_sub = find(:first,
10 last_sub = find(:first,
10 :conditions => {:user_id => user_id,
11 :conditions => {:user_id => user_id,
11 :problem_id => problem_id},
12 :problem_id => problem_id},
12 :order => 'submitted_at DESC')
13 :order => 'submitted_at DESC')
13 else
14 else
14 last_sub = nil
15 last_sub = nil
15 end
16 end
16 return subcount, last_sub
17 return subcount, last_sub
17 end
18 end
18
19
19 def self.find_last_by_problem(problem_id)
20 def self.find_last_by_problem(problem_id)
20 # need to put in SQL command, maybe there's a better way
21 # need to put in SQL command, maybe there's a better way
21 Submission.find_by_sql("SELECT * FROM submissions " +
22 Submission.find_by_sql("SELECT * FROM submissions " +
22 "WHERE id = " +
23 "WHERE id = " +
23 "(SELECT MAX(id) FROM submissions AS subs " +
24 "(SELECT MAX(id) FROM submissions AS subs " +
24 "WHERE subs.user_id = submissions.user_id AND " +
25 "WHERE subs.user_id = submissions.user_id AND " +
25 "problem_id = " + problem_id.to_s + " " +
26 "problem_id = " + problem_id.to_s + " " +
26 "GROUP BY user_id)")
27 "GROUP BY user_id)")
27 end
28 end
28
29
29 def self.find_option_in_source(option, source)
30 def self.find_option_in_source(option, source)
30 i = 0
31 i = 0
31 source.each_line do |s|
32 source.each_line do |s|
32 if s =~ option
33 if s =~ option
33 words = s.split
34 words = s.split
34 return words[1]
35 return words[1]
35 end
36 end
36 i = i + 1
37 i = i + 1
37 if i==10
38 if i==10
38 return nil
39 return nil
39 end
40 end
40 end
41 end
41 return nil
42 return nil
42 end
43 end
43
44
44 def self.find_language_in_source(source)
45 def self.find_language_in_source(source)
45 langopt = find_option_in_source(/^LANG:/,source)
46 langopt = find_option_in_source(/^LANG:/,source)
46 if language = Language.find_by_name(langopt)
47 if language = Language.find_by_name(langopt)
47 return language
48 return language
48 elsif language = Language.find_by_pretty_name(langopt)
49 elsif language = Language.find_by_pretty_name(langopt)
49 return language
50 return language
50 else
51 else
51 return nil
52 return nil
52 end
53 end
53 end
54 end
54
55
55 def self.find_problem_in_source(source)
56 def self.find_problem_in_source(source)
56 prob_opt = find_option_in_source(/^TASK:/,source)
57 prob_opt = find_option_in_source(/^TASK:/,source)
57 if problem = Problem.find_by_name(prob_opt)
58 if problem = Problem.find_by_name(prob_opt)
58 return problem
59 return problem
59 else
60 else
60 return nil
61 return nil
61 end
62 end
62 end
63 end
63
64
64 end
65 end
@@ -1,33 +1,31
1 <h1>Listing problems</h1>
1 <h1>Listing problems</h1>
2
2
3 <div class="usermenu">
3 <div class="usermenu">
4 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
4 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
5 </div>
5 </div>
6
6
7 <table>
7 <table>
8 <tr>
8 <tr>
9 <% for column in Problem.content_columns %>
9 <% for column in Problem.content_columns %>
10 <th><%= column.human_name %></th>
10 <th><%= column.human_name %></th>
11 <% end %>
11 <% end %>
12 </tr>
12 </tr>
13
13
14 <% for problem in @problems %>
14 <% for problem in @problems %>
15 <tr>
15 <tr>
16 <% for column in Problem.content_columns %>
16 <% for column in Problem.content_columns %>
17 <td><%=h problem.send(column.name) %></td>
17 <td><%=h problem.send(column.name) %></td>
18 <% end %>
18 <% end %>
19 <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td>
19 <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td>
20 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
20 <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td>
21 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
21 <td><%= link_to '[Show]', :action => 'show', :id => problem %></td>
22 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
22 <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td>
23 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
23 <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td>
24 </tr>
24 </tr>
25 <% end %>
25 <% end %>
26 </table>
26 </table>
27
27
28 - <%= link_to 'Previous page', { :page => @problem_pages.current.previous } if @problem_pages.current.previous %>
29 - <%= link_to 'Next page', { :page => @problem_pages.current.next } if @problem_pages.current.next %>
30
28
31 <br />
29 <br />
32
30
33 <%= link_to 'New problem', :action => 'new' %>
31 <%= link_to 'New problem', :action => 'new' %>
@@ -1,55 +1,53
1 <h1>Listing users</h1>
1 <h1>Listing users</h1>
2
2
3 <div class="usermenu">
3 <div class="usermenu">
4 <%= link_to 'Stat', :action => 'user_stat' %>
4 <%= link_to 'Stat', :action => 'user_stat' %>
5 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
5 <%= link_to 'Main', :controller => 'main', :action => 'list' %>
6 </div>
6 </div>
7
7
8 <div style="border: solid 1px; margin: 2px">
8 <div style="border: solid 1px; margin: 2px">
9 <b>Quick add</b>
9 <b>Quick add</b>
10 <% form_tag :action => 'create' do %>
10 <% form_tag :action => 'create' do %>
11 <table border="0">
11 <table border="0">
12 <tr>
12 <tr>
13 <td><label for="user_name">Login</label></td>
13 <td><label for="user_name">Login</label></td>
14 <td><label for="user_name">Full name</label></td>
14 <td><label for="user_name">Full name</label></td>
15 <td><label for="user_alias">Alias</label></td>
15 <td><label for="user_alias">Alias</label></td>
16 <td><label for="password">Password</label></td>
16 <td><label for="password">Password</label></td>
17 <td><label for="password_confirmation">confirm</label></td>
17 <td><label for="password_confirmation">confirm</label></td>
18 </tr>
18 </tr>
19 <tr>
19 <tr>
20 <td><%= text_field 'user', 'login', :size => 10 %></td>
20 <td><%= text_field 'user', 'login', :size => 10 %></td>
21 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
21 <td><%= text_field 'user', 'full_name', :size => 30 %></td>
22 <td><%= text_field 'user', 'alias', :size => 10 %></td>
22 <td><%= text_field 'user', 'alias', :size => 10 %></td>
23 <td><%= password_field 'user', 'password', :size => 10 %></td>
23 <td><%= password_field 'user', 'password', :size => 10 %></td>
24 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
24 <td><%= password_field 'user', 'password_confirmation', :size => 10 %></td>
25 <td><%= submit_tag "Create" %></td>
25 <td><%= submit_tag "Create" %></td>
26 </tr></table>
26 </tr></table>
27 <% end %>
27 <% end %>
28
28
29 </div>
29 </div>
30
30
31 <table>
31 <table>
32 <tr>
32 <tr>
33 <% for column in User.content_columns %>
33 <% for column in User.content_columns %>
34 <th><%= column.human_name %></th>
34 <th><%= column.human_name %></th>
35 <% end %>
35 <% end %>
36 </tr>
36 </tr>
37
37
38 <% for user in @users %>
38 <% for user in @users %>
39 <tr>
39 <tr>
40 <% for column in User.content_columns %>
40 <% for column in User.content_columns %>
41 <td><%=h user.send(column.name) %></td>
41 <td><%=h user.send(column.name) %></td>
42 <% end %>
42 <% end %>
43 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
43 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
44 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
44 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
45 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
45 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
46 </tr>
46 </tr>
47 <% end %>
47 <% end %>
48 </table>
48 </table>
49
49
50 - <%= link_to 'Previous page', { :page => @user_pages.current.previous } if @user_pages.current.previous %>
51 - <%= link_to 'Next page', { :page => @user_pages.current.next } if @user_pages.current.next %>
52
50
53 <br />
51 <br />
54
52
55 <%= link_to 'New user', :action => 'new' %>
53 <%= link_to 'New user', :action => 'new' %>
@@ -1,60 +1,60
1 # Be sure to restart your web server when you modify this file.
1 # Be sure to restart your web server when you modify this file.
2
2
3 # Uncomment below to force Rails into production mode when
3 # Uncomment below to force Rails into production mode when
4 # you don't control web/app server and can't set it the proper way
4 # you don't control web/app server and can't set it the proper way
5 # ENV['RAILS_ENV'] ||= 'production'
5 # ENV['RAILS_ENV'] ||= 'production'
6
6
7 # Specifies gem version of Rails to use when vendor/rails is not present
7 # Specifies gem version of Rails to use when vendor/rails is not present
8 - RAILS_GEM_VERSION = '1.2.4' unless defined? RAILS_GEM_VERSION
8 + RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
9
9
10 # Bootstrap the Rails environment, frameworks, and default configuration
10 # Bootstrap the Rails environment, frameworks, and default configuration
11 require File.join(File.dirname(__FILE__), 'boot')
11 require File.join(File.dirname(__FILE__), 'boot')
12
12
13 Rails::Initializer.run do |config|
13 Rails::Initializer.run do |config|
14 # Settings in config/environments/* take precedence over those specified here
14 # Settings in config/environments/* take precedence over those specified here
15
15
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
16 # Skip frameworks you're not going to use (only works if using vendor/rails)
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
17 # config.frameworks -= [ :action_web_service, :action_mailer ]
18
18
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
19 # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
20 # config.plugins = %W( exception_notification ssl_requirement )
20 # config.plugins = %W( exception_notification ssl_requirement )
21
21
22 # Add additional load paths for your own custom dirs
22 # Add additional load paths for your own custom dirs
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
23 # config.load_paths += %W( #{RAILS_ROOT}/extras )
24
24
25 # Force all environments to use the same logger level
25 # Force all environments to use the same logger level
26 # (by default production uses :info, the others :debug)
26 # (by default production uses :info, the others :debug)
27 # config.log_level = :debug
27 # config.log_level = :debug
28
28
29 # Use the database for sessions instead of the file system
29 # Use the database for sessions instead of the file system
30 # (create the session table with 'rake db:sessions:create')
30 # (create the session table with 'rake db:sessions:create')
31 config.action_controller.session_store = :active_record_store
31 config.action_controller.session_store = :active_record_store
32
32
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
33 # Use SQL instead of Active Record's schema dumper when creating the test database.
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
34 # This is necessary if your schema can't be completely dumped by the schema dumper,
35 # like if you have constraints or database-specific column types
35 # like if you have constraints or database-specific column types
36 # config.active_record.schema_format = :sql
36 # config.active_record.schema_format = :sql
37
37
38 # Activate observers that should always be running
38 # Activate observers that should always be running
39 # config.active_record.observers = :cacher, :garbage_collector
39 # config.active_record.observers = :cacher, :garbage_collector
40
40
41 # Make Active Record use UTC-base instead of local time
41 # Make Active Record use UTC-base instead of local time
42 config.active_record.default_timezone = :utc
42 config.active_record.default_timezone = :utc
43
43
44 # See Rails::Configuration for more options
44 # See Rails::Configuration for more options
45 end
45 end
46
46
47 # Add new inflection rules using the following format
47 # Add new inflection rules using the following format
48 # (all these examples are active by default):
48 # (all these examples are active by default):
49 # Inflector.inflections do |inflect|
49 # Inflector.inflections do |inflect|
50 # inflect.plural /^(ox)$/i, '\1en'
50 # inflect.plural /^(ox)$/i, '\1en'
51 # inflect.singular /^(ox)en/i, '\1'
51 # inflect.singular /^(ox)en/i, '\1'
52 # inflect.irregular 'person', 'people'
52 # inflect.irregular 'person', 'people'
53 # inflect.uncountable %w( fish sheep )
53 # inflect.uncountable %w( fish sheep )
54 # end
54 # end
55
55
56 # Add new mime types for use in respond_to blocks:
56 # Add new mime types for use in respond_to blocks:
57 # Mime::Type.register "text/richtext", :rtf
57 # Mime::Type.register "text/richtext", :rtf
58 # Mime::Type.register "application/x-mobile", :mobile
58 # Mime::Type.register "application/x-mobile", :mobile
59
59
60 # Include your application configuration below
60 # Include your application configuration below
@@ -1,21 +1,21
1 # Settings specified here will take precedence over those in config/environment.rb
1 # Settings specified here will take precedence over those in config/environment.rb
2
2
3 # In the development environment your application's code is reloaded on
3 # In the development environment your application's code is reloaded on
4 # every request. This slows down response time but is perfect for development
4 # every request. This slows down response time but is perfect for development
5 # since you don't have to restart the webserver when you make code changes.
5 # since you don't have to restart the webserver when you make code changes.
6 config.cache_classes = false
6 config.cache_classes = false
7
7
8 # Log error messages when you accidentally call methods on nil.
8 # Log error messages when you accidentally call methods on nil.
9 config.whiny_nils = true
9 config.whiny_nils = true
10
10
11 # Enable the breakpoint server that script/breakpointer connects to
11 # Enable the breakpoint server that script/breakpointer connects to
12 - config.breakpoint_server = true
12 + #config.breakpoint_server = true
13
13
14 # Show full error reports and disable caching
14 # Show full error reports and disable caching
15 config.action_controller.consider_all_requests_local = true
15 config.action_controller.consider_all_requests_local = true
16 config.action_controller.perform_caching = false
16 config.action_controller.perform_caching = false
17 config.action_view.cache_template_extensions = false
17 config.action_view.cache_template_extensions = false
18 config.action_view.debug_rjs = true
18 config.action_view.debug_rjs = true
19
19
20 # Don't care if the mailer can't send
20 # Don't care if the mailer can't send
21 config.action_mailer.raise_delivery_errors = false
21 config.action_mailer.raise_delivery_errors = false
You need to be logged in to leave comments. Login now