Skip Menu |

This queue is for tickets about the Catalyst-View-Excel-Template-Plus CPAN distribution.

Report information
The Basics
Id: 68918
Status: resolved
Priority: 0/
Queue: Catalyst-View-Excel-Template-Plus

People
Owner: Nobody in particular
Requestors: jorge.gonzalez [...] daikon.es
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Specification of Content-Disposition and downloaded filename
Sometimes the user will need to set a flag on the downloaded data so that it is not viewed inline, but forced to be downloaded, and specify a proposed filename for the download. This code adds this funcionality: (Catalyst/View/Excel/Template/Plus.pm, near line 69): ... $excel->param( $self->get_template_params($c) ); #### JGV 2011/03/10 my $excel_filename = $c->stash->{excel_filename} || (split '/',$c- Show quoted text
>req->path)[-1] || 'index.xls';
$excel_filename .= '.xls' unless ($excel_filename =~ /\.xls$/i); my $excel_disposition = $c->stash->{excel_disposition} || 'inline'; $c->response->headers->header("Content-Disposition" => qq{$excel_disposition; filename="$excel_filename"}); #### END JGV $c->response->content_type('application/x-msexcel'); $c->response->body($excel->output); } ... Proposed code is between the #### JGV lines. Feel free to remove them from the definitive code :-) This code does the following: - If no 'excel_filename' key has been stashed, a proposed filename of "index.xls" will be selected, otherwise the specified one will be used. - User can select the disposition ('attachment' or 'inline') with the stash key 'excel_disposition'. If none is selected, 'inline' will be used as the default. Again, thanks for a usefull module :-) Regards Jorge
Show quoted text
> #### JGV 2011/03/10 > my $excel_filename = $c->stash->{excel_filename} || (split '/',$c-
> >req->path)[-1] || 'index.xls';
> $excel_filename .= '.xls' unless ($excel_filename =~ /\.xls$/i); > my $excel_disposition = $c->stash->{excel_disposition} || 'inline'; > $c->response->headers->header("Content-Disposition" => > qq{$excel_disposition; filename="$excel_filename"}); > #### END JGV
This change looks pretty good to me. Unfortunately I can't quite figure out how to test it. Any ideas how to access the $c->stash() method from within my test file that uses Catalyst::Test? I tried the following: my ($res, $c) = ctx_request('http://localhost/test_one'); $c->stash(excel_filename => 'test'); $c->stash(excel_disposition => 'attachment'); ($res, $c) = ctx_request('http://localhost/test_one'); But for some reason the second request does not see the stash changes made so it just ends up with the default Content-Disposition. Thanks! - Alex
Got an answer on how to test this: https://twitter.com/shadowcat_mst/status/553986149057064961 :-)
On Sat Jan 10 13:53:56 2015, KAORU wrote: Show quoted text
> Got an answer on how to test this: > > https://twitter.com/shadowcat_mst/status/553986149057064961 > > :-)
Pull Request - https://github.com/stevan/catalyst-view-excel-template-plus/pull/2
Pull request applied and pushed a new version to cpan, much thanks!