<commit_before># -*- coding: utf-8 -*-

import logging

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth import get_user_model
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache

from .forms import LandingPageForm
from .tasks import background_post_register_actions
from .funcs import get_all_beta_data

from ..base.utils import request_context_celery

LOGGER = logging.getLogger(__name__)
User = get_user_model()


def home(request):
    if request.POST:
        form = LandingPageForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']

            user = User.objects.create(username=email, email=email)

            # We need to forge a context for celery,
            # passing the request "as is" never works.
            context = request_context_celery(request, {'new_user_id': user.id})

            # we need to delay to be sure the profile creation is done.
            background_post_register_actions.delay(context)

            return HttpResponseRedirect(reverse('landing_thanks'))

        else:
            try:
                email = form.data['email']
            except:<commit_msg>Redirect authenticated users to the app automatically (but not staff nor superusers).<commit_after># -*- coding: utf-8 -*-

import logging

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth import get_user_model
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache

from .forms import LandingPageForm
from .tasks import background_post_register_actions
from .funcs import get_all_beta_data

from ..base.utils import request_context_celery

LOGGER = logging.getLogger(__name__)
User = get_user_model()


def home(request):

    if request.user.is_authenticated():
        if not (request.user.is_staff or request.user.is_superuser):
            return HttpResponseRedirect(reverse('home'))

    if request.POST:
        form = LandingPageForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']

            user = User.objects.create(username=email, email=email)

            # We need to forge a context for celery,
            # passing the request "as is" never works.
            context = request_context_celery(request, {'new_user_id': user.id})

            # we need to delay to be sure the profile creation is done.
            background_post_register_actions.delay(context)

            return HttpResponseRedirect(reverse('landing_thanks'))

        else:
            try:
                email = form.data['email']
            except:
{'fraction_non_alphanumeric': 0.07695010541110331, 'fraction_numerical': 0.0007027406886858749, 'mean_word_length': 3.044034090909091, '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': '7625698', 'n_tokens_mistral': 779, 'n_tokens_neox': 754, 'n_words': 223}