<commit_before>from django.conf import settings
from django.http import HttpResponse
from django.contrib import messages
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.http import require_POST
from functools import partial

from catalog.utils import replace_apostrophes
from spotter.models import SearchTask
from spotter.utils import first_run, send_newtask_notify


login_required = partial(login_required, redirect_field_name='login_to', login_url='/')


def silent_logout(request):
    logout(request)
    return redirect(request.GET.get('next', settings.LOGOUT_REDIRECT or '/'))


def login_menu(request, template_name='login_menu.jinja'):
    if not request.user.is_authenticated:
        return HttpResponse('')
    path = request.GET.get('next', '')
    return render(request, template_name, {'path': path})


@login_required
def search_list(request, template_name='search_list.jinja'):
    task_list = SearchTask.objects.filter(user=request.user,
        is_deleted=False).defer('found_ids').order_by('-created')
    return render(request, template_name, {'task_list': task_list})


@login_required
def save_search(request):
    query = replace_apostrophes(request.GET.get("q", "")).strip()
    deepsearch = bool(request.GET.get("deepsearch", ""))

    if len(query) < 2:
        messages.warning(request, 'Не вдалось створити завдання з пустим запитом.')
        return redirect('search_list')

    # don't add twice
    if SearchTask.objects.filter(user=request.user,
            query=query, deepsearch=deepsearch, is_deleted=False).exists():
        messages.warning(request, 'Таке завдання вже існує.')<commit_msg>check for email address when create new SearchTask<commit_after>from django.conf import settings
from django.http import HttpResponse
from django.contrib import messages
from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.http import require_POST
from functools import partial

from catalog.utils import replace_apostrophes
from spotter.models import SearchTask
from spotter.utils import first_run, send_newtask_notify


login_required = partial(login_required, redirect_field_name='login_to', login_url='/')


def silent_logout(request):
    logout(request)
    return redirect(request.GET.get('next', settings.LOGOUT_REDIRECT or '/'))


def login_menu(request, template_name='login_menu.jinja'):
    if not request.user.is_authenticated:
        return HttpResponse('')
    path = request.GET.get('next', '')
    return render(request, template_name, {'path': path})


@login_required
def search_list(request, template_name='search_list.jinja'):
    task_list = SearchTask.objects.filter(user=request.user,
        is_deleted=False).defer('found_ids').order_by('-created')
    return render(request, template_name, {'task_list': task_list})


@login_required
def save_search(request):
    query = replace_apostrophes(request.GET.get("q", "")).strip()
    deepsearch = bool(request.GET.get("deepsearch", ""))

    if len(query) < 2:
        messages.warning(request, 'Не вдалось створити завдання з пустим запитом.')
        return redirect('search_list')

    if not request.user.email:
        messages.warning(request, 'Не вдалось створити завдання без адреси електронної пошти.')
        return redirect('search_list')

    # don't add twice
    if SearchTask.objects.filter(user=request.user,
            query=query, deepsearch=deepsearch, is_deleted=False).exists():
        messages.warning(request, 'Таке завдання вже існує.')
{'fraction_non_alphanumeric': 0.10731446876668446, 'fraction_numerical': 0.002135611318739989, 'mean_word_length': 5.053311793214863, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3811268', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1141, 'n_words': 258}