[Jifty-commit] r4103 - in jifty/branches/virtual-models: . lib/Jifty lib/Jifty/View/Declare share/web/static/css

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Sep 12 22:09:14 EDT 2007


Author: sterling
Date: Wed Sep 12 22:09:13 2007
New Revision: 4103

Modified:
   jifty/branches/virtual-models/   (props changed)
   jifty/branches/virtual-models/lib/Jifty/DateTime.pm
   jifty/branches/virtual-models/lib/Jifty/Script/Schema.pm
   jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
   jifty/branches/virtual-models/lib/Jifty/View/Declare/Page.pm
   jifty/branches/virtual-models/share/web/static/css/notices.css

Log:
 r12046 at dynpc145:  andrew | 2007-09-12 21:04:48 -0500
 Merge down from trunk.
  r11951 at dynpc145:  andrew | 2007-09-11 15:04:01 -0500
  Clean up the Pod, added a Synopsis, added a Why? section, added code comments, and some code tidying.
  r11956 at dynpc145:  andrew | 2007-09-11 16:38:08 -0500
  Adding another CRUD setup example to the synopsis.
  r11959 at dynpc145:  andrew | 2007-09-11 17:15:52 -0500
  Don't override object_type if the CRUD view package already defines object_type.
  r12003 at dynpc145:  andrew | 2007-09-11 21:44:01 -0500
  Fixing a bug that prevents any but the first plugin being checked for schema updates.
  r12004 at dynpc145:  andrew | 2007-09-11 21:46:41 -0500
  Plugin upgrade incorrectly assumes a DB version of 0.0.1 when none is found.
  r12007 at dynpc145:  andrew | 2007-09-11 21:54:00 -0500
  Bring the default back, but at 0.0.0 to prevent uninitialized complaints.
  r12040 at dynpc145:  andrew | 2007-09-12 15:41:46 -0500
  Added missing jifty-result-popup div to the page detritus section of Jifty::View::Declare::Page.
 


Modified: jifty/branches/virtual-models/lib/Jifty/DateTime.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/DateTime.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/DateTime.pm	Wed Sep 12 22:09:13 2007
@@ -7,6 +7,18 @@
 
 Jifty::DateTime - a DateTime subclass that knows about Jifty users
 
+=head1 SYNOPSIS
+
+  use Jifty::DateTime;
+  
+  # Get the current date and time
+  my $dt = Jifty::DateTime->now;
+  
+  # Print out the pretty date (i.e., today, tomorrow, yesterday, or 2007-09-11)
+  Jifty->web->out( $dt->friendly_date );
+
+  # Better date parsing
+  my $dt_from_human = Jifty::DateTime->new_from_string("next Saturday");
 
 =head1 DESCRIPTION
 
@@ -14,6 +26,8 @@
 without timezone. This class loads and parses dates and sets them
 into the proper timezone.
 
+To use this DateTime class to it's fullest ability, you'll need to add a C<time_zone> method to your application's user object class. This is the class returned by L<Jifty::CurrentUser/user_object>. It must return a value valid for using as an argument to L<DateTime>'s C<set_time_zone()> method.
+
 =cut
 
 BEGIN {
@@ -27,7 +41,6 @@
 
 use base qw(Jifty::Object DateTime);
 
-
 =head2 new ARGS
 
 See L<DateTime/new>. If we get what appears to be a date, then we
@@ -42,7 +55,12 @@
     my %args  = (@_);
     my $self  = $class->SUPER::new(%args);
 
+    # XXX What if they really mean midnight offset by time zone?
+
+    # Do not bother with time zones unless time is used, we assume that
+    # 00:00:00 implies that no time is used
     if ($self->hour || $self->minute || $self->second) {
+
         # Unless the user has explicitly said they want a floating time,
         # we want to convert to the end-user's timezone.  This is
         # complicated by the fact that DateTime auto-appends
@@ -51,6 +69,8 @@
             $self->set_time_zone( $tz );
         }
     }
