X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FBase.pm;h=a9b3a32a7b9b57ccb6d13f652db6175a1b94fc48;hb=f7e68bd92b9b43454454f9715406b7e0f9b956e1;hp=c4c959f7c7c42a4c2b0b0ec933bc56242120b83b;hpb=9bbeafd23117d2b489a298cc002a97b133de17bd;p=maypole.git diff --git a/lib/Maypole/Model/Base.pm b/lib/Maypole/Model/Base.pm index c4c959f..a9b3a32 100644 --- a/lib/Maypole/Model/Base.pm +++ b/lib/Maypole/Model/Base.pm @@ -8,11 +8,23 @@ sub edit :Exported { } sub process { my ($class, $r) = @_; - $r->template( my $method = $r->action ); - $r->objects([ $class->retrieve(shift @{$r->{args}}) ]); + my $method = $r->action; + return if $r->{template}; # Authentication has set this, we're done. + + $r->{template} = $method; + $r->objects([]); + my $obj = $class->retrieve( $r->{args}->[0] ); + if ($obj) { + $r->objects([ $obj ]); + shift @{$r->{args}}; + } $class->$method($r); } +sub display_columns { + sort shift->columns; +} + =head1 NAME Maypole::Model::Base - Base class for model classes @@ -70,7 +82,9 @@ beers, so C needs to return C. =head2 columns -This is a list of the columns in a table. +This is a list of all the columns in a table. You may also override +C, which is the list of columns you want to view, in +the right order. =head2 table @@ -109,7 +123,10 @@ Return a hash mapping column names with human-readable equivalents. =cut -sub column_names { my $class = shift; map { $_ => ucfirst $_ } $class->columns } +sub column_names { my $class = shift; map { + my $col = $_; + $col =~ s/_+(\w)?/ \U\1/g; + $_ => ucfirst $col } $class->columns } =head2 description