How to use the publish.models.Page.objects 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 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_parent(self):
            # this shouldn't publish the child page
            self.page1.publish()
            self.failUnless(self.page1.public)
            self.failIf(self.page1.public.parent)
            
            page2 = Page.objects.get(id=self.page2.id)
            self.failIf(page2.public)
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())
github johnsensible / django-publish / publish / tests.py View on Github external
def test_publish_selected_does_not_have_permission(self):
            self.admin_site.register(Page, PublishableAdmin)
            pages = Page.objects.exclude(id=self.fp3.id)
            
            class dummy_request(object):
                POST = {}

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

                    @classmethod
                    def get_and_delete_messages(cls):
                        return []
            
            response = publish_selected(self.page_admin, dummy_request, pages)
            self.failIf(response is None)
            # publish button should not be in response
github johnsensible / django-publish / publish / tests.py View on Github external
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)
            self.failUnlessEqual(None, page2.public.parent)
            self.failUnlessEqual(page1.public, child1.public.parent)
            self.failUnlessEqual(page1.public, child2.public.parent)
            self.failUnlessEqual(page2.public, child3.public.parent)
github johnsensible / django-publish / publish / tests.py View on Github external
def setUp(self):
            super(TestPublishableRecursiveForeignKey, self).setUp()
            self.page1 = Page.objects.create(slug='page1', title='page 1', content='some content')
            self.page2 = Page.objects.create(slug='page2', title='page 2', content='other content', parent=self.page1)
github johnsensible / django-publish / publish / tests.py View on Github external
def test_pre_publish(self):
            # page order shouldn't matter when publishing
            # should always get the right number of signals
            self._check_pre_publish(Page.objects.order_by('id'))
            self._check_pre_publish(Page.objects.order_by('-id'))
            self._check_pre_publish(Page.objects.order_by('?'))
github johnsensible / django-publish / publish / tests.py View on Github external
# 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)
            self.failUnlessEqual(None, page2.public.parent)
github johnsensible / django-publish / publish / tests.py View on Github external
def test_queryset(self):
            # make sure we only get back draft objects
            request = None
            
            self.failUnlessEqual(
                set([self.page1, self.page1.public, self.page2, self.page2.public]),
                set(Page.objects.all())
            )
            self.failUnlessEqual(
                set([self.page1, self.page2]),
                set(self.page_admin.queryset(request))
            )