qrurls.models: make URL.apply_publishing_schedule() count optional, to yield an infinite series of publishing times
authorTero Marttila <terom@paivola.fi>
Wed, 05 Nov 2014 10:26:23 +0100
changeset 88 06ef4789a353
parent 87 88d9c9974d6a
child 89 187e874f770c
qrurls.models: make URL.apply_publishing_schedule() count optional, to yield an infinite series of publishing times
qrurls/models.py
--- a/qrurls/models.py	Sat Sep 07 16:17:42 2013 +0300
+++ b/qrurls/models.py	Wed Nov 05 10:26:23 2014 +0100
@@ -1,5 +1,6 @@
 import datetime
 import hashlib
+import itertools
 import logging
 import os.path
 
@@ -169,9 +170,19 @@
         return date, self.publishing_timetz, self.publishing_offset
     
     @classmethod
-    def apply_publishing_schedule (self, date, time, offset, count) :
-        """Yield publishing times off given date/time to offset * count."""
-        for index in xrange(0, count) :
+    def apply_publishing_schedule (self, date, time, offset, count=None) :
+        """
+            Yield publishing times off given date/time to offset * count.
+
+            If count is not given, yields an infinite series of publish-datetimes.
+        """
+
+        if count:
+            iter = xrange(count)
+        else:
+            iter = itertools.count()
+
+        for index in iter:
             yield datetime.datetime.combine(date + offset * index, time)
 
     def __unicode__ (self) :