From d2c852208417c014caec0436a677fcadccc197d8 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sun, 16 Jan 2005 18:47:28 +0000 Subject: [PATCH] removed Maypole::Model->description, fixed overidability of classmetadata in View, fix Maypole::Model::CDBI->related_class, fix edit/addnew templates & do_edit action git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@332 48953598-375a-da11-a14b-00016c27c3ee --- Changes | 15 ++++++++++++++- META.yml | 2 +- lib/Apache/MVC.pm | 2 +- lib/CGI/Maypole.pm | 2 +- lib/Maypole.pm | 5 ++--- lib/Maypole/Application.pm | 2 +- lib/Maypole/Manual/View.pod | 4 ---- lib/Maypole/Model/Base.pm | 8 -------- lib/Maypole/Model/CDBI.pm | 20 +++++++++++--------- lib/Maypole/View/Base.pm | 7 ++----- templates/factory/addnew | 13 ++++++++++++- templates/factory/edit | 7 +++++-- 12 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Changes b/Changes index e81f2fa..a05fbc6 100644 --- a/Changes +++ b/Changes @@ -2,10 +2,23 @@ This file documents the revision history for Perl extension Maypole. For information about current developments and future releases, see: http://maypole.perl.org/?TheRoadmap -2.0X XXX +2.07 Sun Jan 16 18:45:00 2005 + Internal changes: + - Removed Maypole::Model->description. It didn't work as expected and + clashed with 'description' columns in the database + Fixes: - Model->process() shouldn't set $r->objects() to a list with a single, undefined element + - Fixed overriding $r->template_args->{classmetadata} in M::V::Base + (Thanks to Dave Howorth for spotting the mistake) + - #9473: Maypole::Model::CDBI->related_class (Thanks David Baird) + - #9434: M::M::CDBI->search generated "uninitialized value" warnings + + Templates: + - The addnew template will attempt to prefill form fields with request + parameters + - edit template includes 'addnew' if there is no object to edit 2.06 Wed Dec 29 01:30:00 2004 Fixes: diff --git a/META.yml b/META.yml index 5b5ce58..d19d2ac 100644 --- a/META.yml +++ b/META.yml @@ -1,7 +1,7 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Maypole -version: 2.06 +version: 2.07 version_from: lib/Maypole.pm installdirs: site requires: diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index 6bbe9b6..45dd897 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -1,6 +1,6 @@ package Apache::MVC; -our $VERSION = '2.06'; +our $VERSION = '2.07'; use strict; use warnings; diff --git a/lib/CGI/Maypole.pm b/lib/CGI/Maypole.pm index 9c025ec..e002cf2 100644 --- a/lib/CGI/Maypole.pm +++ b/lib/CGI/Maypole.pm @@ -6,7 +6,7 @@ use warnings; use CGI::Simple; use Maypole::Headers; -our $VERSION = '2.06'; +our $VERSION = '2.07'; sub run { my $self = shift; diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 75d159e..7f1e9d3 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -7,7 +7,7 @@ use Maypole::Config; use Maypole::Constants; use Maypole::Headers; -our $VERSION = '2.06'; +our $VERSION = '2.07'; __PACKAGE__->mk_classdata($_) for qw( config init_done view_object ); __PACKAGE__->mk_accessors( @@ -186,8 +186,7 @@ sub exception { return ERROR } sub parse_path { my $self = shift; $self->{path} ||= "frontpage"; - my @pi = split /\//, $self->{path}; - shift @pi while @pi and !$pi[0]; + my @pi = $self->{path} =~ m{([^/]+)/?}g; $self->{table} = shift @pi; $self->{action} = shift @pi; $self->{action} ||= "index"; diff --git a/lib/Maypole/Application.pm b/lib/Maypole/Application.pm index 01dd614..18cd589 100644 --- a/lib/Maypole/Application.pm +++ b/lib/Maypole/Application.pm @@ -7,7 +7,7 @@ use Maypole; use Maypole::Config; our @ISA; -our $VERSION = '2.06'; +our $VERSION = '2.07'; sub import { my ( $self, @plugins ) = @_; diff --git a/lib/Maypole/Manual/View.pod b/lib/Maypole/Manual/View.pod index 5477d05..38ba8e7 100644 --- a/lib/Maypole/Manual/View.pod +++ b/lib/Maypole/Manual/View.pod @@ -385,10 +385,6 @@ that class. That is, for the C table, C should be a C object containing a drop-down list of beer styles. -TODO =item C -TODO -TODO This is the human-readable description provided by a class. - =item C This is a list of accessors which can be called on an object to get diff --git a/lib/Maypole/Model/Base.pm b/lib/Maypole/Model/Base.pm index 3375dfd..678c399 100644 --- a/lib/Maypole/Model/Base.pm +++ b/lib/Maypole/Model/Base.pm @@ -169,14 +169,6 @@ sub column_names { } $class->columns; } -=head2 description - -A description of the class to be passed to the template. - -=cut - -sub description { "A poorly defined class" } - =head2 is_public should return true if a certain action is supported, or false otherwise. diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index ac89318..4ed0aa6 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -82,8 +82,13 @@ sub related { sub related_class { my ( $self, $r, $accessor ) = @_; - my $related = $self->related->{$accessor}; - if ( my $mapping = $related->{args}->{mapping} ) { + + my $related = $self->meta_info( has_many => $accessor ) || + $self->meta_info( has_a => $accessor ) || + return; + + my $mapping = $related->{args}->{mapping}; + if ( @$mapping ) { return $related->{foreign_class}->meta_info('has_a')->{ $$mapping[0] } ->{foreign_class}; } @@ -123,12 +128,8 @@ sub do_edit : Exported { $r->{template_args}{cgi_params} = $r->{params}; $r->{template_args}{errors} = \%errors; - if ($creating) { - undef $obj; - $r->template("addnew"); - } else { - $r->template("edit"); - } + undef $obj if $creating; + $r->template("edit"); } else { $r->{template} = "view"; @@ -171,7 +172,8 @@ sub search : Exported { my $oper = "like"; # For now my %params = %{ $r->{params} }; my %values = map { $_ => { $oper, $params{$_} } } - grep { length ($params{$_}) and $fields{$_} } keys %params; + grep { defined $params{$_} && length ($params{$_}) && $fields{$_} } + keys %params; $r->template("list"); if ( !%values ) { return $self->list($r) } diff --git a/lib/Maypole/View/Base.pm b/lib/Maypole/View/Base.pm index f7881a2..312d38b 100644 --- a/lib/Maypole/View/Base.pm +++ b/lib/Maypole/View/Base.pm @@ -35,9 +35,8 @@ sub vars { # ... ); if ($class) { - my $classmeta = $args{classmetadata} ||= {}; + my $classmeta = $r->template_args->{classmetadata} ||= {}; $classmeta->{name} ||= $class; - $classmeta->{description} ||= $class->description; $classmeta->{table} ||= $class->table; $classmeta->{columns} ||= [ $class->display_columns ]; $classmeta->{list_columns} ||= [ $class->list_columns ]; @@ -57,9 +56,7 @@ sub vars { } # Overrides - local $r->{template_args} = $r->{template_args}; - delete $r->{template_args}{classmetadata}; # already overrides - %args = ( %args, %{ $r->{template_args} || {} } ); + %args = ( %args, %{ $r->template_args || {} } ); %args; } diff --git a/templates/factory/addnew b/templates/factory/addnew index a6027ce..f530bc9 100644 --- a/templates/factory/addnew +++ b/templates/factory/addnew @@ -18,8 +18,19 @@ table. [% FOR col = classmetadata.columns %] [% NEXT IF col == "id" %] + [% IF errors.$col %] + [% errors.$col %] + [% END %] + [% END; %] diff --git a/templates/factory/edit b/templates/factory/edit index 5feb34e..d114897 100644 --- a/templates/factory/edit +++ b/templates/factory/edit @@ -3,7 +3,7 @@ =head1 edit This is the edit page. It edits the passed-in object, by displaying a -form similar to L but with the current values filled in. +form similar to L but with the current values filled in. =cut @@ -11,6 +11,7 @@ form similar to L but with the current values filled in. [% PROCESS macros %] [% INCLUDE header %] [% INCLUDE title %] +[% IF objects.length %]
Edit a [% classmetadata.moniker %]
[% FOR item = objects; %]
@@ -30,5 +31,7 @@ form similar to L but with the current values filled in. ""; END %] - +[% ELSE %] +[% INCLUDE addnew %] +[% END %] [% INCLUDE footer %] -- 2.39.2