--- a/qrurls/models.py Thu Aug 22 02:12:13 2013 +0300
+++ b/qrurls/models.py Thu Aug 22 02:44:51 2013 +0300
@@ -106,6 +106,35 @@
except IndexError :
return None
+ @property
+ def publishing_timetz (self) :
+ """publishing_time, with tzinfo on the correct timezone."""
+ return self.publishing_time.replace(tzinfo=timezone.get_current_timezone())
+
+ # XXX: hardcoded for now
+ publishing_offset = datetime.timedelta(days=1)
+
+ def publishing_schedule (self) :
+ """Calculate initial URLItem.published values for feed."""
+
+ # following the last item in the queue
+ item = self.last_item()
+
+ if item and item.published > self.now():
+ # starting from the following day
+ date = item.published.date() + self.publishing_offset
+ else :
+ # defaults to today
+ date = self.now().date()
+
+ 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) :
+ yield datetime.datetime.combine(date + offset * index, time)
+
def __unicode__ (self) :
return self.shorturl