+
+    # No time, just use the floating time zone
     else {
         $self->set_time_zone("floating");
     }
@@ -60,15 +80,21 @@
 
 =head2 current_user_has_timezone
 
-Return timezone if the current user has it
+Return timezone if the current user has one. This is determined by checking to see if the current user has a user object. If it has a user object, then it checks to see if that user object has a C<time_zone> method and uses that to determine the value.
 
 =cut
 
 sub current_user_has_timezone {
     my $self = shift;
     $self->_get_current_user();
+
+    # Can't continue if we have no notion of a user_object
     return unless $self->current_user->can('user_object');
+
+    # Can't continue unless the user object is defined
     my $user_obj = $self->current_user->user_object or return;
+
+    # Check for a time_zone method and then use it if it exists
     my $f = $user_obj->can('time_zone') or return;
     return $f->($user_obj);
 }
@@ -80,6 +106,8 @@
 it in the floating timezone, otherwise, set it to the current user's
 timezone.
 
+As of this writing, this uses L<Date::Manip> along with some internal hacks to alter the way L<Date::Manip> normally interprets week day names. This may change in the future.
+
 =cut
 
 sub new_from_string {
@@ -87,6 +115,7 @@
     my $string = shift;
     my $now;
 
+    # Hack to use Date::Manip to flexibly scan dates from strings
     {
         # Date::Manip interprets days of the week (eg, ''monday'') as
         # days within the *current* week. Detect these and prepend
@@ -102,13 +131,18 @@
         Date::Manip::Date_Init("TZ=GMT");
         $now = Date::Manip::UnixDate( $string, "%o" );
     }
+
+    # Stop here if Date::Manip couldn't figure it out
     return undef unless $now;
+
+    # Build a DateTime object from the Date::Manip value and setup the TZ
     my $self = $class->from_epoch( epoch => $now, time_zone => 'gmt' );
     if (my $tz = $self->current_user_has_timezone) {
         $self->set_time_zone("floating")
             unless ( $self->hour or $self->minute or $self->second );
         $self->set_time_zone( $tz );
     }
+
     return $self;
 }
 
@@ -124,24 +158,48 @@
     my $self = shift;
     my $ymd = $self->ymd;
 
+    # Use the current user's time zone on the date
     my $tz = $self->current_user_has_timezone || $self->time_zone;
     my $rel = DateTime->now( time_zone => $tz );
 
+    # Is it today?
     if ($ymd eq $rel->ymd) {
         return "today";
     }
     
+    # Is it yesterday?
     my $yesterday = $rel->clone->subtract(days => 1);
     if ($ymd eq $yesterday->ymd) {
         return "yesterday";
     }
     
+    # Is it tomorrow?
     my $tomorrow = $rel->clone->add(days => 1);
     if ($ymd eq $tomorrow->ymd) {
         return "tomorrow";
     }
     
+    # None of the above, just spit out the date
     return $ymd;
 }
 
+=head1 WHY?
+
+There are other ways to do some of these things and some of the decisions here may seem arbitrary, particularly if you read the code. They are.
+
+These things are valuable to applications built by Best Practical Solutions, so it's here. If you disagree with the policy or need to do it differently, then you probably need to implement something yourself using a DateTime::Format::* class or your own code. 
+
+Parts may be cleaned up and the API cleared up a bit more in the future.
+
+=head1 SEE ALSO
+
+L<DateTime>, L<DateTime::TimeZone>, L<Jifty::CurrentUser>
+
+=head1 LICENSE
+
+Jifty is Copyright 2005-2007 Best Practical Solutions, LLC.
+Jifty is distributed under the same terms as Perl itself.
+
+=cut
+
 1;

