<commit_before>from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponse, Http404, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.translation import ugettext_lazy as _
from django.template.context import RequestContext

from cms import settings
from cms.models import Page, Title, CMSPlugin, MASK_CHILDREN, MASK_DESCENDANTS,\
    MASK_PAGE
from cms.plugin_pool import plugin_pool
from django.template.defaultfilters import escapejs, force_escape
from django.views.decorators.http import require_POST
from cms.utils.admin import render_admin_menu_item
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied

@require_POST
def change_status(request, page_id):
    """
    Switch the status of a page
    """
    page = get_object_or_404(Page, pk=page_id)
    if page.has_publish_permission(request):
        page.published = not page.published
        page.save(force_state=Page.MODERATOR_NEED_APPROVEMENT)    
        return render_admin_menu_item(request, page)
    raise Http404
change_status = staff_member_required(change_status)

@require_POST
def change_innavigation(request, page_id):
    """
    Switch the in_navigation of a page
    """
    page = get_object_or_404(Page, pk=page_id)
    if page.has_change_permission(request):
        if page.in_navigation:
            page.in_navigation = False
            val = 0
        else:
            page.in_navigation = True
            val = 1
        page.save(force_state=Page.MODERATOR_NEED_APPROVEMENT)
        return render_admin_menu_item(request, page)
    raise Http404
change_innavigation = staff_member_required(change_innavigation)

if 'reversion' in settings.INSTALLED_APPS:
    from reversion import revision    

def add_plugin(request):
    if 'history' in request.path or 'recover' in request.path:
        return HttpResponse(str("error"))
    if request.method == "POST":
        plugin_type = request.POST['plugin_type']
        page_id = request.POST.get('page_id', None)
        parent = None
        if page_id:
            page = get_object_or_404(Page, pk=page_id)
            placeholder = request.POST['placeholder'].lower()
            language = request.POST['language']<commit_msg>Changed permission check 404s to HttpResponseForbidden<commit_after>from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponse, Http404, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.translation import ugettext_lazy as _
from django.template.context import RequestContext

from cms import settings
from cms.models import Page, Title, CMSPlugin, MASK_CHILDREN, MASK_DESCENDANTS,\
    MASK_PAGE
from cms.plugin_pool import plugin_pool
from django.template.defaultfilters import escapejs, force_escape
from django.views.decorators.http import require_POST
from cms.utils.admin import render_admin_menu_item
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied

@require_POST
def change_status(request, page_id):
    """
    Switch the status of a page
    """
    page = get_object_or_404(Page, pk=page_id)
    if page.has_publish_permission(request):
        page.published = not page.published
        page.save(force_state=Page.MODERATOR_NEED_APPROVEMENT)    
        return render_admin_menu_item(request, page)
    else:
        return HttpResponseForbidden(_("You do not have permission to publish this page"))
change_status = staff_member_required(change_status)

@require_POST
def change_innavigation(request, page_id):
    """
    Switch the in_navigation of a page
    """
    page = get_object_or_404(Page, pk=page_id)
    if page.has_change_permission(request):
        if page.in_navigation:
            page.in_navigation = False
            val = 0
        else:
            page.in_navigation = True
            val = 1
        page.save(force_state=Page.MODERATOR_NEED_APPROVEMENT)
        return render_admin_menu_item(request, page)
    return HttpResponseForbidden(_("You do not have permission to change this page's in_navigation status"))
change_innavigation = staff_member_required(change_innavigation)

if 'reversion' in settings.INSTALLED_APPS:
    from reversion import revision    

def add_plugin(request):
    if 'history' in request.path or 'recover' in request.path:
        return HttpResponse(str("error"))
    if request.method == "POST":
        plugin_type = request.POST['plugin_type']
        page_id = request.POST.get('page_id', None)
        parent = None
        if page_id:
            page = get_object_or_404(Page, pk=page_id)
            placeholder = request.POST['placeholder'].lower()
            language = request.POST['language']
{'fraction_non_alphanumeric': 0.0738296555990926, 'fraction_numerical': 0.008867807795421737, 'mean_word_length': 3.8940464177598386, 'pattern_counts': {'":': 2, '<': 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': '1258335', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1409, 'n_words': 341}