changeset 87:663f0410ff39

Added a 'date_published' field to the Persona model, which allows us to get accurate information on new personas.
author Atul Varma <varmaa@toolness.com>
date Tue, 18 Mar 2008 12:03:48 -0500
parents f97c99f193fd
children 7870c445d9f3
files PersonasBackend/personas/forms.py PersonasBackend/personas/json_feeds.py PersonasBackend/personas/models.py PersonasBackend/personas/tests.py
diffstat 4 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/PersonasBackend/personas/forms.py	Thu Mar 13 18:23:59 2008 -0500
+++ b/PersonasBackend/personas/forms.py	Tue Mar 18 12:03:48 2008 -0500
@@ -9,7 +9,7 @@
 
     class Meta:
         model = models.Persona
-        exclude = ["owner", "popularity", "status"]
+        exclude = ["owner", "date_published", "popularity", "status"]
 
     def clean( self ):
         try:
--- a/PersonasBackend/personas/json_feeds.py	Thu Mar 13 18:23:59 2008 -0500
+++ b/PersonasBackend/personas/json_feeds.py	Tue Mar 18 12:03:48 2008 -0500
@@ -45,10 +45,7 @@
     for persona in published.order_by( "-popularity" )[:10]:
         isPopular[persona.id] = True
 
-    # TODO: This isn't really a good way of determining what the
-    # newest Personas are, because, for instance, the date_updated
-    # field is changed whenever a Persona's popularity is increased.
-    for persona in published.order_by( "-date_updated" )[:10]:
+    for persona in published.order_by( "-date_published" )[:10]:
         isNew[persona.id] = True
 
     for persona in published:
--- a/PersonasBackend/personas/models.py	Thu Mar 13 18:23:59 2008 -0500
+++ b/PersonasBackend/personas/models.py	Tue Mar 18 12:03:48 2008 -0500
@@ -298,6 +298,12 @@
         default="light",
         )
 
+    date_published = models.DateTimeField(
+        help_text=("The date that the Persona was last published."),
+        null=True,
+        editable=True,
+        )
+
     date_updated = models.DateTimeField(
         # This ensures that this field is updated with the current
         # timestamp whenever the record is changed.
@@ -459,12 +465,14 @@
             if not self.owner:
                 self.owner = self.updater
             assert self.owner == self.updater
-            if ( not self.status ) and self.updater:
-                if self.updater.has_perm( "personas.can_publish" ):
+            if not self.status:
+                if ( self.updater and
+                     self.updater.has_perm( "personas.can_publish" ) ):
                     # If the person creating the Persona can publish
                     # Personas, mark this new Persona as published, by
                     # default.
                     self.status = "published"
+                    self.date_published = datetime.datetime.now()
                 else:
                     # Otherwise, mark this new Persona as unpublished by
                     # default.
@@ -489,6 +497,12 @@
 
                     self.status = "unpublished"
 
+            original = Persona.objects.get(id=self.id)
+
+            if ( (original.status != self.status) and 
+                 (self.status == "published") ):
+                self.date_published = datetime.datetime.now()
+
             self.__make_new_revision()
 
         super(Persona, self).save()
--- a/PersonasBackend/personas/tests.py	Thu Mar 13 18:23:59 2008 -0500
+++ b/PersonasBackend/personas/tests.py	Tue Mar 18 12:03:48 2008 -0500
@@ -1,4 +1,5 @@
 import unittest
+import datetime
 
 from django.test.client import Client
 from PersonasBackend.personas import models
@@ -34,5 +35,21 @@
         response = client.get( "/en-US/personas_all.dat" )
         assert response.status_code == 200
 
+    def testPublishDateIsUpdatedProperly( self ):
+      p = models.Persona(
+          name='Yet Another Test Persona',
+          header_img_file='test.png',
+          footer_img_file='test2.png',
+          category=models.Category.objects.get(name='Other'))
+
+      p.save()
+      self.assertEquals( p.status, "unpublished" )
+      self.assertEquals( p.date_published, None )
+
+      p.status = "published"
+      now = datetime.datetime.now()
+      p.save()
+      assert p.date_published >= now
+
 if __name__ == "__main__":
     unittest.main()