qrurls.models: make URL.apply_publishing_schedule() count optional, to yield an infinite series of publishing times
--- 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) :