Skip to content

Commit

Permalink
Add start/end date
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Aug 31, 2017
1 parent 90392cf commit 073a578
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 8 additions & 1 deletion publisher/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db import models
from django.db.models import Q
from django.utils import timezone

from .signals import publisher_pre_delete
from .middleware import get_draft_status
Expand All @@ -16,7 +18,12 @@ def drafts(self):

def published(self):
from .models import PublisherModelBase
return self.filter(publisher_is_draft=PublisherModelBase.STATE_PUBLISHED)

return self.filter(
Q(publication_start_date__isnull=True) | Q(publication_start_date__lte=timezone.now()),
Q(publication_end_date__isnull=True) | Q(publication_end_date__gt=timezone.now()),
publisher_is_draft=PublisherModelBase.STATE_PUBLISHED,
)

def current(self):
if get_draft_status():
Expand Down
30 changes: 29 additions & 1 deletion publisher/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.utils import timezone
from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone

from .managers import PublisherManager
from .utils import assert_draft
Expand Down Expand Up @@ -33,6 +35,23 @@ class PublisherModelBase(models.Model):

publisher_published_at = models.DateTimeField(null=True, editable=False)

publication_start_date = models.DateTimeField(
_("publication start date"),
null=True, blank=True, db_index=True,
help_text=_(
"Published content will only be visible from this point in time."
" Leave blank if always visible."
)
)
publication_end_date = models.DateTimeField(
_("publication end date"),
null=True, blank=True, db_index=True,
help_text=_(
"When to expire the published version."
" Leave empty to never expire."
),
)

publisher_fields = (
'publisher_linked',
'publisher_is_draft',
Expand All @@ -58,7 +77,16 @@ def is_draft(self):

@property
def is_published(self):
return self.publisher_is_draft == self.STATE_PUBLISHED
if self.publisher_is_draft != self.STATE_PUBLISHED:
return False

if self.publication_end_date and self.publication_end_date <= timezone.now():
return False

if self.publication_start_date and self.publication_start_date >= timezone.now():
return False

return True

@property
def is_dirty(self):
Expand Down

0 comments on commit 073a578

Please sign in to comment.