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'])
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)
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))
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))
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
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