How to use the publish.models.Page.objects.draft function in publish

To help you get started, we’ve selected a few publish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_after_dry_run_handles_caching(self):
            # if we do a dry tun publish in the same queryset
            # before publishing for real, we have to make
            # sure we don't run into issues with the instance
            # caching parent's as None
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())
            
            draft = Page.objects.draft()

            all_published = NestedSet()
            for p in draft:
                p.publish(dry_run=True, all_published=all_published)
            
            # nothing published yet
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            # now publish (using same queryset, as this will have cached the instances)
            draft.publish()

            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(5, Page.objects.published().count())

            # now actually check the public parent's are setup right
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_selected_does_not_have_related_permission(self):
            # check we can't publish when we don't have permission
            # for a related model (in this case authors)
            self.admin_site.register(Author, PublishableAdmin)

            author = Author.objects.create(name='John')
            self.fp1.authors.add(author)

            pages = Page.objects.draft()

            class dummy_request(object):
                POST = { 'post': True }

                class user(object):
                    pk = 1

                    @classmethod
                    def is_authenticated(cls):
                        return True

                    @classmethod
                    def has_perm(cls, perm):
                        return perm != 'publish.publish_author'
            
            try:
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_after_dry_run_handles_caching(self):
            # if we do a dry tun publish in the same queryset
            # before publishing for real, we have to make
            # sure we don't run into issues with the instance
            # caching parent's as None
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())
            
            draft = Page.objects.draft()

            all_published = NestedSet()
            for p in draft:
                p.publish(dry_run=True, all_published=all_published)
            
            # nothing published yet
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            # now publish (using same queryset, as this will have cached the instances)
            draft.publish()

            self.failUnlessEqual(5, Page.objects.draft().count())
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_after_dry_run_handles_caching(self):
            # if we do a dry tun publish in the same queryset
            # before publishing for real, we have to make
            # sure we don't run into issues with the instance
            # caching parent's as None
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())
            
            draft = Page.objects.draft()

            all_published = NestedSet()
            for p in draft:
                p.publish(dry_run=True, all_published=all_published)
            
            # nothing published yet
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())

            # now publish (using same queryset, as this will have cached the instances)
            draft.publish()

            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(5, Page.objects.published().count())

            # now actually check the public parent's are setup right
            page1 = Page.objects.get(id=self.page1.id)
            page2 = Page.objects.get(id=self.page2.id)
            child1 = Page.objects.get(id=self.child1.id)
            child2 = Page.objects.get(id=self.child2.id)
            child3 = Page.objects.get(id=self.child3.id)

            self.failUnlessEqual(None, page1.public.parent)
github johnsensible / django-publish / publish / tests.py View on Github external
return True

                    class message_set(object):
                        @classmethod
                        def create(cls, message=None):
                            self._message = message

                class _messages(object):
                    @classmethod
                    def add(cls, *message):
                        self._message = message

            response = unpublish_selected(self.page_admin, dummy_request, pages)

            self.failUnlessEqual(0, Page.objects.published().count())
            self.failUnlessEqual(3, Page.objects.draft().count())
            self.failUnless( getattr(self, '_message', None) is not None )
            self.failUnless( response is None )
github johnsensible / django-publish / publish / tests.py View on Github external
def test_unpublish_selected_confirm(self):
            pages = Page.objects.draft()

            class dummy_request(object):
                META = {}
                POST = {}

                class user(object):
                    @classmethod
                    def has_perm(cls, *arg):
                        return True

                    @classmethod
                    def get_and_delete_messages(cls):
                        return []

            response = unpublish_selected(self.page_admin, dummy_request, pages)
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_selected_confirmed(self):
            pages = Page.objects.draft()

            class dummy_request(object):
                POST = {'post': True}

                class user(object):
                    @classmethod
                    def is_authenticated(cls):
                        return True

                    @classmethod
                    def has_perm(cls, *arg):
                        return True

                    class message_set(object):
                        @classmethod
                        def create(cls, message=None):
github johnsensible / django-publish / publish / tests.py View on Github external
def setUp(self):
            self.page1  = Page.objects.create(slug='page1', title='page 1')
            self.page2  = Page.objects.create(slug='page2', title='page 2')
            self.child1 = Page.objects.create(parent=self.page1, slug='child1', title='Child 1')
            self.child2 = Page.objects.create(parent=self.page1, slug='child2', title='Child 2')
            self.child3 = Page.objects.create(parent=self.page2, slug='child3', title='Child 3')

            self.failUnlessEqual(5, Page.objects.draft().count())
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_with_overlapping_models_published(self):
            # make sure when we publish we don't accidentally create
            # multiple published versions
            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(0, Page.objects.published().count())
            
            all_published = NestedSet()
            Page.objects.draft().publish(all_published)
            
            self.failUnlessEqual(5, len(all_published))

            self.failUnlessEqual(5, Page.objects.draft().count())
            self.failUnlessEqual(5, Page.objects.published().count())