Modified: jifty/branches/virtual-models/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Script/Schema.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Script/Schema.pm	Wed Sep 12 22:09:13 2007
@@ -344,10 +344,10 @@
 
     for my $plugin (Jifty->plugins) {
         my $plugin_class = ref $plugin;
-        my $dbv  = version->new( Jifty::Model::Metadata->load($plugin_class . '_version') || '0.0.1' );
+        my $dbv  = version->new( Jifty::Model::Metadata->load($plugin_class . '_version') || '0.0.0' );
         my $appv = version->new( $plugin->version );
 
-        return unless $self->upgrade_tables( $plugin_class, $dbv, $appv, $plugin->upgrade_class );
+        next unless $self->upgrade_tables( $plugin_class, $dbv, $appv, $plugin->upgrade_class );
         if ( $self->{print} ) {
             warn "Need to upgrade ${plugin_class}_db_version to $appv here!";
         } else {

Modified: jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/View/Declare/CRUD.pm	Wed Sep 12 22:09:13 2007
@@ -18,13 +18,40 @@
 
 =head1 SYNOPSIS
 
+  package App::View::User;
+  use Jifty::View::Declare -base;
+  use base qw/ Jifty::View::Declare::CRUD /;
+
+  template 'view' => sub {
+      # customize the view
+  };
+
+  1;
+
+  package App::View::Tag;
+  use Jifty::View::Declare -base;
+  use base qw/ Jifty::View::Declare::CRUD /;
+
+  template 'view' => sub {
+      # customize the view
+  };
+
+  1;
+
   package App::View;
   use Jifty::View::Declare -base;
 
   use Jifty::View::Declare::CRUD;
+
+  # If you have customizations, this is a good way...
   Jifty::View::Declare::CRUD->mount_view('User');
   Jifty::View::Declare::CRUD->mount_view('Category', 'App::View::Tag', '/tag');
 
+  # Another way to do the above, good for quick and dirty
+  alias Jifty::View::Declare::CRUD under '/admin/blog', {
+      object_type => 'BlogPost',
+  };
+
 =head1 DESCRIPTION
 
 This class provides a set of views that may be used by a model to display
@@ -81,7 +108,10 @@
 
     # Override object_type
     no strict 'refs';
-    *{$vclass."::object_type"} = sub { $model };
+    my $object_type = $vclass."::object_type";
+
+    # Avoid the override if object_type() is already defined
+    *{$object_type} = sub { $model } unless defined *{$object_type};
 }
 
 # XXX TODO FIXME This is related to the trimclient branch and performs some

Modified: jifty/branches/virtual-models/lib/Jifty/View/Declare/Page.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/View/Declare/Page.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/View/Declare/Page.pm	Wed Sep 12 22:09:13 2007
@@ -192,6 +192,8 @@
     show('/keybindings');
     with( id => "jifty-wait-message", style => "display: none" ),
         div { _('Loading...') };
+    with( id => "jifty-result-popup", style => "display: none" ),
+        div { };
 
     # This is required for jifty server push.  If you maintain your own
     # wrapper, make sure you have this as well.

Modified: jifty/branches/virtual-models/share/web/static/css/notices.css
==============================================================================
--- jifty/branches/virtual-models/share/web/static/css/notices.css	(original)
+++ jifty/branches/virtual-models/share/web/static/css/notices.css	Wed Sep 12 22:09:13 2007
@@ -37,3 +37,24 @@
     text-indent: -9999em;
 }
 
+#jifty-result-popup {
+    bottom: 0.6em;
+    position: fixed;
+    right: 0;
+    width: 180px;
+    z-index: 43;
+}
+
+#jifty-result-popup .popup_notification {
+     background: #A9B7FF url(/static/images/silk/information.png) no-repeat scroll 5px center;
+     border: 1px solid #004E75;
+     overflow: hidden;
+     padding: 0.5em 0.5em 0.5em 27px;
+}
+
+#jifty-result-popup .result-error {
+    background: #FFA8A8 url(/static/images/silk/error.png) no-repeat scroll 5px center;
+    border: 1px solid #B71111;
+    color: #B71111;
+}
+


More information about the Jifty-commit mailing list