[Catalyst-commits] r8435 - in trunk/Catalyst-Example-InstantCRUD: .
lib/Catalyst/Example/Controller
lib/Catalyst/Helper/Controller lib/Catalyst/Helper/View t t/var
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Fri Sep 19 17:58:38 BST 2008
Author: zby
Date: 2008-09-19 17:58:36 +0100 (Fri, 19 Sep 2008)
New Revision: 8435
Added:
trunk/Catalyst-Example-InstantCRUD/t/var/test.sql
Modified:
trunk/Catalyst-Example-InstantCRUD/MANIFEST
trunk/Catalyst-Example-InstantCRUD/Makefile.PL
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm
trunk/Catalyst-Example-InstantCRUD/t/10.apptest.t
trunk/Catalyst-Example-InstantCRUD/t/21.test_dvdzbr.t
trunk/Catalyst-Example-InstantCRUD/t/var/test.db
Log:
Support for composed keys
Modified: trunk/Catalyst-Example-InstantCRUD/MANIFEST
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/MANIFEST 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/MANIFEST 2008-09-19 16:58:36 UTC (rev 8435)
@@ -13,7 +13,6 @@
t/tmp/test.db
t/var/dvdzbr.db
t/var/test.db
-lib/HTML/Widget/Element/DoubleSelect.pm
lib/Catalyst/Helper/View/InstantCRUD.pm
lib/Catalyst/Helper/Model/InstantCRUD.pm
lib/Catalyst/Helper/InstantCRUD.pm
@@ -21,6 +20,5 @@
lib/Catalyst/Plugin/Auth/Utils.pm
lib/Catalyst/Example/InstantCRUD.pm
lib/Catalyst/Example/Controller/InstantCRUD.pm
-lib/Catalyst/Example/InstantCRUD/Utils.pm
META.yml Module meta-data (added by MakeMaker)
Modified: trunk/Catalyst-Example-InstantCRUD/Makefile.PL
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/Makefile.PL 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/Makefile.PL 2008-09-19 16:58:36 UTC (rev 8435)
@@ -32,11 +32,11 @@
'URI::Escape' => 0,
'HTML::Entities' => 0,
'HTML::Widget' => 1.10,
- 'HTML::Widget::DBIC' => 0,
'File::Spec' => 0,
'File::Slurp' => 0,
'Pod::Usage' => 0,
'Digest::SHA1' => 0,
+ 'List::Util' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Catalyst-Example-InstantCRUD-*' },
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Example/Controller/InstantCRUD.pm 2008-09-19 16:58:36 UTC (rev 8435)
@@ -33,9 +33,9 @@
}
sub model_item {
- my ( $self, $c, $id ) = @_;
+ my ( $self, $c, @pks ) = @_;
my $rs = $self->model_resultset($c);
- my $item = defined $id ? $rs->find($id) : $rs->new( {} );
+ my $item = scalar @pks ? $rs->find( @pks, { key => 'primary' }) : $rs->new( {} );
return $item;
}
@@ -53,15 +53,15 @@
}
sub destroy : Local {
- my ( $self, $c, $id ) = @_;
+ my ( $self, $c, @pks ) = @_;
if ( $c->req->method eq 'POST' ) {
- $self->model_item( $c, $id )->delete;
+ $self->model_item( $c, @pks )->delete;
$c->forward('list');
}
else {
my $w =
$c->widget('widget')->method('post')
- ->action( $c->uri_for( 'destroy', $id ) );
+ ->action( $c->uri_for( 'destroy', @pks) );
$w->element( 'Submit', 'ok' )->value('Delete ?');
$c->stash->{destroywidget} = $w->process;
# $c->stash->{template} = 'destroy.tt';
@@ -69,34 +69,32 @@
}
sub edit : Local {
- my ( $self, $c, $id ) = @_;
+ my ( $self, $c, @pks ) = @_;
my $form_name = ref( $self ) . '::' . $self->source_name . 'Form';
my $form = $form_name->new();
- warn $form->html_table;
my $rs = $self->model_resultset($c);
options_from_resultset( $form, $rs );
my $params = $c->req->params;
- $params->{id} = $id;
$form->params( $params );
# $form->prepare();
$form->init_fields();
if( $c->req->method eq 'POST' and $form->was_submitted ){
if ( $form->validate ){
- my $item = dbic_from_form($form, $rs);
+ my $item = dbic_from_form($form, $rs, @pks);
$c->res->redirect( $c->uri_for( 'view', $item->id ) );
}
}
else {
- init_with_dbic($form, $rs->find( $id )) if $id;
+ init_with_dbic($form, $rs->find( @pks, { key => 'primary' } ) ) if scalar @pks;
}
$c->stash( form => $form );
}
sub view : Local {
- my ( $self, $c, $id ) = @_;
- die "You need to pass an id" unless $id;
- my $item = $self->model_item( $c, $id );
+ my ( $self, $c, @pks ) = @_;
+ die "You need to pass an id" unless @pks;
+ my $item = $self->model_item( $c, @pks );
$c->stash->{item} = $item;
# $c->stash->{template} = 'view.tt';
}
@@ -147,7 +145,6 @@
$c->stash->{order_by_column_link} = $self->create_col_link($c, $source);
$c->stash->{result} = $result;
# $c->stash->{template} = 'list.tt';
- warn $c->uri_for();
}
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/Controller/InstantCRUD.pm 2008-09-19 16:58:36 UTC (rev 8435)
@@ -31,7 +31,6 @@
m2m => $m2m,
);
$helper->{form_code} = $generator->generate_form( $class );
- warn "form code for $class: " . $helper->{form_code};
$helper->render_file( compclass => $file );
}
Modified: trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/lib/Catalyst/Helper/View/InstantCRUD.pm 2008-09-19 16:58:36 UTC (rev 8435)
@@ -50,7 +50,7 @@
for qw/edit destroy/;
$helper->{field_configs} = _get_column_config( $schema, $class, $m2m ) ;
my $source = $schema->source($class);
- $helper->{primary_keys} = $source->primary_columns;
+ $helper->{primary_keys} = [ $source->primary_columns ];
$helper->render_file( list => file( $classdir, 'list.tt' ));
$helper->render_file( view => file( $classdir, 'view.tt' ));
}
@@ -145,9 +145,9 @@
</td>
<+ END +>
[% SET id = row.$pri %]
- <td><a href="[% c.uri_for( 'view', id ) %]">View</a></td>
- <td><a href="[% c.uri_for( 'edit', id ) %]">Edit</a></td>
- <td><a href="[% c.uri_for( 'destroy', id ) %]">Destroy</a></td>
+ <td><a href="[% c.uri_for( 'view', <+ FOR key = primary_keys +>item.<+ key +>, <+ END +> ) %]">View</a></td>
+ <td><a href="[% c.uri_for( 'edit', <+ FOR key = primary_keys +>item.<+ key +>, <+ END +> ) %]">Edit</a></td>
+ <td><a href="[% c.uri_for( 'destroy', <+ FOR key = primary_keys +>item.<+ key +>, <+ END +> ) %]">Destroy</a></td>
</tr>
[% END %]
</table>
Modified: trunk/Catalyst-Example-InstantCRUD/t/10.apptest.t
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/10.apptest.t 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/t/10.apptest.t 2008-09-19 16:58:36 UTC (rev 8435)
@@ -1,6 +1,8 @@
use strict;
use warnings;
use Test::More;
+use String::Random qw(random_string random_regex);
+use DBI;
BEGIN {
use lib 't/tmp/My-App/lib';
@@ -10,7 +12,7 @@
if ($@){
plan skip_all => "Test::WWW::Mechanize::Catalyst required for testing application";
}else{
- plan tests => 13;
+ plan tests => 14;
}
my $mech = Test::WWW::Mechanize::Catalyst->new;
@@ -41,4 +43,30 @@
$mech->get_ok("/firsttable/destroy/2", "Destroy 2nd record");
$mech->submit_form( form_number => 1 );
$mech->content_lacks("Changed varchar field", "Record deleted");
-
+
+$mech->follow_link_ok({text => 'ComposedKey'}, "Click on composed key table");
+$mech->follow_link_ok({text => 'Add'}, "Click on composed key Add row");
+my $id1 = int(rand(1000000));
+my $id2 = int(rand(1000000));
+$mech->submit_form(
+ form_number => 1,
+ fields => {
+ id1 => $id1,
+ id2 => $id2,
+ value => 'Varchar Field',
+ }
+);
+$mech->content_like( qr{<b>Id1:</b>\s*$id1\s*<br/>}, 'Viewing record with composed key' );
+$mech->follow_link_ok({text => 'Edit'}, "Editing a DVD");
+$mech->content_contains( $id1, 'Following Edit for a record with composed key' );
+my $random_string = 'random ' . random_regex('\w{20}');
+#DBI->trace(1);
+$mech->submit_form(
+ form_number => 1,
+ fields => {
+ value => $random_string,
+ }
+);
+$mech->content_contains( $id1, 'Editing record with composed key' );
+$mech->content_contains( $random_string, 'Editing record with composed key' );
+
Modified: trunk/Catalyst-Example-InstantCRUD/t/21.test_dvdzbr.t
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/21.test_dvdzbr.t 2008-09-18 19:37:27 UTC (rev 8434)
+++ trunk/Catalyst-Example-InstantCRUD/t/21.test_dvdzbr.t 2008-09-19 16:58:36 UTC (rev 8435)
@@ -103,7 +103,7 @@
form_number => 1,
fields => {
name => 'Jurassic Park II',
- tags => 1,
+ tags => 1,
owner => 1,
current_owner => 2,
hour => '10:00',
Modified: trunk/Catalyst-Example-InstantCRUD/t/var/test.db
===================================================================
(Binary files differ)
Added: trunk/Catalyst-Example-InstantCRUD/t/var/test.sql
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/t/var/test.sql (rev 0)
+++ trunk/Catalyst-Example-InstantCRUD/t/var/test.sql 2008-09-19 16:58:36 UTC (rev 8435)
@@ -0,0 +1,66 @@
+BEGIN TRANSACTION;
+CREATE TABLE firsttable (
+id integer primary key,
+intfield integer,
+charfield char(10),
+varfield varchar(100)
+);
+INSERT INTO "firsttable" VALUES(1,1,'aaa','This is the first row');
+INSERT INTO "firsttable" VALUES(2,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(3,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(4,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(5,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(6,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(7,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(8,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(9,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(10,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(11,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(12,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(13,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(14,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(15,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(16,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(17,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(18,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(19,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(20,1,'aaa','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+INSERT INTO "firsttable" VALUES(21,9999,'aaa','This is the row with the biggest int');
+INSERT INTO "firsttable" VALUES(22,0,'aaa','This is the row with the smallest int');
+INSERT INTO "firsttable" VALUES(23,1,'bbb','aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
+CREATE TABLE secondtable(
+id integer primary key,
+firstableid integer,
+charfield char(10),
+foreign key (firstableid) references firsttable(id)
+);
+INSERT INTO "secondtable" VALUES(1,1,'bbb');
+INSERT INTO "secondtable" VALUES(2,1,'bbb');
+INSERT INTO "secondtable" VALUES(3,1,'bbb');
+INSERT INTO "secondtable" VALUES(4,1,'bbb');
+INSERT INTO "secondtable" VALUES(5,1,'bbb');
+INSERT INTO "secondtable" VALUES(6,1,'bbb');
+INSERT INTO "secondtable" VALUES(7,1,'bbb');
+INSERT INTO "secondtable" VALUES(8,1,'bbb');
+INSERT INTO "secondtable" VALUES(9,1,'bbb');
+INSERT INTO "secondtable" VALUES(10,1,'bbb');
+INSERT INTO "secondtable" VALUES(11,2,'aaa');
+INSERT INTO "secondtable" VALUES(12,3,'aaa');
+INSERT INTO "secondtable" VALUES(13,4,'aaa');
+CREATE TABLE usr(
+id serial primary key
+);
+CREATE TABLE bookmark(
+id serial primary key,
+usr integer,
+foreign key (usr) references usr(id)
+);
+CREATE TABLE composed_key(
+ id1 integer,
+ id2 integer,
+ value varchar(32),
+ primary key (id1, id2)
+);
+INSERT INTO "composed_key" VALUES(0,0,'bbb');
+
+COMMIT;
More information about the Catalyst-commits
mailing list