示例#1
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))
示例#2
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