[Yapcom checkin] rev 30 - lib/YAPC t t/lib/YAPC/Test templates

[prev] [thread] [next] [lurker] [Date index for 2003/11/24]

From: svn
Subject: [Yapcom checkin] rev 30 - lib/YAPC t t/lib/YAPC/Test templates
Date: 22:56 on 24 Nov 2003
Author: gabor
Date: 2003-11-24 22:56:38 +0200 (Mon, 24 Nov 2003)
New Revision: 30

Modified:
   lib/YAPC/Organizer.pm
   lib/YAPC/Talk.pm
   t/05-web-proposals.t
   t/lib/YAPC/Test/Data.pm
   templates/proposal.tmpl
Log:
clean up the send_proposal run_mode

Modified: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	2003-11-24 20:03:35 UTC (rev 29)
+++ lib/YAPC/Organizer.pm	2003-11-24 20:56:38 UTC (rev 30)
@@ -76,6 +76,9 @@
           return;
        }
    }       
+
+   if ($page eq 'proposal') { $self->prerun_mode('send_proposal') }
+
 =poc
    if (grep {$_ eq $page} @admin_pages) {
        if (my $id = $self->is_logged_in) {
@@ -107,16 +110,6 @@
 
     my $id = $self->is_logged_in;
 
-    if ($id and $page eq 'proposal') {
-       my $t = $self->_server_page($page, $filename);
-       $t->param(run => 'send_proposal');
-       my @length_selection = map {{ value => $_, text => $_} } @YAPC::Config::proposal_lengths;
-       $t->param(length => \@length_selection);
-       my @language_selection = map {{ value => $_, text => $_} } @YAPC::Config::proposal_languages;
-       $t->param(language => \@language_selection);
-       return $t->output;
-    }
-
     if ($id) {
        if (grep {$_ eq $page} @admin_pages) {
           my ($person) = YAPC::Person->search(id => $id); 
@@ -487,52 +480,71 @@
     }
 }
 
+sub build_prop_page {
+   my $self = shift;
+   my $q = $self->query;
+   my $t = shift;
+
+
+   my $length = $q->param('length') || '';
+   my $language = $q->param('language') || '';
+   my @length_selection = map {{ value => $_, text => $_, selected => ($length eq $_)} } @YAPC::Config::proposal_lengths;
+   $t->param(length => \@length_selection);
+   my @language_selection = map {{ value => $_, text => $_, selected => ($language eq $_)} } @YAPC::Config::proposal_languages;
+   $t->param(language => \@language_selection);
+   return $t->output;
+   #$t->param(run => 'send_proposal');
+}
 sub do_send_proposal {
     my $self = shift;
     my $q = $self->query;
-
     my $talk;
     my $id = $self->is_logged_in;
 
-    eval {
-       $talk = YAPC::Talk->propose($q->Vars, user_id => $id);
-    };
-    if ($@) {
-       my $msg = $@;
-       my $t = $self->_server_page('send_proposal', "$templates_dir/proposal.tmpl");
-       $t->param(MESSAGE => 'There was an error in the provided data.');
-       my $length = $q->param('length');
-       my @length_selection = map {{ value => $_, text => $_, selected => ($length eq $_)} } @YAPC::Config::proposal_lengths;
-       $t->param(length => \@length_selection);
-       my $language = $q->param('language');
-       my @language_selection = map {{ value => $_, text => $_, selected => ($language eq $_)} } @YAPC::Config::proposal_languages;
-       $t->param(language => \@language_selection);
+    my $t = $self->_server_page('send_proposal', "$templates_dir/proposal.tmpl");
 
-       return $t->output;
-    } else {
-       my $person = $talk->user_id;
-       my $text = "Subject: " . $talk->title . "\n";
-       $text .= "Speaker: ". $person->fname . "  " . $person->lname . "  " . $person->email . "\n";
-       $text .= "Language: " . $talk->language . "\n";
-       $text .= "Length: " . $talk->length . "\n";
-       $text .= "Abstract: " . $talk->abstract . "\n"; 
-       $text .= "Comments: " . $talk->other . "\n"; 
+    if ($q->param('submit')) {
+       eval {
+         $talk = YAPC::Talk->propose($q->Vars, user_id => $id);
+       };
+       if ($@) {
+          my $msg = $@;
+          $t->param(MESSAGE => 'There was an error in the provided data.');
+          return $self->build_prop_page($t);
+       }
+    } else {  # first time on this page
+       return $self->build_prop_page($t);
+    }
 
-       # sending e-mail to administrator about new proposal
-       my %mail = (To      => $YAPC::Config::email_address,
-                   From    => $YAPC::Config::email_address,
-                   Subject => "[YAPC talk] " . $talk->title,
-                   Message => $text, 
-                  );
-       sendmail(%mail) or die $Mail::Sendmail::error unless $ENV{YAPCOM_NOMAIL};
+    # success
+    $self->send_new_proposal_to_admin($talk);
+    $t = $self->_server_page('thank_proposal', "$templates_dir/thank_proposal.tmpl");
+    return $t->output;
+}
 
-       my $t = $self->_server_page('thank_proposal', "$templates_dir/thank_proposal.tmpl");
-       return $t->output;
-    }
 
+sub send_new_proposal_to_admin {
+    my $self = shift;
+    my $talk = shift;
 
+    my $person = $talk->user_id;
+    my $text = "Subject: " . $talk->title . "\n";
+    $text .= "Speaker: ". $person->fname . "  " . $person->lname . "  " . $person->email . "\n";
+    $text .= "Language: " . $talk->language . "\n";
+    $text .= "Length: " . $talk->length . "\n";
+    $text .= "Abstract: " . $talk->abstract . "\n"; 
+    $text .= "Comments: " . $talk->other . "\n"; 
+
+       # sending e-mail to administrator about new proposal
+    my %mail = (To      => $YAPC::Config::email_address,
+                From    => $YAPC::Config::email_address,
+                Subject => "[YAPC talk] " . $talk->title,
+                Message => $text, 
+               );
+    sendmail(%mail) or die $Mail::Sendmail::error unless $ENV{YAPCOM_NOMAIL};
 }
 
+
 1;
 
 

Modified: lib/YAPC/Talk.pm
===================================================================
--- lib/YAPC/Talk.pm	2003-11-24 20:03:35 UTC (rev 29)
+++ lib/YAPC/Talk.pm	2003-11-24 20:56:38 UTC (rev 30)
@@ -18,6 +18,7 @@
     my $self = shift;
     my %args = @_; # cookie =>    subject =>  language => 	 length =>   abstract =>  comment =>
     delete $args{run};    # was added for CGI::Application
+    delete $args{submit};    # was added for CGI::Application
 
 #    $args{user_id} = YAPC::Login->get_user_id(cookie => $args{cookie});
 #    delete $args{cookie};

Modified: t/05-web-proposals.t
===================================================================
--- t/05-web-proposals.t	2003-11-24 20:03:35 UTC (rev 29)
+++ t/05-web-proposals.t	2003-11-24 20:56:38 UTC (rev 30)
@@ -39,6 +39,8 @@
    $webapp->query($q);
    my $result = $webapp->run();
    like($result, qr/<h2>Submit Proposal<\/h2>/, 'proposal page received');
+   like($result, qr/<option value="English" >/, 'proposal page received');
+   like($result, qr/<option value="180" >/, 'proposal page received');
 }
 
 
@@ -51,6 +53,7 @@
    'language' => 'English',
    'abstract' => 'This is my abstract',
    'comment'  => 'There can be a comment, no ?',
+   'submit'   => 1,
 );
 
 ####### sending a proposal

