From a02686080acb66fce170e9657e110761b09e62a2 Mon Sep 17 00:00:00 2001 From: Aaron Trevena Date: Sat, 24 Dec 2005 10:30:10 +0000 Subject: [PATCH] AJT synch git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@442 48953598-375a-da11-a14b-00016c27c3ee --- AUTHORS | 22 ++++++++++++ Changes | 7 +++- MANIFEST | 2 +- META.yml | 5 ++- ex/beerdb.sql | 37 ++++++++++++++++++++ lib/Maypole.pm | 7 +--- lib/Maypole/Model/CDBI.pm | 51 ++++++++++++++++++++-------- lib/Maypole/View/TT.pm | 28 +++++++++++++++ lib/Maypole/templates/factory/addnew | 2 +- lib/Maypole/templates/factory/login | 8 +++-- lib/Maypole/templates/factory/macros | 12 +++---- 11 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 AUTHORS create mode 100644 ex/beerdb.sql diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..34ec949 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,22 @@ +AUTHORS +------- + +The following people have written and documented Maypole: + +Simon Cozens - Author Emeritus +Sebastian Riedel - Maintainer (1.x to 2.x) +Simon Flack - Maintainer ( 2.x to 2.9 ) +Aaron Trevena - Maintainer (2.10 to present) +Dave Howorth - Developer +David Baird - Developer + +Thanks also to for fixes and other contributions: + +Randal Schwartz +Jester +Marcus Ramberg +Steven Simms +Kevin Connor +Dagfinn Ilmari Mannsåker +Danijel Milicevic +Dave Slack diff --git a/Changes b/Changes index 545522e..bbee811 100644 --- a/Changes +++ b/Changes @@ -7,13 +7,16 @@ For information about current developments and future releases, see: Deprecated: Directly accessing the attributes of the request object, or the parameters in $r->params, or anything else, is DEPRECATED and likely to break in future - releases. Be good, and use proper method calls. + releases. Be good, and use proper method calls. Incompatible API changes: Maypole: - is_applicable() renamed to is_model_applicable(), and returns boolean instead of a status code. Old-style is_applicable() will still work, but issues a warning. + Maypole::Model + - delete and search actions are now deprecated - use do_search and do_delete + instead API additions and enhancements: Maypole::Application: @@ -37,6 +40,8 @@ API additions and enhancements: - added make_path() - added make_uri() - improved exception handling + Maypole::Model + - do_delete, do_search in place of delete/search actions Maypole::View::TT: - new report_error method - new embedded error report page in __DATA__ diff --git a/MANIFEST b/MANIFEST index d766970..be5dea4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -62,4 +62,4 @@ lib/Maypole/templates/factory/pager lib/Maypole/templates/factory/search_form lib/Maypole/templates/factory/title lib/Maypole/templates/factory/view -lib/Maypole/templates/maypole.css +lib/Maypole/templates/factory/maypole.css diff --git a/META.yml b/META.yml index 02da7a5..8461737 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.10 +version: 2.11 version_from: lib/Maypole.pm installdirs: site requires: @@ -18,11 +18,14 @@ requires: Class::DBI::SQLite: 0 Digest::MD5: 0 HTTP::Headers: 1.59 + HTTP::Server::Simple: 0.02 + HTTP::Server::Simple::Static: 0.01 Template: 0 Template::Plugin::Class: 0 Test::MockModule: 0 UNIVERSAL::moniker: 0 UNIVERSAL::require: 0 + URI: 0 URI::QueryParam: 0 distribution_type: module diff --git a/ex/beerdb.sql b/ex/beerdb.sql new file mode 100644 index 0000000..b5d7d7c --- /dev/null +++ b/ex/beerdb.sql @@ -0,0 +1,37 @@ +CREATE TABLE style ( + id integer primary key auto_increment, + name varchar(60), + notes text +); + +CREATE TABLE pub ( + id integer primary key auto_increment, + name varchar(60), + url varchar(120), + notes text +); + +CREATE TABLE handpump ( + id integer primary key auto_increment, + beer integer, + pub integer +); + +CREATE TABLE beer ( + id integer primary key auto_increment, + brewery integer, + style integer, + name varchar(30), + url varchar(120), + score integer(2), + price varchar(12), + abv varchar(10), + notes text +); + +CREATE TABLE brewery ( + id integer primary key auto_increment, + name varchar(30), + url varchar(50), + notes text +); diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 85d471f..119a85a 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -443,16 +443,11 @@ sub handler : method $self->get_user; my $status = $self->handler_guts; - - # moving this here causes unit test failures - need to check why - # before committing the move - #$status = $self->__call_process_view unless $self->output; - return $status unless $status == OK; # TODO: require send_output to return a status code $self->send_output; - + return $status; } diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 6ae19f5..1442d0e 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -113,8 +113,9 @@ sub do_edit : Exported my $table = $r->table; my $required_cols = $config->{$table}->{required_cols} || []; + my $ignored_cols = $r->{config}{ $r->{table} }{ignore_cols}; - ($obj, my $fatal, my $creating) = $self->_do_update_or_create($r, $obj, $required_cols); + ($obj, my $fatal, my $creating) = $self->_do_update_or_create($r, $obj, $required_cols, $ignored_cols); # handle errors, if none, proceed to view the newly created/updated object my %errors = $fatal ? (FATAL => $fatal) : $obj->cgi_update_errors; @@ -140,7 +141,7 @@ sub do_edit : Exported # reported by Mp::P::Trace sub _do_update_or_create { - my ($self, $r, $obj, $required_cols) = @_; + my ($self, $r, $obj, $required_cols, $ignored_cols) = @_; my $fatal; my $creating = 0; @@ -150,13 +151,19 @@ sub _do_update_or_create if ($obj) { # We have something to edit - eval { $obj->update_from_cgi( $h => {required => $required_cols} ) }; + eval { $obj->update_from_cgi( $h => { + required => $required_cols, + ignore => $ignored_cols, + } ) }; $fatal = $@; } - else + else { - eval { - $obj = $self->create_from_cgi( $h => {required => $required_cols} ) + eval { + $obj = $self->create_from_cgi( $h => { + required => $required_cols, + ignore => $ignored_cols, + } ) }; if ($fatal = $@) @@ -168,14 +175,22 @@ sub _do_update_or_create return $obj, $fatal, $creating; } - + sub delete : Exported { - return shift->SUPER::delete(@_) if caller ne "Maypole::Model::Base"; - my ( $self, $r ) = @_; - $_->SUPER::delete for @{ $r->objects || [] }; - $r->objects( [ $self->retrieve_all ] ); - $r->{template} = "list"; - $self->list($r); + my $self = shift; + my ($sub) = (caller(1))[3]; + $sub =~ /^(.+)::([^:]+)$/; + # So subclasses can still send search down ... + return ($1 ne "Maypole::Model::Base" && $2 ne "delete") ? + $self->SUPER::search(@_) : $self->do_delete(@_); +} + +sub do_delete { + my ( $self, $r ) = @_; + $_->SUPER::delete for @{ $r->objects || [] }; + $r->objects( [ $self->retrieve_all ] ); + $r->{template} = "list"; + $self->list($r); } sub stringify_column { @@ -197,9 +212,15 @@ sub adopt { } sub search : Exported { - return shift->SUPER::search(@_) if caller ne "Maypole::Model::Base"; + my $self = shift; + my ($sub) = (caller(1))[3]; + $sub =~ /^(.+)::([^:]+)$/; + # So subclasses can still send search down ... + return ($1 ne "Maypole::Model::Base" && $2 ne "search") ? + $self->SUPER::search(@_) : $self->do_search(@_); +} - # A real CDBI search. +sub do_search : Exported { my ( $self, $r ) = @_; my %fields = map { $_ => 1 } $self->columns; my $oper = "like"; # For now diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm index 0280e1e..fd71b48 100644 --- a/lib/Maypole/View/TT.pm +++ b/lib/Maypole/View/TT.pm @@ -276,6 +276,34 @@ and useful macros in the templates/ directory of the package and these are used in the beerdb and default templates. See the MACRO section of the L documentation. +=head1 ACCESSING MAYPOLE VALUES + +=head2 request + +You can access the request in your templates in order to see the action, table, etc as well +as parameters passed through forms : + +for example + +Hello [% request.params.forename %] [% request.params.surname %] ! + +or + +Are you want to [% request.action %] in the [% request.table %] ? + +=head2 config + +You can access your maypole application configuration through the config variable : + + + +=head2 object and objects + +Objects are passed to the request using r->objects($arrayref) and are accessed in the templates +as an array called objects. + +[% FOR objects %] [% object %] [% END %] + =head1 MAYPOLE MACROS AND FILTERS Maypole provides a collection of useful and powerful macros in the templates/factory/macros diff --git a/lib/Maypole/templates/factory/addnew b/lib/Maypole/templates/factory/addnew index bf2b9ce..2334496 100644 --- a/lib/Maypole/templates/factory/addnew +++ b/lib/Maypole/templates/factory/addnew @@ -30,7 +30,7 @@ table. elem.as_XML; %] [% IF errors.$col %] - [% errors.$col %] + [% errors.$col | html %] [% END %] [% END; %] diff --git a/lib/Maypole/templates/factory/login b/lib/Maypole/templates/factory/login index 266921a..af08e5b 100644 --- a/lib/Maypole/templates/factory/login +++ b/lib/Maypole/templates/factory/login @@ -1,22 +1,24 @@ [% PROCESS macros %] [% INCLUDE header %] [% INCLUDE title %] +[% user_field = config.auth.user_field || "user" %] +
You need to log in
[% IF login_error %] -
[% login_error %]
+
[% login_error | html %]
[% END %]
Login
diff --git a/lib/Maypole/templates/factory/macros b/lib/Maypole/templates/factory/macros index a102c73..cbf58bb 100644 --- a/lib/Maypole/templates/factory/macros +++ b/lib/Maypole/templates/factory/macros @@ -16,7 +16,7 @@ MACRO link(table, command, additional, label) BLOCK; SET lnk = base _ "/" _ table _ "/" _ command _ "/" _ additional; lnk = lnk | uri | html; ''; - label; + label | html; ""; END; %] @@ -37,7 +37,7 @@ MACRO maybe_link_view(object) BLOCK; IF object.isa('Maypole::Model::Base'); link(object.table, "view", object.id.join('/'), object); ELSE; - object; + object | html ; END; END; %] @@ -58,7 +58,7 @@ for some. NEXT IF col == "id" OR col == classmetadata.table _ "_id"; ""; IF col == "url" AND item.url; - ' '; item.url; ''; + ' '; item.url; ''; ELSIF col == classmetadata.stringify_column; maybe_link_view(item); ELSE; @@ -129,12 +129,12 @@ This takes an object and and displays its properties in a table. #%] [% MACRO view_item(item) BLOCK; %] [% SET string = classmetadata.stringify_column %] -
[% item.$string %]
+
[% item.$string | html %]
[% INCLUDE navbar %] - + [% FOR col = classmetadata.columns.list; NEXT IF col == "id" OR col == string OR col == classmetadata.table _ "_id";; @@ -152,7 +152,7 @@ from the C method:
[% classmetadata.colnames.$string %][% item.$string %][% item.$string | html %]
[% classmetadata.colnames.$col; %] [% IF col == "url" && item.url; # Possibly too much magic. - ' '; item.url; ''; + ' '; item.url; ''; ELSE; maybe_link_view(item.$col); END; %] -- 2.39.2