From 436fd74e09a36cccdff90be36e1d098426cbc975 Mon Sep 17 00:00:00 2001 From: biopete Date: Wed, 12 Jul 2006 04:58:02 +0000 Subject: [PATCH] Drinker uses add_to_from_cgi and other stuff. Now it is a nice working basic example with lots to do such as berrs, brewery, adding handpumps to pubs, styles. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@505 48953598-375a-da11-a14b-00016c27c3ee --- ex/fancy_example/BeerDB.pm | 1 - ex/fancy_example/BeerDB/Base.pm | 15 +++++++++++++++ ex/fancy_example/BeerDB/Drinker.pm | 11 ++++++----- ex/fancy_example/templates/custom/metadata | 5 +++++ ex/fancy_example/templates/drinker/view | 7 ++++--- 5 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 ex/fancy_example/templates/custom/metadata diff --git a/ex/fancy_example/BeerDB.pm b/ex/fancy_example/BeerDB.pm index 593851f..5b30188 100644 --- a/ex/fancy_example/BeerDB.pm +++ b/ex/fancy_example/BeerDB.pm @@ -58,7 +58,6 @@ BeerDB->config->{person}{required_cols} = [qw/first_name sur_name dob email/]; # Columns to display sub BeerDB::Handpump::display_columns { qw/pub beer/ } -sub BeerDB::Pint::display_columns { qw/drinker handpump/ } sub BeerDB::Person::display_columns { qw/first_name last_name dob email/ } BeerDB->config->{loader}->relationship($_) for ( diff --git a/ex/fancy_example/BeerDB/Base.pm b/ex/fancy_example/BeerDB/Base.pm index 0f980d9..23b1dd1 100644 --- a/ex/fancy_example/BeerDB/Base.pm +++ b/ex/fancy_example/BeerDB/Base.pm @@ -15,4 +15,19 @@ sub list : Exported { $r->template_args->{classmetadata}{cgi} = { $self->to_cgi(@cols) }; } + +# Template switcheroo bug bit me -- was seeing view page but the view action was never +# being executed after an edit. +sub do_edit : Exported { + my ($self, $r) = (shift, shift); + $self->SUPER::do_edit($r, @_); + if (my $obj = $r->object) { + my $url = $r->config->uri_base . "/" . $r->table . "/view/" . $obj->id; + $r->redirect_request(url => $url); + } +} + +sub metadata: Exported {} + + 1; diff --git a/ex/fancy_example/BeerDB/Drinker.pm b/ex/fancy_example/BeerDB/Drinker.pm index f3edd7b..5119dcf 100644 --- a/ex/fancy_example/BeerDB/Drinker.pm +++ b/ex/fancy_example/BeerDB/Drinker.pm @@ -44,14 +44,15 @@ sub view : Exported { my ($self, $r, $obj) = @_; $self->_croak( "Object method only") unless $obj; - if ($r->params->{submit} eq 'drink') { - $r->params->{drinker} = $self; - my ($pint, $errs) = $self->related_class($r, 'pints')->create_from_cgi($r); - $r->template_args->{errors} = $errs if $errs; + if ($r->params->{submit}) { + my ($pint) = $obj->add_to_from_cgi($r); + if (my $errs = $obj->cgi_update_errors) { + $r->template_args->{errors} = $errs; + } } my %cgi = $self->to_cgi('pints'); - $cgi{pints}{drinker} = $obj->to_field(drinker => 'link_hidden', {r => $r}); + delete $cgi{pints}{drinker}; # = $obj->to_field(drinker => 'link_hidden', {r => $r}); $r->template_args->{classmetadata}{cgi} = \%cgi ; } diff --git a/ex/fancy_example/templates/custom/metadata b/ex/fancy_example/templates/custom/metadata new file mode 100644 index 0000000..e15fb6a --- /dev/null +++ b/ex/fancy_example/templates/custom/metadata @@ -0,0 +1,5 @@ +

Class::DBI meta info for [% classmetadata.name %]

+[% + USE this = Class(classmetadata.name); + USE Dumper; Dumper.dump(this.meta_info); +%] diff --git a/ex/fancy_example/templates/drinker/view b/ex/fancy_example/templates/drinker/view index 50a51ca..fd85e88 100644 --- a/ex/fancy_example/templates/drinker/view +++ b/ex/fancy_example/templates/drinker/view @@ -20,13 +20,14 @@ Drinker C template displays drinker and from to drink beer.