104 try : |
104 try : |
105 return URLItem.objects.filter(shorturl=self).order_by('-published')[0] |
105 return URLItem.objects.filter(shorturl=self).order_by('-published')[0] |
106 except IndexError : |
106 except IndexError : |
107 return None |
107 return None |
108 |
108 |
|
109 @property |
|
110 def publishing_timetz (self) : |
|
111 """publishing_time, with tzinfo on the correct timezone.""" |
|
112 return self.publishing_time.replace(tzinfo=timezone.get_current_timezone()) |
|
113 |
|
114 # XXX: hardcoded for now |
|
115 publishing_offset = datetime.timedelta(days=1) |
|
116 |
|
117 def publishing_schedule (self) : |
|
118 """Calculate initial URLItem.published values for feed.""" |
|
119 |
|
120 # following the last item in the queue |
|
121 item = self.last_item() |
|
122 |
|
123 if item and item.published > self.now(): |
|
124 # starting from the following day |
|
125 date = item.published.date() + self.publishing_offset |
|
126 else : |
|
127 # defaults to today |
|
128 date = self.now().date() |
|
129 |
|
130 return date, self.publishing_timetz, self.publishing_offset |
|
131 |
|
132 @classmethod |
|
133 def apply_publishing_schedule (self, date, time, offset, count) : |
|
134 """Yield publishing times off given date/time to offset * count.""" |
|
135 for index in xrange(0, count) : |
|
136 yield datetime.datetime.combine(date + offset * index, time) |
|
137 |
109 def __unicode__ (self) : |
138 def __unicode__ (self) : |
110 return self.shorturl |
139 return self.shorturl |
111 |
140 |
112 class URLImage(models.Model): |
141 class URLImage(models.Model): |
113 image = models.ImageField(upload_to=IMAGES_MEDIA, storage=SecretFileSystemStorage()) |
142 image = models.ImageField(upload_to=IMAGES_MEDIA, storage=SecretFileSystemStorage()) |