announce object status methods refactored
This commit is contained in:
parent
1d6c349b5e
commit
36e2db0b1c
|
@ -17,7 +17,7 @@ class Announce(models.Model):
|
|||
help_text=_('maximum 256 characters'))
|
||||
text = RichTextField(_('Content'))
|
||||
publication_time = models.DateTimeField(_('publication time'), blank=True,
|
||||
null=True, default=timezone.now)
|
||||
null=True)
|
||||
expiration_time = models.DateTimeField(_('expiration time'), blank=True,
|
||||
null=True)
|
||||
ctime = models.DateTimeField(_('creation time'), auto_now_add=True)
|
||||
|
@ -28,18 +28,17 @@ class Announce(models.Model):
|
|||
return u'{title} ({id}) at {mtime}'.format(title=self.title,
|
||||
id=self.id, mtime=self.mtime)
|
||||
|
||||
def is_published(self):
|
||||
if self.publication_time:
|
||||
if self.expiration_time:
|
||||
return self.publication_time <= timezone.now() < self.expiration_time
|
||||
return self.publication_time <= timezone.now()
|
||||
|
||||
def is_expired(self):
|
||||
if self.expiration_time:
|
||||
return self.expiration_time > timezone.now()
|
||||
return self.expiration_time < timezone.now()
|
||||
return False
|
||||
|
||||
def is_not_published(self):
|
||||
return not self.publication_time
|
||||
def is_published(self):
|
||||
if self.is_expired():
|
||||
return False
|
||||
if self.publication_time:
|
||||
return self.publication_time <= timezone.now()
|
||||
return False
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('announce')
|
||||
|
|
Reference in New Issue