<commit_before>import haystack.forms
from crispy_forms.helper import FormHelper
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm

from core.layout import (Layout, Column, Row, Submit, Field, FormActions,
                         FORM_BUTTONS, Fieldset, UneditableField, HTML,
                         Reset, Div)
from core.models import User


class LoginForm(AuthenticationForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Div(
                Field('username', edit=True),
                Field('password', edit=True),
                FormActions(
                    Reset('reset', 'Reset', css_class='btn btn-light btn-outline-dark mr-1'),
                    Submit('submit', 'Submit', css_class='btn btn-info'),
                    css_class='float-right',
                ),
                css_class='mt-5',
            ),
        )


class SignUpForm(UserCreationForm):

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email')

    def __init__(self, *args, edit=True, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Row(Column(HTML('<h1>Sign up for a new user account</h1>'), css_class='col-12')),
            Row(
                Column(
                    Field('first_name', edit=edit),
                    Field('last_name', edit=edit),
                    Field('email', edit=edit),
                    HTML('[[TERMS OF USE]]'),
                    css_class='col-6',
                ),
                Column(
                    Field('username', edit=edit),
                    Field('password1', edit=edit),
                    Field('password2', edit=edit),

                    FormActions(
                        Reset('reset', 'Reset', css_class='btn btn-light btn-outline-dark mr-1'),
                        Submit('submit', 'Submit', css_class='btn btn-info'),
                        css_class='float-right',
                    ),
                    css_class='col-6',
                )
            )
        )


class UserProfileForm(UserCreationForm):

    class Meta:
        model = User
        exclude = ()

    def __init__(self, *args, editable=True, **kwargs):
        super().__init__(*args, **kwargs)
        # import pdb; pdb.set_trace()

        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            HTML('<h3>User: {{object.username}}</h3>'),
            Field('username', edit=edit),

            Fieldset('Personal Information',
                     Field('first_name', edit=edit),
                     Field('last_name', edit=edit),
                     Field('email', edit=edit),
                     Field('url', edit=edit),
                     ),

            Field('organization', edit=edit),
            Field('professional_title', edit=edit),

            Fieldset('Preferences',
                     Field('get_notification_emails', edit=edit),
                     ),

            FORM_BUTTONS if editable else HTML(''),
        )


class SearchForm(haystack.forms.SearchForm):
    def search(self):
        if not self.is_valid():
            return self.no_query_found()

        if not self.cleaned_data.get('q'):
            sqs = self.searchqueryset
            # return self.no_query_found()

        sqs = self.searchqueryset.auto_query(self.cleaned_data['q'])

        if self.load_all:
            sqs = sqs.load_all()

        return sqs
<commit_msg>fix: added confirmation dialog to new user form<commit_after>import haystack.forms
from crispy_forms.helper import FormHelper
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm

from core.layout import (Layout, Column, Row, Submit, Field, FormActions,
                         FORM_BUTTONS, Fieldset, UneditableField, HTML,
                         Reset, Div)
from core.models import User


class LoginForm(AuthenticationForm):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Div(
                Field('username', edit=True),
                Field('password', edit=True),
                FormActions(
                    Reset('reset', 'Reset', css_class='btn btn-light btn-outline-dark mr-1'),
                    Submit('submit', 'Submit', css_class='btn btn-info'),
                    css_class='float-right',
                ),
                css_class='mt-5',
            ),
        )


class SignUpForm(UserCreationForm):

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email')

    def __init__(self, *args, edit=True, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Row(Column(HTML('<h1>Sign up for a new user account</h1>'), css_class='col-12')),
            Row(
                Column(
                    Field('first_name', edit=edit),
                    Field('last_name', edit=edit),
                    Field('email', edit=edit),
                    HTML('[[TERMS OF USE]]'),
                    css_class='col-6',
                ),
                Column(
                    Field('username', edit=edit),
                    Field('<PASSWORD>', edit=edit),
                    Field('password2', edit=edit),

                    FORM_BUTTONS,
                    css_class='col-6',
                )
            )
        )


class UserProfileForm(UserCreationForm):

    class Meta:
        model = User
        exclude = ()

    def __init__(self, *args, editable=True, **kwargs):
        super().__init__(*args, **kwargs)
        # import pdb; pdb.set_trace()

        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            HTML('<h3>User: {{object.username}}</h3>'),
            Field('username', edit=edit),

            Fieldset('Personal Information',
                     Field('first_name', edit=edit),
                     Field('last_name', edit=edit),
                     Field('email', edit=edit),
                     Field('url', edit=edit),
                     ),

            Field('organization', edit=edit),
            Field('professional_title', edit=edit),

            Fieldset('Preferences',
                     Field('get_notification_emails', edit=edit),
                     ),

            FORM_BUTTONS if editable else HTML(''),
        )


class SearchForm(haystack.forms.SearchForm):
    def search(self):
        if not self.is_valid():
            return self.no_query_found()

        if not self.cleaned_data.get('q'):
            sqs = self.searchqueryset
            # return self.no_query_found()

        sqs = self.searchqueryset.auto_query(self.cleaned_data['q'])

        if self.load_all:
            sqs = sqs.load_all()

        return sqs

{'fraction_non_alphanumeric': 0.12471687429218573, 'fraction_numerical': 0.0033975084937712344, 'mean_word_length': 1.656015037593985, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3338363', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1825, 'n_words': 382}