|
|
|
@ -41,6 +41,14 @@ class WorkflowQuerySet(models.QuerySet):
|
|
|
|
|
"archiving_datetime__lte": timezone.now(), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def future_filter(cls): |
|
|
|
|
return { |
|
|
|
|
"is_published": True, |
|
|
|
|
"publication_datetime__gt": timezone.now(), |
|
|
|
|
"archiving_datetime__gt": timezone.now(), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def unpublished(self): |
|
|
|
|
return self.exclude(**self.published_filter()) |
|
|
|
|
|
|
|
|
@ -56,6 +64,9 @@ class WorkflowQuerySet(models.QuerySet):
|
|
|
|
|
def archived(self): |
|
|
|
|
return self.filter(**self.archived_filter()) |
|
|
|
|
|
|
|
|
|
def future(self): |
|
|
|
|
return self.filter(**self.future_filter()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ManyToManyWorkflowQuerySet(WorkflowQuerySet): |
|
|
|
|
def _build_related_filters(self, filter_template): |
|
|
|
@ -83,6 +94,9 @@ class ManyToManyWorkflowQuerySet(WorkflowQuerySet):
|
|
|
|
|
def archived(self): |
|
|
|
|
return self.filter(**self._build_related_filters(self.archived_filter())) |
|
|
|
|
|
|
|
|
|
def future(self): |
|
|
|
|
return self.filter(**self._build_related_filters(self.future_filter())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkflowManager(models.Manager.from_queryset(WorkflowQuerySet)): |
|
|
|
|
pass |
|
|
|
@ -115,9 +129,9 @@ class WorkflowMixin(models.Model):
|
|
|
|
|
@property |
|
|
|
|
def worflow_status(self): |
|
|
|
|
now = timezone.now() |
|
|
|
|
if not self.is_published or self.publication_datetime < now: |
|
|
|
|
if not self.is_published or self.publication_datetime > now: |
|
|
|
|
return 'unpublished' |
|
|
|
|
elif self.publication_datetime >= now and self.archiving_datetime < now: |
|
|
|
|
elif self.publication_datetime <= now and self.archiving_datetime > now: |
|
|
|
|
return 'active' |
|
|
|
|
else: |
|
|
|
|
return 'archived' |
|
|
|
|