fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-10-03 05:44 am

[dw-free] convert htdocs/invite.bml to TT

[commit: http://hg.dwscoalition.org/dw-free/rev/499ca7b84a26]

http://bugs.dwscoalition.org/show_bug.cgi?id=3954

BML file -> controller and .tt files.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/DW/Controller/InviteCodes.pm
  • cgi-bin/DW/Template/Plugin/FormHTML.pm
  • htdocs/invite.bml
  • htdocs/invite.bml.text
  • views/invite/index.tt
  • views/invite/index.tt.text
--------------------------------------------------------------------------------
diff -r 3c1dde8411c1 -r 499ca7b84a26 cgi-bin/DW/Controller/InviteCodes.pm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Controller/InviteCodes.pm	Mon Oct 03 13:44:00 2011 +0800
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+#
+# DW::Controller::InviteCodes
+#
+# Tools for managing invite codes, including generating an image
+# that shows the current status of a given invite code.
+#
+# Authors:
+#      Jen Griffin <kareila@livejournal.com>
+#
+# Copyright (c) 2011 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package DW::Controller::InviteCodes;
+
+use strict;
+use DW::Routing;
+use DW::Template;
+use DW::Controller;
+
+use DW::InviteCodes;
+use DW::InviteCodeRequests;
+use DW::BusinessRules::InviteCodeRequests;
+
+DW::Routing->register_string( '/invite/index', \&management_handler, app => 1 );
+
+sub management_handler {
+    my $r = DW::Request->get;
+    my ( $ok, $rv ) = controller();
+    return $rv unless $ok;
+
+    my $remote = $rv->{remote};
+
+    # check whether we requested more invite codes
+    if ( LJ::did_post() ) {
+        my $args = $r->post_args;
+        return error_ml( 'error.invalidform' )
+            unless LJ::check_form_auth( $args->{lj_form_auth} );
+
+        if ( DW::InviteCodeRequests->create( userid => $remote->id, reason => $args->{reason} ) ) {
+            $rv->{req_yes} = 1;
+        } else {
+            $rv->{req_no} = 1;
+        }
+    }
+
+    $rv->{print_req_form} = DW::BusinessRules::InviteCodeRequests::can_request( user => $remote );
+    $rv->{view_full} = $r->get_args->{full};
+
+    my @invitecodes = DW::InviteCodes->by_owner( userid => $remote->id );
+
+    my @recipient_ids;
+    foreach my $code ( @invitecodes ) {
+        push @recipient_ids, $code->recipient if $code->recipient;
+    }
+
+    my $recipient_users = LJ::load_userids( @recipient_ids );
+
+    unless ( $rv->{view_full} ) {
+        # filter out codes that were used over two weeks ago
+        my $two_weeks_ago = time() - ( 14 * 24 * 60 * 60 );
+        @invitecodes = grep {
+            my $u = $recipient_users->{$_->recipient};
+            # if it's used, we should always have a recipient, but...
+            ! $_->is_used || ( $u && $u->timecreate ) > $two_weeks_ago
+        } @invitecodes;
+    }
+
+    # sort so that invite codes end up in this order:
+    #  - unsent and unused
+    #  - sent but unused, with earliest sent first
+    #  - used
+    @invitecodes = sort {
+        return $a->is_used <=> $b->is_used if $a->is_used != $b->is_used;
+        return $a->timesent <=> $b->timesent;
+    } @invitecodes;
+
+    $rv->{has_codes} = scalar @invitecodes;
+    $rv->{invitecodes} = \@invitecodes;
+    $rv->{users} = $recipient_users;
+
+    $rv->{create_link} = sub {
+        my ( $code ) = @_;
+        my $root = $LJ::USE_SSL ? $LJ::SSLROOT : $LJ::SITEROOT;
+        return "$root/create?from=$remote->{user}&code=$code";
+    };
+    $rv->{time_to_http} = sub { return $_[0] ? LJ::time_to_http( $_[0] ) : '' };
+
+    return DW::Template->render_template( 'invite/index.tt', $rv );
+}
+
+1;
diff -r 3c1dde8411c1 -r 499ca7b84a26 cgi-bin/DW/Template/Plugin/FormHTML.pm
--- a/cgi-bin/DW/Template/Plugin/FormHTML.pm	Mon Oct 03 13:41:38 2011 +0800
+++ b/cgi-bin/DW/Template/Plugin/FormHTML.pm	Mon Oct 03 13:44:00 2011 +0800
@@ -155,6 +155,19 @@
     return $ret;
 }
 
