Description:
imports task description as pdf
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r271:69482b83f9d6 - - 8 files changed: 62 inserted, 9 deleted
@@ -0,0 +1,1 | |||
|
1 | + [a-zA-Z]* |
@@ -0,0 +1,9 | |||
|
1 | + class AddDescriptionFilenameToProblems < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + add_column :problems, :description_filename, :string | |
|
4 | + end | |
|
5 | + | |
|
6 | + def self.down | |
|
7 | + remove_column :problems, :description_filename | |
|
8 | + end | |
|
9 | + end |
@@ -9,17 +9,21 | |||
|
9 | 9 | def list |
|
10 | 10 | @problems = Problem.find_available_problems |
|
11 | 11 | @user = User.find(session[:user_id]) |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def view |
|
15 | - base_filename = File.basename("#{params[:file]}.#{params[:ext]}") | |
|
16 | - filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}" | |
|
17 | - #filename = "/home/ioi/web_grader/data/tasks/#{base_filename}" | |
|
18 | - #filename = "/home/ioi/web_grader/public/images/rails.png" | |
|
19 | - if !FileTest.exists?(filename) | |
|
15 | + base_name = params[:file] | |
|
16 | + if !check_user_viewability(base_name) | |
|
17 | + redirect_to :action => 'index' and return | |
|
18 | + end | |
|
19 | + | |
|
20 | + base_filename = File.basename("#{base_name}.#{params[:ext]}") | |
|
21 | + filename = "#{Problem.download_file_basedir}/#{base_filename}" | |
|
22 | + | |
|
23 | + if !check_user_viewability(base_name) or !FileTest.exists?(filename) | |
|
20 | 24 | redirect_to :action => 'index' and return |
|
21 | 25 | end |
|
22 | 26 | |
|
23 | 27 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
24 | 28 | response.headers['Content-Type'] = "application/force-download" |
|
25 | 29 | response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" |
@@ -31,14 +35,20 | |||
|
31 | 35 | end |
|
32 | 36 | end |
|
33 | 37 | |
|
34 | 38 | protected |
|
35 | 39 | |
|
36 | 40 | def check_viewability |
|
37 | - user = User.find(session[:user_id]) | |
|
38 | - if user==nil or !Configuration.show_tasks_to?(user) | |
|
41 | + @user = User.find(session[:user_id]) | |
|
42 | + if @user==nil or !Configuration.show_tasks_to?(@user) | |
|
39 | 43 | redirect_to :controller => 'main', :action => 'list' |
|
40 | 44 | return false |
|
41 | 45 | end |
|
42 | 46 | end |
|
43 | 47 | |
|
48 | + def check_user_viewability(filename) | |
|
49 | + # individual file access control shall be added here | |
|
50 | + return false if not @user | |
|
51 | + return Configuration.show_tasks_to?(@user) | |
|
44 | 52 | end |
|
53 | + | |
|
54 | + end |
@@ -1,3 +1,18 | |||
|
1 | 1 | module MainHelper |
|
2 | 2 | |
|
3 | + def link_to_description_if_any(name, problem, options={}) | |
|
4 | + if !problem.url.blank? | |
|
5 | + return link_to name, problem.url, options | |
|
6 | + elsif !problem.description_filename.blank? | |
|
7 | + basename, ext = problem.description_filename.split('.') | |
|
8 | + options[:controller] = 'tasks' | |
|
9 | + options[:action] = 'view' | |
|
10 | + options[:file] = basename | |
|
11 | + options[:ext] = ext | |
|
12 | + return link_to name, options | |
|
13 | + else | |
|
14 | + return '' | |
|
3 | 15 | end |
|
16 | + end | |
|
17 | + | |
|
18 | + end |
@@ -44,12 +44,16 | |||
|
44 | 44 | problem.errors.add_to_base('Import error.') |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | return problem, importer.log_msg |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | + def self.download_file_basedir | |
|
51 | + return "#{RAILS_ROOT}/data/tasks" | |
|
52 | + end | |
|
53 | + | |
|
50 | 54 | protected |
|
51 | 55 | |
|
52 | 56 | def self.to_i_or_default(st, default) |
|
53 | 57 | if st!='' |
|
54 | 58 | st.to_i |
|
55 | 59 | else |
@@ -1,13 +1,13 | |||
|
1 | 1 | <tr class="info-<%= (problem_counter%2==0) ? "even" : "odd" %>"> |
|
2 | 2 | <td> |
|
3 | 3 | <%= "#{problem_counter+1}" %> |
|
4 | 4 | </td> |
|
5 | 5 | <td> |
|
6 | 6 | <%= "#{problem.full_name} (#{problem.name})" %> |
|
7 | - <%= link_to "[#{t 'main.problem_desc'}]", problem.url, :popup => true if (problem.url!=nil) and (problem.url!='') %> | |
|
7 | + <%= link_to_description_if_any "[#{t 'main.problem_desc'}]", problem %> | |
|
8 | 8 | </td> |
|
9 | 9 | <td align="center"> |
|
10 | 10 | <%= @prob_submissions[problem_counter][:count] %> |
|
11 | 11 | </td> |
|
12 | 12 | <td> |
|
13 | 13 | <%= render :partial => 'submission_short', |
@@ -6,13 +6,13 | |||
|
6 | 6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | 7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | 8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 2010021 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20100219014840) do | |
|
13 | 13 | |
|
14 | 14 | create_table "announcements", :force => true do |t| |
|
15 | 15 | t.string "author" |
|
16 | 16 | t.text "body" |
|
17 | 17 | t.boolean "published" |
|
18 | 18 | t.datetime "created_at" |
@@ -109,12 +109,13 | |||
|
109 | 109 | t.string "url" |
|
110 | 110 | t.integer "description_id" |
|
111 | 111 | t.boolean "test_allowed" |
|
112 | 112 | t.boolean "output_only" |
|
113 | 113 | t.integer "level", :default => 0 |
|
114 | 114 | t.datetime "updated_at" |
|
115 | + t.string "description_filename" | |
|
115 | 116 | end |
|
116 | 117 | |
|
117 | 118 | create_table "rights", :force => true do |t| |
|
118 | 119 | t.string "name" |
|
119 | 120 | t.string "controller" |
|
120 | 121 | t.string "action" |
@@ -30,12 +30,13 | |||
|
30 | 30 | else |
|
31 | 31 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | @log_msg << import_problem_description(dirname) |
|
36 | + @log_msg << import_problem_pdf(dirname) | |
|
36 | 37 | |
|
37 | 38 | return true |
|
38 | 39 | end |
|
39 | 40 | |
|
40 | 41 | protected |
|
41 | 42 | |
@@ -132,7 +133,19 | |||
|
132 | 133 | return "\nProblem description imported from #{filename}." |
|
133 | 134 | else |
|
134 | 135 | return '' |
|
135 | 136 | end |
|
136 | 137 | end |
|
137 | 138 | |
|
139 | + def import_problem_pdf(dirname) | |
|
140 | + pdf_files = Dir["#{dirname}/*.pdf"] | |
|
141 | + if pdf_files.length != 0 | |
|
142 | + filename = pdf_files[0] | |
|
143 | + out_filename = "#{Problem.download_file_basedir}/#{@problem.name}.pdf" | |
|
144 | + File.rename(filename, out_filename) | |
|
145 | + @problem.description_filename = "#{@problem.name}.pdf" | |
|
146 | + @problem.save | |
|
147 | + return "\nProblem pdf imported from #{filename}." | |
|
138 | 148 | end |
|
149 | + end | |
|
150 | + | |
|
151 | + end |
You need to be logged in to leave comments.
Login now