Commits

Jacco Flenter committed bdd2ae8

LiveManager moved from scm_core.models to the new scm_core.managers module

  • Participants
  • Parent commits 60e08b5

Comments (0)

Files changed (2)

File scm_core/managers.py

+from .models import PUBLISH_STATE_PUBLISHED
+
+class LiveManager(models.Manager):
+    """Live manager, checks for publish_date and state.
+
+    .. note::
+       it is not a failsafe way of retrieving data that is published. Keep
+       using common sense while developing!
+    """
+
+    def filter(self, *args, **kwargs):
+        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
+        kwargs['publish_date__lte'] = timezone.now
+
+        return super(LiveManager, self).filter(*args, **kwargs)
+
+    def all(self, *args, **kwargs):
+        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
+        kwargs['publish_date__lte'] = timezone.now
+        return self.filter(*args, **kwargs)
+
+    def count(self, *args, **kwargs):
+        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
+        kwargs['publish_date__lte'] = timezone.now
+        return self.filter(*args, **kwargs).count()
+
+    def get(self, *args, **kwargs):
+        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
+        kwargs['publish_date__lte'] = timezone.now
+
+        return super(LiveManager, self).get(*args, **kwargs)
+
+    def exclude(self, *args, **kwargs):
+        return self.filter().exclude(*args, **kwargs)
+
+    def get_random(self):
+
+        items = self.get_query_set().filter(category=category)
+        
+        count = items.count()
+
+	if count == 0:
+            raise self.model.DoesNotExist("%s matching query does not exist."
+                    % self.model._meta.object_name)
+
+        import random
+
+        return items[random.randint(0, count-1)]
+
+

File scm_core/models.py

 
 import reversion
 
+import .managers import LiveManager
+
 PUBLISH_STATE_DRAFT = 'draft'
 PUBLISH_STATE_PUBLISHED = 'published'
 PUBLISH_STATE_FOR_REVIEW = 'for_review'
 )
 
 
-class LiveManager(models.Manager):
-    """Live manager, checks for publish_date and state.
-
-    .. note::
-       it is not a failsafe way of retrieving data that is published. Keep
-       using common sense while developing!
-    """
-
-    def filter(self, *args, **kwargs):
-        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = timezone.now
-
-        return super(LiveManager, self).filter(*args, **kwargs)
-
-    def all(self, *args, **kwargs):
-        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = timezone.now
-        return self.filter(*args, **kwargs)
-
-    def count(self, *args, **kwargs):
-        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = timezone.now
-        return self.filter(*args, **kwargs).count()
-
-    def get(self, *args, **kwargs):
-        kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = timezone.now
-
-        return super(LiveManager, self).get(*args, **kwargs)
-
-    def exclude(self, *args, **kwargs):
-        return self.filter().exclude(*args, **kwargs)
-
-    def get_random(self):
-
-        items = self.get_query_set().filter(category=category)
-        
-        count = items.count()
-
-	if count == 0:
-            raise self.model.DoesNotExist("%s matching query does not exist."
-                    % self.model._meta.object_name)
-
-        import random
-
-        return items[random.randint(0, count-1)]
-
-
 class PublishItem(models.Model):
     """Basic model for publish/unpublish and date related stuff
     """