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
@@ -80,19 +80,14 | |||||
|
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 |
@@ -58,12 +58,21 | |||||
|
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 |
You need to be logged in to leave comments.
Login now