<commit_before>import typing

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Field, HTML, Layout, Submit
from django import forms

from lib.forms import FormWithSubmit, ModelFormWithSubmit
from accounts.models import Account
from .project_models import Project, SessionParameters


class ProjectCreateForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['account', 'name', 'description', 'public']
        widgets = {
            'name': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        request = kwargs.pop('request')
        super().__init__(*args, **kwargs)

        accounts = Account.objects.filter(user_roles__user=request.user)
        self.fields['account'].queryset = accounts


class ProjectGeneralForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['name', 'description', 'public']
        widgets = {
            'name': forms.TextInput()
        }


class ProjectSharingForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['public', 'token', 'key']
        widgets = {
            'token': forms.TextInput(),
            'key': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Div(
                HTML(
                    '<p class="title is-5">Public access</p>'
                    '<p class="subtitle is-6">Make this project readable by everyone!</p>'
                ),
                'public',
                css_class="section"
            ),
            Div(
                HTML(
                    '<p class="title is-5">Collaborator access</p>'
                    '<p class="subtitle is-6">Add collaborators to this project</p>'
                ),
                css_class="section"
            ),
            Submit('submit', 'Update', css_class="button is-primary")
        )


class ProjectSettingsMetadataForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['name', 'description']
        widgets = {
            'name': forms.TextInput()
        }


class ProjectSettingsAccessForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['token', 'key']
        widgets = {
            'token': forms.TextInput(),
            'key': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Div(<commit_msg>Just use forms.ModelForm since custom layout is specified<commit_after>import typing

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Field, HTML, Layout, Submit
from django import forms

from lib.forms import FormWithSubmit, ModelFormWithSubmit
from accounts.models import Account
from .project_models import Project, SessionParameters


class ProjectCreateForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['account', 'name', 'description', 'public']
        widgets = {
            'name': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        request = kwargs.pop('request')
        super().__init__(*args, **kwargs)

        accounts = Account.objects.filter(user_roles__user=request.user)
        self.fields['account'].queryset = accounts


class ProjectGeneralForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['name', 'description', 'public']
        widgets = {
            'name': forms.TextInput()
        }


class ProjectSharingForm(forms.ModelForm):

    class Meta:
        model = Project
        fields = ['public', 'token', 'key']
        widgets = {
            'token': forms.TextInput(),
            'key': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Div(
                HTML(
                    '<p class="title is-5">Public access</p>'
                    '<p class="subtitle is-6">Make this project readable by everyone!</p>'
                ),
                'public',
                css_class="section"
            ),
            Div(
                HTML(
                    '<p class="title is-5">Collaborator access</p>'
                    '<p class="subtitle is-6">Add collaborators to this project</p>'
                ),
                css_class="section"
            ),
            Submit('submit', 'Update', css_class="button is-primary")
        )


class ProjectSettingsMetadataForm(ModelFormWithSubmit):

    class Meta:
        model = Project
        fields = ['name', 'description']
        widgets = {
            'name': forms.TextInput()
        }


class ProjectSettingsAccessForm(forms.ModelForm):

    class Meta:
        model = Project
        fields = ['token', 'key']
        widgets = {
            'token': forms.TextInput(),
            'key': forms.TextInput()
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Div(
{'fraction_non_alphanumeric': 0.1194225721784777, 'fraction_numerical': 0.0014998125234345708, 'mean_word_length': 1.978782802903406, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4380214', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1373, 'n_words': 340}