From: Simon Cozens Date: Sat, 31 Jan 2004 14:32:16 +0000 (+0000) Subject: Link to has-many objects in the view page. X-Git-Tag: 2.10~337 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=a0f5a455f933d562b30d9feb613098fb7ddc85b6;p=maypole.git Link to has-many objects in the view page. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@25 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index 8ed51bf..68a9927 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -105,10 +105,10 @@ sub parse_location { sub is_applicable { my $self = shift; my $config = $self->config; - my %ok = map {$_ => 1} @{$config->{display_tables}}; + $config->{ok_tables} = {map {$_ => 1} @{$config->{display_tables}}}; warn "We don't have that table ($self->{table})" - unless $ok{$self->{table}}; - return DECLINED() unless exists $ok{$self->{table}}; + unless $config->{ok_tables}{$self->{table}}; + return DECLINED() unless exists $config->{ok_tables}{$self->{table}}; # Does the action method exist? # XXX We should set the method class to the class for the table diff --git a/lib/Apache/MVC/Model/CDBI.pm b/lib/Apache/MVC/Model/CDBI.pm index 88ba3da..f9b2087 100644 --- a/lib/Apache/MVC/Model/CDBI.pm +++ b/lib/Apache/MVC/Model/CDBI.pm @@ -1,5 +1,6 @@ package Apache::MVC::Model::CDBI; use base qw(Apache::MVC::Model::Base Class::DBI); +use Lingua::EN::Inflect::Number qw(to_PL); use Class::DBI::AsForm; use Class::DBI::FromCGI; use CGI::Untaint; @@ -13,6 +14,15 @@ sub get_objects { return $self->retrieve(shift @{$r->{args}}); } +sub related { + my ($self, $r) = @_; + # Has-many methods; XXX this is a hack + map {to_PL($_)} + grep { exists $r->{config}{ok_tables}{$_} } + map {$_->table} + keys %{shift->__hasa_list} +} + sub do_edit :Exported { my ($self, $r) = @_; my $h = CGI::Untaint->new(%{$r->{params}}); diff --git a/lib/Apache/MVC/View/TT.pm b/lib/Apache/MVC/View/TT.pm index 90624ad..083b359 100644 --- a/lib/Apache/MVC/View/TT.pm +++ b/lib/Apache/MVC/View/TT.pm @@ -34,6 +34,7 @@ sub _args { name => $class, columns => [ $class->columns ], colnames => { $class->column_names }, + related_accessors => [ $class->related($r) ], moniker => $class->moniker, plural => $class->plural_moniker, cgi => { $class->to_cgi }, diff --git a/templates/factory/macros b/templates/factory/macros index 2a23155..044ba45 100644 --- a/templates/factory/macros +++ b/templates/factory/macros @@ -34,3 +34,14 @@ END %] [% END %] +[% MACRO view_related(object) BLOCK; + FOR accessor = classmetadata.related_accessors.list; + "

"; accessor | ucfirst; "

\n"; + ""; + END; +END; +%] diff --git a/templates/factory/view b/templates/factory/view index 509208e..202da15 100644 --- a/templates/factory/view +++ b/templates/factory/view @@ -25,9 +25,9 @@ [% END; %] [% + view_related(item); button(item, "edit"); button(item, "delete"); %] - [% END; %]