Description:
added timestamp to source download
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@365 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
r168:1a0b47f4c2a4 - - 2 files changed: 10 inserted, 6 deleted
@@ -62,55 +62,50 | |||||
|
62 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
62 | if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and |
|
63 | user.site!=nil and user.site.finished? |
|
63 | user.site!=nil and user.site.finished? |
|
64 | @submission.errors.add_to_base "The contest is over." |
|
64 | @submission.errors.add_to_base "The contest is over." |
|
65 | prepare_list_information |
|
65 | prepare_list_information |
|
66 | render :action => 'list' and return |
|
66 | render :action => 'list' and return |
|
67 | end |
|
67 | end |
|
68 |
|
68 | ||
|
69 | if @submission.valid? |
|
69 | if @submission.valid? |
|
70 | if @submission.save == false |
|
70 | if @submission.save == false |
|
71 | flash[:notice] = 'Error saving your submission' |
|
71 | flash[:notice] = 'Error saving your submission' |
|
72 | elsif Task.create(:submission_id => @submission.id, |
|
72 | elsif Task.create(:submission_id => @submission.id, |
|
73 | :status => Task::STATUS_INQUEUE) == false |
|
73 | :status => Task::STATUS_INQUEUE) == false |
|
74 | flash[:notice] = 'Error adding your submission to task queue' |
|
74 | flash[:notice] = 'Error adding your submission to task queue' |
|
75 | end |
|
75 | end |
|
76 | else |
|
76 | else |
|
77 | prepare_list_information |
|
77 | prepare_list_information |
|
78 | render :action => 'list' and return |
|
78 | render :action => 'list' and return |
|
79 | end |
|
79 | end |
|
80 | redirect_to :action => 'list' |
|
80 | redirect_to :action => 'list' |
|
81 | end |
|
81 | end |
|
82 |
|
82 | ||
|
83 | def source |
|
83 | def source |
|
84 | submission = Submission.find(params[:id]) |
|
84 | submission = Submission.find(params[:id]) |
|
85 | if submission.user_id == session[:user_id] |
|
85 | if submission.user_id == session[:user_id] |
|
86 | - if submission.problem.output_only |
|
||
|
87 | - fname = submission.source_filename |
|
||
|
88 | - else |
|
||
|
89 | - fname = submission.problem.name + '.' + submission.language.ext |
|
||
|
90 | - end |
|
||
|
91 | send_data(submission.source, |
|
86 | send_data(submission.source, |
|
92 | - {:filename => fname, |
|
87 | + {:filename => submission.download_filename, |
|
93 | :type => 'text/plain'}) |
|
88 | :type => 'text/plain'}) |
|
94 | else |
|
89 | else |
|
95 | flash[:notice] = 'Error viewing source' |
|
90 | flash[:notice] = 'Error viewing source' |
|
96 | redirect_to :action => 'list' |
|
91 | redirect_to :action => 'list' |
|
97 | end |
|
92 | end |
|
98 | end |
|
93 | end |
|
99 |
|
94 | ||
|
100 | def compiler_msg |
|
95 | def compiler_msg |
|
101 | @submission = Submission.find(params[:id]) |
|
96 | @submission = Submission.find(params[:id]) |
|
102 | if @submission.user_id == session[:user_id] |
|
97 | if @submission.user_id == session[:user_id] |
|
103 | render :action => 'compiler_msg', :layout => 'empty' |
|
98 | render :action => 'compiler_msg', :layout => 'empty' |
|
104 | else |
|
99 | else |
|
105 | flash[:notice] = 'Error viewing source' |
|
100 | flash[:notice] = 'Error viewing source' |
|
106 | redirect_to :action => 'list' |
|
101 | redirect_to :action => 'list' |
|
107 | end |
|
102 | end |
|
108 | end |
|
103 | end |
|
109 |
|
104 | ||
|
110 | def submission |
|
105 | def submission |
|
111 | @user = User.find(session[:user_id]) |
|
106 | @user = User.find(session[:user_id]) |
|
112 | @problems = Problem.find_available_problems |
|
107 | @problems = Problem.find_available_problems |
|
113 | if params[:id]==nil |
|
108 | if params[:id]==nil |
|
114 | @problem = nil |
|
109 | @problem = nil |
|
115 | @submissions = nil |
|
110 | @submissions = nil |
|
116 | else |
|
111 | else |
@@ -40,48 +40,57 | |||||
|
40 | problems.each do |problem| |
|
40 | problems.each do |problem| |
|
41 | sub = Submission.find_last_by_user_and_problem(user_id, problem.id) |
|
41 | sub = Submission.find_last_by_user_and_problem(user_id, problem.id) |
|
42 | submissions << sub if sub!=nil |
|
42 | submissions << sub if sub!=nil |
|
43 | end |
|
43 | end |
|
44 | submissions |
|
44 | submissions |
|
45 | end |
|
45 | end |
|
46 |
|
46 | ||
|
47 | def self.find_by_user_problem_number(user_id, problem_id, number) |
|
47 | def self.find_by_user_problem_number(user_id, problem_id, number) |
|
48 | Submission.find(:first, |
|
48 | Submission.find(:first, |
|
49 | :conditions => { |
|
49 | :conditions => { |
|
50 | :user_id => user_id, |
|
50 | :user_id => user_id, |
|
51 | :problem_id => problem_id, |
|
51 | :problem_id => problem_id, |
|
52 | :number => number |
|
52 | :number => number |
|
53 | }) |
|
53 | }) |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | def self.find_all_by_user_problem(user_id, problem_id) |
|
56 | def self.find_all_by_user_problem(user_id, problem_id) |
|
57 | Submission.find(:all, |
|
57 | Submission.find(:all, |
|
58 | :conditions => { |
|
58 | :conditions => { |
|
59 | :user_id => user_id, |
|
59 | :user_id => user_id, |
|
60 | :problem_id => problem_id, |
|
60 | :problem_id => problem_id, |
|
61 | }) |
|
61 | }) |
|
62 | end |
|
62 | end |
|
63 |
|
63 | ||
|
|
64 | + def download_filename | ||
|
|
65 | + if self.problem.output_only | ||
|
|
66 | + return self.source_filename | ||
|
|
67 | + else | ||
|
|
68 | + timestamp = self.submitted_at.localtime.strftime("%H%M%S") | ||
|
|
69 | + return "#{self.problem.name}-#{timestamp}.#{self.language.ext}" | ||
|
|
70 | + end | ||
|
|
71 | + end | ||
|
|
72 | + | ||
|
64 | protected |
|
73 | protected |
|
65 |
|
74 | ||
|
66 | def self.find_option_in_source(option, source) |
|
75 | def self.find_option_in_source(option, source) |
|
67 | if source==nil |
|
76 | if source==nil |
|
68 | return nil |
|
77 | return nil |
|
69 | end |
|
78 | end |
|
70 | i = 0 |
|
79 | i = 0 |
|
71 | source.each_line do |s| |
|
80 | source.each_line do |s| |
|
72 | if s =~ option |
|
81 | if s =~ option |
|
73 | words = s.split |
|
82 | words = s.split |
|
74 | return words[1] |
|
83 | return words[1] |
|
75 | end |
|
84 | end |
|
76 | i = i + 1 |
|
85 | i = i + 1 |
|
77 | if i==10 |
|
86 | if i==10 |
|
78 | return nil |
|
87 | return nil |
|
79 | end |
|
88 | end |
|
80 | end |
|
89 | end |
|
81 | return nil |
|
90 | return nil |
|
82 | end |
|
91 | end |
|
83 |
|
92 | ||
|
84 | def self.find_language_in_source(source, source_filename="") |
|
93 | def self.find_language_in_source(source, source_filename="") |
|
85 | langopt = find_option_in_source(/^LANG:/,source) |
|
94 | langopt = find_option_in_source(/^LANG:/,source) |
|
86 | if langopt |
|
95 | if langopt |
|
87 | return (Language.find_by_name(langopt) || |
|
96 | return (Language.find_by_name(langopt) || |
You need to be logged in to leave comments.
Login now