Modified: t/lib/YAPC/Test/Data.pm
===================================================================
--- t/lib/YAPC/Test/Data.pm	2003-11-24 20:03:35 UTC (rev 29)
+++ t/lib/YAPC/Test/Data.pm	2003-11-24 20:56:38 UTC (rev 30)
@@ -134,6 +134,7 @@
     local $ENV{HTTP_COOKIE} = "Yapcom=$cookie";
     my %prop = %{$talks[$t]};
     $prop{run} = 'send_proposal';
+    $prop{submit} = 1;
     my $q = CGI->new(\%prop);
     my $webapp = YAPC::Organizer->new;
     $webapp->query($q);

Modified: templates/proposal.tmpl
===================================================================
--- templates/proposal.tmpl	2003-11-24 20:03:35 UTC (rev 29)
+++ templates/proposal.tmpl	2003-11-24 20:56:38 UTC (rev 30)
@@ -28,7 +28,7 @@
         <textarea cols=60 rows=20 name="abstract"><TMPL_VAR NAME=abstract></textarea></td></tr>
 <tr><td colspan="2">Comments and special requests to the organizers<br>
         <textarea cols=60 rows=10 name="comment"><TMPL_VAR NAME=comment></textarea></td></tr>
-<tr><td></td><td><input type="submit" value="Submit"></td></tr>
+<tr><td></td><td><input type="submit" name="submit" value="Submit"></td></tr>
 </table>
 </form>
 

Generated at 00:06 on 25 Nov 2003 by mariachi 0.51