<commit_before>
import base64
import commonware
import datetime
import hashlib
import json
import os
import requests
import xml.etree.ElementTree as ET
import urllib

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse

from django.http import (
    Http404,
    HttpResponse,
    HttpResponseBadRequest,
    HttpResponseForbidden,
    HttpResponseRedirect,
)

from django.shortcuts import render
from django.templatetags.static import static
from django.utils.datastructures import MultiValueDictKeyError
from django_browserid import verify as browserid_verify
from django_browserid import get_audience
from pontoon.administration.utils.vcs import commit_to_vcs
from pontoon.administration.utils import files
from pontoon.base import utils

from pontoon.base.models import (
    Locale,
    Project,
    Subpage,
    Entity,
    Translation,
    UserProfile,
    get_entities,
    get_translation,
    unset_approved,
)

from session_csrf import anonymous_csrf_exempt
from suds.client import Client, WebFault


log = commonware.log.getLogger('pontoon')


def home(request, template='home.html'):
    """Home view."""
    log.debug("Home view.")

    translate_error = request.session.pop('translate_error', {})

    data = {
        'accept_language': request.META.get('HTTP_ACCEPT_LANGUAGE', '')
        .split(',')[0],
        'locale_code': translate_error.get('locale', None),
        'project': translate_error.get('project', None),
        'redirect': translate_error.get('redirect', None),
        'locales': Locale.objects.all(),
        'projects': Project.objects.filter(
            pk__in=Entity.objects.values('project'))
    }

    return render(request, template, data)


def handle_error(request):
    """
    A view to handle errors during loading a website for translation
    by Pontoon. This view is bound with a generic URL which can
    be called from Pontoon's javascript with appropriate GET parameters
    and the page will get redirected to the home page showing proper
    error messages, url and locale.
    """
    messages.error(request, request.GET.get('error', ''))
    request.session['translate_error'] = {
        'locale': request.GET.get('locale'),
        'project': request.GET.get('project')
    }
    return HttpResponseRedirect(reverse('pontoon.home'))


def translate(request, locale, slug, page=None, template='translate.html'):
    """Translate view."""
    log.debug("Translate view.")

    invalid_locale = invalid_project = False

    # Validate locale
    log.debug("Locale: " + locale)
    try:
        l = Locale.objects.get(code=locale)
    except Locale.DoesNotExist:
        invalid_locale = True

    # Validate project
    try:
        p = Project.objects.get(
            slug=slug, pk__in=Entity.objects.values('project'))
    except Project.DoesNotExist:
        invalid_project = True

    if invalid_locale:
        if invalid_project:
            raise Http404
        else:
            messages.error(request, "Oops, locale is not supported.")
            request.session['translate_error'] = {
                'project': p.slug,
            }
            return HttpResponseRedirect(reverse('pontoon.home'))

    if invalid_project:
        messages.error(request, "Oops, project could not be found.")
        request.session['translate_error'] = {
            'locale': locale,
        }<commit_msg>Remove obsolete log message<commit_after>
import base64
import commonware
import datetime
import hashlib
import json
import os
import requests
import xml.etree.ElementTree as ET
import urllib

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse

from django.http import (
    Http404,
    HttpResponse,
    HttpResponseBadRequest,
    HttpResponseForbidden,
    HttpResponseRedirect,
)

from django.shortcuts import render
from django.templatetags.static import static
from django.utils.datastructures import MultiValueDictKeyError
from django_browserid import verify as browserid_verify
from django_browserid import get_audience
from pontoon.administration.utils.vcs import commit_to_vcs
from pontoon.administration.utils import files
from pontoon.base import utils

from pontoon.base.models import (
    Locale,
    Project,
    Subpage,
    Entity,
    Translation,
    UserProfile,
    get_entities,
    get_translation,
    unset_approved,
)

from session_csrf import anonymous_csrf_exempt
from suds.client import Client, WebFault


log = commonware.log.getLogger('pontoon')


def home(request, template='home.html'):
    """Home view."""
    log.debug("Home view.")

    translate_error = request.session.pop('translate_error', {})

    data = {
        'accept_language': request.META.get('HTTP_ACCEPT_LANGUAGE', '')
        .split(',')[0],
        'locale_code': translate_error.get('locale', None),
        'project': translate_error.get('project', None),
        'redirect': translate_error.get('redirect', None),
        'locales': Locale.objects.all(),
        'projects': Project.objects.filter(
            pk__in=Entity.objects.values('project'))
    }

    return render(request, template, data)


def handle_error(request):
    """
    A view to handle errors during loading a website for translation
    by Pontoon. This view is bound with a generic URL which can
    be called from Pontoon's javascript with appropriate GET parameters
    and the page will get redirected to the home page showing proper
    error messages, url and locale.
    """
    messages.error(request, request.GET.get('error', ''))
    request.session['translate_error'] = {
        'locale': request.GET.get('locale'),
        'project': request.GET.get('project')
    }
    return HttpResponseRedirect(reverse('pontoon.home'))


def translate(request, locale, slug, page=None, template='translate.html'):
    """Translate view."""
    log.debug("Translate view.")

    invalid_locale = invalid_project = False

    # Validate locale
    try:
        l = Locale.objects.get(code=locale)
    except Locale.DoesNotExist:
        invalid_locale = True

    # Validate project
    try:
        p = Project.objects.get(
            slug=slug, pk__in=Entity.objects.values('project'))
    except Project.DoesNotExist:
        invalid_project = True

    if invalid_locale:
        if invalid_project:
            raise Http404
        else:
            messages.error(request, "Oops, locale is not supported.")
            request.session['translate_error'] = {
                'project': p.slug,
            }
            return HttpResponseRedirect(reverse('pontoon.home'))

    if invalid_project:
        messages.error(request, "Oops, project could not be found.")
        request.session['translate_error'] = {
            'locale': locale,
        }
{'fraction_non_alphanumeric': 0.09592494048452598, 'fraction_numerical': 0.002520655370396303, 'mean_word_length': 3.320629159104658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5861933', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1952, 'n_words': 535}