コード例 #1
0
ファイル: tests.py プロジェクト: tburgnews/django-page-cms
    def test_flow(self):
        # Export
        page1 = self.new_page(content={'title': 'page1', 'slug': 'slug1'})
        tag1 = Tag.objects.create(name="t1")
        page1.tags.add(tag1)

        page2 = self.new_page(content={'title': 'page2', 'slug': 'slug2'})
        tag2 = Tag.objects.create(name="t2")
        page2.tags.add(tag2)

        data = pages_to_json(Page.objects.all())

        # Clear
        Page.objects.all().delete()
        Tag.objects.all().delete()

        # Import
        user = User.objects.create()
        json_to_pages(data, user)
        pages = Page.objects.all()
        self.assertEqual(pages.count(), 2)

        page1 = Page.objects.from_slug('slug1')
        self.assertEqual(page1.title(), 'page1')
        self.assertEqual([t.name for t in page1.tags.all()], ['t1'])

        page1 = Page.objects.from_slug('slug2')
        self.assertEqual(page1.title(), 'page2')
        self.assertEqual([t.name for t in page1.tags.all()], ['t2'])
コード例 #2
0
ファイル: tests.py プロジェクト: DjangoBD/django-page-cms
    def test_flow(self):
        # Export
        page1 = self.new_page(content={'title': 'page1', 'slug': 'slug1'})
        tag1 = Tag.objects.create(name="t1")
        page1.tags.add(tag1)

        page2 = self.new_page(content={'title': 'page2', 'slug': 'slug2'})
        tag2 = Tag.objects.create(name="t2")
        page2.tags.add(tag2)

        data = pages_to_json(Page.objects.all())

        # Clear
        Page.objects.all().delete()
        Tag.objects.all().delete()

        # Import
        user = User.objects.create()
        json_to_pages(data, user)
        pages = Page.objects.all()
        self.assertEqual(pages.count(), 2)

        page1 = Page.objects.from_slug('slug1')
        self.assertEqual(page1.title(), 'page1')
        self.assertEqual([t.name for t in page1.tags.all()], ['t1'])

        page1 = Page.objects.from_slug('slug2')
        self.assertEqual(page1.title(), 'page2')
        self.assertEqual([t.name for t in page1.tags.all()], ['t2'])
コード例 #3
0
    def test_json_parsing(self):
        """Test page date ordering feature."""
        self.new_page({'slug': 'p1'})
        self.new_page({'slug': 'p2'})
        jsondata = utils.pages_to_json(Page.objects.all())

        self.assertIn("p1", jsondata)
        self.assertIn("p2", jsondata)
        data = json.loads(jsondata)
        self.assertEqual(len(data['pages']), 2)
コード例 #4
0
    def test_json_parsing(self):
        """Test page date ordering feature."""
        self.new_page({'slug': 'p1'})
        self.new_page({'slug': 'p2'})
        jsondata = utils.pages_to_json(Page.objects.all())

        self.assertIn("p1", jsondata)
        self.assertIn("p2", jsondata)
        data = json.loads(jsondata)
        self.assertEqual(len(data['pages']), 2)
コード例 #5
0
    def handle(self, site=None, **options):
        """
        Export pages in JSON format.  Site may be specified by id or domain.
        Default: export pages from the current site specified by settings.SITE_ID.
        """
        if options["all_sites"]:
            monkeypatch_remove_pages_site_restrictions()
        qs = Page.objects.all()
        if site:
            for match in ("pk", "domain"):
                try:
                    s = Site.objects.get(**{match: site})
                    break
                except (Site.objects.DoesNotExist, ValueError):
                    continue
            else:
                raise CommandError(_("Site with id/domain = '%s' not found") % site)
            qs.filter(site=s)

        sys.stdout.write(pages_to_json(qs))
コード例 #6
0
    def handle(self, site=None, **options):
        """
        Export pages in JSON format.  Site may be specified by id or domain.
        Default: export pages from the current site specified by settings.SITE_ID.
        """
        if options['all_sites']:
            monkeypatch_remove_pages_site_restrictions()
        qs = Page.objects.all()
        if site:
            for match in ('pk', 'domain'):
                try:
                    s = Site.objects.get(**{match:site})
                    break
                except (Site.objects.DoesNotExist, ValueError):
                    continue
            else:
                raise CommandError(_("Site with id/domain = '%s' not found")
                    % site)
            qs.filter(site=s)

        sys.stdout.write(pages_to_json(qs))
コード例 #7
0
ファイル: actions.py プロジェクト: DjangoBD/django-page-cms
def export_pages_as_json(modeladmin, request, queryset):
    response = HttpResponse(content_type="application/json")
    response['Content-Disposition'] = 'attachment; filename=%s' % (
        JSON_PAGE_EXPORT_FILENAME,)
    response.write(pages_to_json(queryset))
    return response
コード例 #8
0
def export_pages_as_json(modeladmin, request, queryset):
    response = HttpResponse(mimetype="application/json")
    response['Content-Disposition'] = 'attachment; filename=%s' % (
        JSON_PAGE_EXPORT_FILENAME, )
    response.write(pages_to_json(queryset))
    return response