def test_archive_action_method(self): entry = Entry.objects.get(id=1) entry.state = 5 # force the state for now entry.save() sm = BlogEntryWorkflow(instance=entry) self.assertTrue(entry.allow_comments) sm.take_action('archive') self.assertEqual('Archived', sm.state) self.assertFalse(entry.allow_comments)
def test_public_returns_only_published(self): create_objects() self.assertEqual([], list(Entry.objects.published())) # We need some published items for item in Entry.objects.filter(id__in=[2, 3]): sm = BlogEntryWorkflow(instance=item) sm.take_action('publish') item.save() self.assertEqual([2, 3], list(Entry.objects.published().values_list('id', flat=True)))
def test_publish_action_method(self): entry = Entry.objects.get(id=1) sm = BlogEntryWorkflow(instance=entry) self.assertEqual('Private', sm.state) self.assertEqual(None, entry.publish_date) sm.take_action('publish') # Now the state should be updated ... self.assertEqual('Published', sm.state) # ... and the publish date should also be updated self.assertGreaterEqual(timezone.now(), entry.publish_date)
def test_public_returns_only_published(self): create_objects() self.assertEqual([], list(Entry.objects.published())) # We need some published items for item in Entry.objects.filter(id__in=[2, 3]): sm = BlogEntryWorkflow(instance=item) sm.take_action('publish') item.save() self.assertEqual( [2, 3], list(Entry.objects.published().values_list('id', flat=True)))
def test_retract_from_published_can_reset_date(self): entry = Entry.objects.get(id=1) sm = BlogEntryWorkflow(instance=entry) sm.take_action('publish') sm.take_action('retract') self.assertEqual('Private', sm.state) self.assertIsNotNone(entry.publish_date) sm.take_action('publish') # Now test with the reset feature sm.take_action('retract', reset_publish_date=True) self.assertEqual('Private', sm.state) self.assertIsNone(entry.publish_date)
def test_approve_from_review_sets_publish_date(self): entry = Entry.objects.get(id=1) sm = BlogEntryWorkflow(instance=entry) sm.take_action('review') self.assertEqual('Review', sm.state) self.assertIsNone(entry.publish_date) sm.take_action('approve') self.assertEqual('Published', sm.state) self.assertIsNotNone(entry.publish_date)
class BlogEntryBase(models.Model): """ Our abstract BlogEntryBase model. Using an abstract class allows the developer to customize his blog entry models how he/she feels best fits the needs of a project. """ title = models.CharField(_("Title"), max_length=255) slug = models.SlugField(_("Slug"), unique=True, help_text=_("A unique, url-friendly slug based on the title")) content = models.TextField(_("Content")) # Publication Fields state = models.IntegerField(_("State"), default=1, choices=BlogEntryWorkflow.get_choices()) author = models.ForeignKey(User, verbose_name=_("Author")) created_date = models.DateTimeField(_("Created date"), auto_now_add=True) modified_date = models.DateTimeField(_("Modified date"), auto_now=True, null=True, blank=True) publish_date = models.DateTimeField(_("Publish date"), null=True, blank=True) archived_date = models.DateTimeField(_("Archived date"), null=True, blank=True) allow_comments = models.BooleanField(_("Allow comments"), default=True) objects = BlogEntryManager() class Meta: abstract = True ordering = ('-publish_date', '-created_date') get_latest_by = 'publish_date' permissions = BlogEntryWorkflow.get_permissions('blog', 'Blog Entry') def __unicode__(self): return '%s' % self.title
def entry_state(self, obj): sm = BlogEntryWorkflow(instance=obj) return sm.state
class Meta: abstract = True ordering = ('-publish_date', '-created_date') get_latest_by = 'publish_date' permissions = BlogEntryWorkflow.get_permissions('blog', 'Blog Entry')