Author: batiste.bieler
Date: Sun Mar  8 14:02:46 2009
New Revision: 397

Modified:
    trunk/pages/managers.py
    trunk/pages/models.py

Log:
Refactor the code to retablish date publication on the frontend

Modified: trunk/pages/managers.py
==============================================================================
--- trunk/pages/managers.py     (original)
+++ trunk/pages/managers.py     Sun Mar  8 14:02:46 2009
@@ -5,7 +5,6 @@
  from django.contrib.sites.managers import CurrentSiteManager
  from django.contrib.sites.models import Site
  from django.db.models import Q
-
  from pages import settings

  class PageManager(models.Manager):
@@ -45,21 +44,25 @@
      def hidden(self):
          return self.on_site().filter(status=self.model.HIDDEN)

-    def published(self):
-        pub = itertools.chain(
-            self.on_site().filter(status=self.model.PUBLISHED),
-            self.hidden()
-        )
+    def filter_published(self, queryset):
+        """Resuable filter for published page"""
+        if settings.PAGE_USE_SITE_ID:
+            queryset = queryset.filter(sites=settings.SITE_ID)
+
+        queryset = queryset.filter(status=self.model.PUBLISHED)

          if settings.PAGE_SHOW_START_DATE:
-            pub = pub.filter(publication_date__lte=datetime.now())
+            queryset =  
queryset.filter(publication_date__lte=datetime.now())

          if settings.PAGE_SHOW_END_DATE:
-            pub = pub.filter(
+            queryset = queryset.filter(
                  Q(publication_end_date__gt=datetime.now()) |
                  Q(publication_end_date__isnull=True)
              )
-        return pub
+        return queryset
+
+    def published(self):
+        return self.filter_published(self)

      def drafts(self):
          pub = self.on_site().filter(status=self.model.DRAFT)

Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py       (original)
+++ trunk/pages/models.py       Sun Mar  8 14:02:46 2009
@@ -100,10 +100,7 @@

      def get_children_for_frontend(self):
          """Return children of the page for the frontend """
-        children = self.get_children().filter(status=self.PUBLISHED)
-        if settings.PAGE_USE_SITE_ID:
-            children = children.filter(sites=settings.SITE_ID)
-        return children
+        return Page.objects.filter_published(self.get_children())

      def invalidate(self):
          """Invalidate a page and it's descendants"""

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to