+=head2 [% form.submit( name =... ) %]
+
+Return a button for submitting a form. Values are prepopulated by the plugin's datasource.
+
+=cut
+
+sub submit {
+    my ( $self, $args ) = @_;
+
+    $self->_process_value_and_label( $args );
+    return LJ::html_submit( delete $args->{name}, delete $args->{value}, $args );
+}
+
 =head2 [% form.textarea( label=... ) %]
 
 Return a textarea with a matching label, if provided. Values are prepopulated
diff -r 3c1dde8411c1 -r 499ca7b84a26 htdocs/invite.bml
--- a/htdocs/invite.bml	Mon Oct 03 13:41:38 2011 +0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-<?_c
-#
-# manage/invitecodes.bml
-#
-# Invite code management system (user-facing).
-#
-# Authors:
-#      Afuna <coder.dw@afunamatata.com>
-#
-# Copyright (c) 2009 by Dreamwidth Studios, LLC.
-#
-# This program is free software; you may redistribute it and/or modify it under
-# the same terms as Perl itself.  For a copy of the license, please reference
-# 'perldoc perlartistic' or 'perldoc perlgpl'.
-#
-_c?>
-<?page
-title=>Invite Codes
-body<=
-<?_code
-{
-    use strict;
-
-    return LJ::server_down_html() if ($LJ::SERVER_DOWN);
-
-    my $remote = LJ::get_remote();
-    return "<?needlogin?>"
-        unless $remote;
-
-    my $ret;
-
-    if ( LJ::did_post() ) {
-        return "<?h1 $ML{'Error'} ?h1> $ML{'error.invalidform'}" unless LJ::check_form_auth();
-        if ( DW::InviteCodeRequests->create( userid => $remote->id, reason => $POST{reason} ) ) {
-            $ret .= "<div class='highlight-box'>$ML{'.msg.request.success'}</div>";
-        } else {
-            $ret .= "<?errorbar $ML{'.msg.request.error'} errorbar?>";
-        }
-    }
-
-    if ( DW::BusinessRules::InviteCodeRequests::can_request( user => $remote ) ) {
-        $ret .= "<?h2 $ML{'.form.request.header'} h2?>";
-        $ret .= "<?p $ML{'.form.request.intro'} p?>";
-        $ret .= "<div><form method='POST'>";
-        $ret .= LJ::form_auth();
-        $ret .= LJ::labelfy( 'reason', $ML{'.form.request.reason'} );
-        $ret .= LJ::html_text( { name => 'reason', id => 'reason', size => 75, maxlength => 255  } );
-        $ret .= LJ::html_submit( value => $ML{'.form.request.submit'} );
-        $ret .= "</form></div>";
-    }
-
-    if ( $GET{full} ) {
-        $ret .= "<p>" . LJ::Lang::ml( '.label.viewing.full', { aopts => "href='/invite'" } ) . "</p>";
-    } else {
-        $ret .= "<p>" . LJ::Lang::ml( '.label.viewing.partial', { aopts => "href='/invite?full=1'" } ) . "</p>";
-    }
-
-    my @invitecodes = DW::InviteCodes->by_owner( userid => $remote->id );
-
-    my @recipient_ids;
-    foreach my $code ( @invitecodes ) {
-        push @recipient_ids, $code->recipient if $code->recipient;
-    }
-
-    my $recipient_users = LJ::load_userids( @recipient_ids );
-
-    unless ( $GET{full} ) {
-        # filter out codes that were used over two weeks ago
-        my $two_weeks_ago = time() - ( 14 * 24 * 60 * 60 );
-        @invitecodes = grep {
-            my $u = $recipient_users->{$_->recipient};
-            # if it's used, we should always have a recipient, but...
-            ! $_->is_used || ( $u && $u->timecreate ) > $two_weeks_ago
-        } @invitecodes;
-    }
-
-    if ( @invitecodes ) {
-
-        $ret .= "<p>" . LJ::Lang::ml( '.label.send', { aopts => "href='/manage/circle/invite'" } ) . "</p>";
-
-        # sort so that invite codes end up in this order:
-        #  - unsent and unused
-        #  - sent but unused, with earliest sent first
-        #  - used
-        @invitecodes = sort {
-            return $a->is_used <=> $b->is_used if $a->is_used != $b->is_used;
-            return $a->timesent <=> $b->timesent;
-        } @invitecodes;
-
-
-        $ret .= "<table class='invitecodes' id='invitecodes'><thead><tr><th>$ML{'.header.code'}</th><th>$ML{'.header.recipient'}</th><th width='200'>$ML{'.header.used'}</th><th width='200'>$ML{'.header.sent'}</th><th>$ML{'.header.email'}</th></tr></thead>";
-
-        foreach my $code ( @invitecodes ) {
-            $ret .= "<tr>";
-            $ret .= "<td><tt>".$code->code."</tt></td>";
-            $ret .= "<td>";
-
-            if( $code->is_used ) {
-                my $u = $recipient_users->{$code->recipient};
-                $ret .= $u->ljuser_display;
-            } else {
-                my $create_link = ($LJ::USE_SSL ? $LJ::SSLROOT : $LJ::SITEROOT)
-                    . "/create?from=$remote->{user}&code=".$code->code;
-                $ret .= BML::ml( '.code.use', { aopts => "href='$create_link'" } );
-            }
-
-            $ret .= "</td>";
-
-            $ret .= "<td>";
-            if ( $code->is_used ) {
-                my $u = $recipient_users->{$code->recipient};
-                my $timeused = $u->timecreate;
-                $ret .= LJ::time_to_http( $timeused ) if $timeused;
-            }
-            $ret .= "</td>";
-
-            $ret .= "<td>";
-            $ret .= LJ::time_to_http( $code->timesent ) if $code->timesent;
-            $ret .= "</td>";
-
-            $ret .= "<td>";
-            $ret .= $code->email;
-            $ret .= "</td>";
-
-            $ret .= "</tr>";
-        }
-
-        $ret .= "</table>";
-    } elsif ( $GET{full} ) {
-        $ret .= "<?p $ML{'.noinvitecodes'} p?>";
-    } else {
-        $ret .= "<?p $ML{'.noinvitecodes.partial'} p?>";
-   }
-
-    return $ret;
-} _code?>
-<=body
-page?>
diff -r 3c1dde8411c1 -r 499ca7b84a26 htdocs/invite.bml.text
--- a/htdocs/invite.bml.text	Mon Oct 03 13:41:38 2011 +0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-;; -*- coding: utf-8 -*-
-.code.use=<a [[aopts]]>Use this code</a>
-
-.form.request.header=Request More Invite Codes
-
-.form.request.intro=Are you out of invite codes but still know people you'd like to invite to our site? Enter a short message below to ask for an invite, and a site administrator will review your request.
-
-.form.request.reason=Reason:
-
-.form.request.submit=Request invites:
-
-.header.code=Code:
-
-.header.email=Sent to email:
-
-.header.recipient=Recipient:
-
-.header.sent=Sent on:
-
-.header.used=Used on:
-
-.label.send=You can <a [[aopts]]>email an invite code to a friend.</a>
-
-.label.viewing.full=Here is a full list of your invite codes. See only those which are <a [[aopts]]>unused, or used but recently sent</a>.
-
-.label.viewing.partial=Here are your unused and recently sent invite codes. See the <a [[aopts]]>full list of your invite codes</a>.
-
-.msg.request.error=Your request didn't go through.
-
-.msg.request.success=Your request for new invite codes has been forwarded to site administrators for review.
-
-.noinvitecodes=You don't have any invite codes.
-
-.noinvitecodes.partial=You have no unused or recently sent invite codes.
-
diff -r 3c1dde8411c1 -r 499ca7b84a26 views/invite/index.tt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/invite/index.tt	Mon Oct 03 13:44:00 2011 +0800
@@ -0,0 +1,77 @@
+[%# TT conversion of manage/invitecodes.bml
+  # Invite code management system (user-facing).
+  #
+  # Authors:
+  #      Jen Griffin <kareila@livejournal.com>
+  #
+  # Copyright (c) 2011 by Dreamwidth Studios, LLC.
+  #
+  # This program is free software; you may redistribute it and/or modify it
+  # under the same terms as Perl itself. For a copy of the license, please
+  # reference 'perldoc perlartistic' or 'perldoc perlgpl'.
+  #
+%]
+
+[%- sections.title='.title' | ml -%]
+
+[%- IF req_yes -%]
+    <div class='highlight-box'>[% '.msg.request.success' | ml %]</div>
+[%- ELSIF req_no -%]
+    <div class='error-box'>[% '.msg.request.error' | ml %]</div>
+[%- END -%]
+
+[%- IF print_req_form -%]
+    <h2>[% '.form.request.header' | ml %]</h2>
+    <p>[% '.form.request.intro' | ml %]</p>
+    <div><form method='POST'>
+    [% dw.form_auth;
+    reason_label = '.form.request.reason' | ml;
+    submit_label = '.form.request.submit' | ml;
+    form.textbox( label = reason_label, name = 'reason', id = 'reason',
+                  size = 75, maxlength = 255 );
+    form.submit( value = submit_label ) %]
+    </form></div>
+[%- END -%]
+
+[%- IF view_full;
+        viewing_label = '.label.viewing.full' | ml(aopts = "href='/invite'");
+    ELSE;
+        viewing_label = '.label.viewing.partial' | ml(aopts = "href='/invite?full=1'");
+    END -%]
+<p>[% viewing_label %]</p>
+
+[%- IF has_codes -%]
+    <p>[% '.label.send' | ml(aopts = "href='/manage/circle/invite'") %]</p>
+    <table class='invitecodes' id='invitecodes'>
+      <thead><tr>
+        <th>[% '.header.code' | ml %]</th>
+        <th>[% '.header.recipient' | ml %]</th>
+        <th width='200'>[% '.header.used' | ml %]</th>
+        <th width='200'>[% '.header.sent' | ml %]</th>
+        <th>[% '.header.email' | ml %]</th>
+      </tr></thead>
+
+    [%- FOREACH code = invitecodes;
+                IF code.is_used; recuser = code.recipient; END -%]
+      <tr>
+        <td><tt>[% code.code %]</tt></td>
+        <td>
+        [%- IF code.is_used;
+                users.$recuser.ljuser_display;
+            ELSE;
+                link = create_link( code.code );
+                '.code.use' | ml(aopts = "href='$link'");
+            END -%]
+        </td><td>
+        [% IF code.is_used; time_to_http( users.$recuser.timecreate ); END %]
+        </td><td>
+        [% time_to_http( code.timesent ) %]
+        </td><td>[% code.email %]</td>
+      </tr>
+    [% END %]
+    </table>
+
+[%- ELSE -%]
+    <p>[% IF view_full; '.noinvitecodes' | ml;
+          ELSE; '.noinvitecodes.partial' | ml; END %]</p>
+[%- END -%]
diff -r 3c1dde8411c1 -r 499ca7b84a26 views/invite/index.tt.text
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/invite/index.tt.text	Mon Oct 03 13:44:00 2011 +0800
@@ -0,0 +1,36 @@
+;; -*- coding: utf-8 -*-
+.code.use=<a [[aopts]]>Use this code</a>
+
+.form.request.header=Request More Invite Codes
+
+.form.request.intro=Are you out of invite codes but still know people you'd like to invite to our site? Enter a short message below to ask for an invite, and a site administrator will review your request.
+
+.form.request.reason=Reason:
+
+.form.request.submit=Request invites:
+
+.header.code=Code:
+
+.header.email=Sent to email:
+
+.header.recipient=Recipient:
+
+.header.sent=Sent on:
+
+.header.used=Used on:
+
+.label.send=You can <a [[aopts]]>email an invite code to a friend.</a>
+
+.label.viewing.full=Here is a full list of your invite codes. See only those which are <a [[aopts]]>unused, or used but recently sent</a>.
+
+.label.viewing.partial=Here are your unused and recently sent invite codes. See the <a [[aopts]]>full list of your invite codes</a>.
+
+.msg.request.error=Your request didn't go through.
+
+.msg.request.success=Your request for new invite codes has been forwarded to site administrators for review.
+
+.noinvitecodes=You don't have any invite codes.
+
+.noinvitecodes.partial=You have no unused or recently sent invite codes.
+
+.title=Invite Codes
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org