<commit_before>from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
from django.conf import settings as global_settings
from django.db import transaction
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext

from pages import settings
from pages.http import get_language_from_request
from pages.utils import get_placeholders
from pages.models import Page

JSON_PAGE_EXPORT_FILENAME = 'cms_pages.json'


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
export_pages_as_json.short_description = _("Export pages as JSON")

@transaction.commit_on_success
def import_pages_from_json(request,
        template_name='admin/pages/page/import_pages.html'):
    try:
        j = request.FILES['json']
    except KeyError:
        return redirect('admin:page-index')

    errors, pages_created = json_to_pages(j, request.user,
        get_language_from_request(request))

    return render_to_response(template_name, {
        'errors': errors,
        'pages_created': pages_created,
        'app_label': 'pages',
        'opts': Page._meta,
    }, RequestContext(request))

<commit_msg>fix admin import/export after refactor<commit_after>from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse
from django.conf import settings as global_settings
from django.db import transaction
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext

from pages import settings
from pages.http import get_language_from_request
from pages.utils import get_placeholders, pages_to_json, json_to_pages
from pages.models import Page

JSON_PAGE_EXPORT_FILENAME = 'cms_pages.json'


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
export_pages_as_json.short_description = _("Export pages as JSON")

@transaction.commit_on_success
def import_pages_from_json(request,
        template_name='admin/pages/page/import_pages.html'):
    try:
        j = request.FILES['json']
    except KeyError:
        return redirect('admin:page-index')

    errors, pages_created = json_to_pages(j, request.user,
        get_language_from_request(request))

    return render_to_response(template_name, {
        'errors': errors,
        'pages_created': pages_created,
        'app_label': 'pages',
        'opts': Page._meta,
    }, RequestContext(request))


{'fraction_non_alphanumeric': 0.08453174324798317, 'fraction_numerical': 0.0, 'mean_word_length': 4.796747967479675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3705597', 'n_tokens_mistral': 826, 'n_tokens_neox': 802, 'n_words': 188}