<commit_before>import json
import logging
import requests
from urllib import urlencode

from django.conf import settings
from django.contrib.auth.views import logout as auth_logout
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404, render
from django.utils import timezone
from django.utils.crypto import get_random_string
from django.utils.encoding import force_bytes, smart_bytes
from django.utils.safestring import mark_safe
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.generic import View

from django.utils.translation import ugettext as _
from haystack.generic_views import SearchView
from haystack.query import EmptySearchQuerySet
from josepy.jwk import JWK
from josepy.jws import JWS
from mozilla_django_oidc.views import OIDCAuthenticationRequestView, get_next_url
from mozilla_django_oidc.utils import absolutify, import_from_settings
from raven.contrib.django.models import client
from waffle import flag_is_active
from waffle.decorators import waffle_flag

from mozillians.api.models import APIv2App
from mozillians.common.decorators import allow_public, allow_unvouched
from mozillians.common.middleware import LOGIN_MESSAGE, GET_VOUCHED_MESSAGE
from mozillians.common.templatetags.helpers import (get_object_or_none, nonprefixed_url, redirect,
                                                    urlparams)
from mozillians.common.urlresolvers import reverse
from mozillians.groups.models import Group
import mozillians.phonebook.forms as forms
from mozillians.phonebook.models import Invite
from mozillians.phonebook.utils import redeem_invite
from mozillians.users.managers import EMPLOYEES, MOZILLIANS, PUBLIC, PRIVATE
from mozillians.users.models import AbuseReport, ExternalAccount, IdpProfile, UserProfile
from mozillians.users.tasks import (check_spam_account, send_userprofile_to_cis,
                                    update_email_in_basket)


ORIGINAL_CONNECTION_USER_ID = 'https://sso.mozilla.com/claim/original_connection_user_id'
BUGZILLA_URL = 'https://bugzilla.mozilla.org/enter_bug.cgi?product=Participation%20Infrastructure&component=Phonebook'  # noqa


@allow_unvouched
def login(request):
    if request.user.userprofile.is_complete:
        return redirect('phonebook:home')
    return redirect('phonebook:profile_edit')


@never_cache
@allow_public
def home(request):
    show_start = False
    if request.GET.get('source', ''):
        show_start = True

    link = '<a href="{}">file a bug</a>'.format(BUGZILLA_URL)
    msg = 'In case you are facing authentication issues please {}'.format(link)
    messages.warning(request, mark_safe(msg))
    return render(request, 'phonebook/home.html', {'show_start': show_start})


@allow_unvouched
@never_cache
def vouch(request, username):
    """Automatically vouch username.

    This must be behind a waffle flag and activated only for testing
    purposes.

    """
    if flag_is_active(request, 'testing-autovouch-views'):
        profile = get_object_or_404(UserProfile, user__username=username)
        now = timezone.now()
        description = 'Automatically vouched for testing purposes on {0}'.format(now)
        vouch = profile.vouch(None, description=description, autovouch=True)
        if vouch:<commit_msg>Remove warning message from home view.<commit_after>import json
import logging
import requests
from urllib import urlencode

from django.conf import settings
from django.contrib.auth.views import logout as auth_logout
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404, render
from django.utils import timezone
from django.utils.crypto import get_random_string
from django.utils.encoding import force_bytes, smart_bytes
from django.utils.safestring import mark_safe
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.generic import View

from django.utils.translation import ugettext as _
from haystack.generic_views import SearchView
from haystack.query import EmptySearchQuerySet
from josepy.jwk import JWK
from josepy.jws import JWS
from mozilla_django_oidc.views import OIDCAuthenticationRequestView, get_next_url
from mozilla_django_oidc.utils import absolutify, import_from_settings
from raven.contrib.django.models import client
from waffle import flag_is_active
from waffle.decorators import waffle_flag

from mozillians.api.models import APIv2App
from mozillians.common.decorators import allow_public, allow_unvouched
from mozillians.common.middleware import LOGIN_MESSAGE, GET_VOUCHED_MESSAGE
from mozillians.common.templatetags.helpers import (get_object_or_none, nonprefixed_url, redirect,
                                                    urlparams)
from mozillians.common.urlresolvers import reverse
from mozillians.groups.models import Group
import mozillians.phonebook.forms as forms
from mozillians.phonebook.models import Invite
from mozillians.phonebook.utils import redeem_invite
from mozillians.users.managers import EMPLOYEES, MOZILLIANS, PUBLIC, PRIVATE
from mozillians.users.models import AbuseReport, ExternalAccount, IdpProfile, UserProfile
from mozillians.users.tasks import (check_spam_account, send_userprofile_to_cis,
                                    update_email_in_basket)


ORIGINAL_CONNECTION_USER_ID = 'https://sso.mozilla.com/claim/original_connection_user_id'


@allow_unvouched
def login(request):
    if request.user.userprofile.is_complete:
        return redirect('phonebook:home')
    return redirect('phonebook:profile_edit')


@never_cache
@allow_public
def home(request):
    show_start = False
    if request.GET.get('source', ''):
        show_start = True

    return render(request, 'phonebook/home.html', {'show_start': show_start})


@allow_unvouched
@never_cache
def vouch(request, username):
    """Automatically vouch username.

    This must be behind a waffle flag and activated only for testing
    purposes.

    """
    if flag_is_active(request, 'testing-autovouch-views'):
        profile = get_object_or_404(UserProfile, user__username=username)
        now = timezone.now()
        description = 'Automatically vouched for testing purposes on {0}'.format(now)
        vouch = profile.vouch(None, description=description, autovouch=True)
        if vouch:
{'fraction_non_alphanumeric': 0.06562408652440807, 'fraction_numerical': 0.0035077462730195848, 'mean_word_length': 4.981643356643357, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5260432', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1968, 'n_words': 524}