# HG changeset patch # User Tero Marttila # Date 1415179583 -3600 # Node ID 06ef4789a353fafbe0725272c272249460529d71 # Parent 88d9c9974d6a05c45950f485906b2692a793d770 qrurls.models: make URL.apply_publishing_schedule() count optional, to yield an infinite series of publishing times diff -r 88d9c9974d6a -r 06ef4789a353 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) :