<commit_before>from django import forms
from django.core.validators import RegexValidator

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit

import models


class ProjectCreateForm(forms.ModelForm):

    type = forms.ModelChoiceField(models.ProjectType.objects.all(), empty_label=None)

    class Meta:
        model = models.Project
        fields = [
            'name',
            'type',
            'description',
        ]

    helper = FormHelper()
    helper.layout = Layout(
        'name',
        'type',
        'description',
        ButtonHolder(
            Submit('submit', 'Create Project', css_class='button')
        )
    )


class ProjectUpdateForm(ProjectCreateForm):

    helper = FormHelper()
    helper.layout = Layout(
        'name',
        'type',
        'description',
        ButtonHolder(
            Submit('submit', 'Update Project', css_class='button')
        )
    )


class ConfigurationCreateForm(forms.ModelForm):

    class Meta:
        model = models.Configuration
        fields = [
            'key',
            'value',
            'prompt_me_for_input',
        ]

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

        self.fields['key'].validators.append(RegexValidator(r'^[a-zA-Z_]+[0-9a-zA-Z_]*$')) # valid python variable name

    helper = FormHelper()
    helper.layout = Layout(
        'key',
        'value',
        'prompt_me_for_input',
        ButtonHolder(
            Submit('submit', 'Create Configuration', css_class='button')
        )
    )


class ConfigurationUpdateForm(ConfigurationCreateForm):

    class Meta:
        model = models.Configuration
        fields = [
            'key',
            'value',
            'prompt_me_for_input',
        ]

    helper = FormHelper()
    helper.layout = Layout(
        'key',
        'value',
        'prompt_me_for_input',
        ButtonHolder(
            Submit('submit', 'Update Configuration', css_class='button')
        )
    )


class DeploymentForm(forms.ModelForm):
    class Meta:
        fields = ['comments']
        model = models.Deployment

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

        self.helper = FormHelper()

        self.helper.layout = Layout(
            'comments',
            ButtonHolder(
                Submit('submit', 'Go!', css_class='btn btn-success')
            )
        )


class StageCreateForm(forms.ModelForm):

    class Meta:
        model = models.Stage
        fields = [
            'name',
        ]

    helper = FormHelper()
    helper.layout = Layout(
        'name',
        ButtonHolder(
            Submit('submit', 'Create Stage', css_class='button')
        )
    )


class StageUpdateForm(StageCreateForm):

    class Meta:
        model = models.Stage
        fields = [
            'name',
        ]

    helper = FormHelper()
    helper.layout = Layout(
        'name',
        ButtonHolder(
            Submit('submit', 'Update Stage', css_class='button')
        )
    )<commit_msg>Cleaned up the form inheritance for the projects app.<commit_after>from django import forms
from django.core.validators import RegexValidator

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit

import models


class ProjectCreateForm(forms.ModelForm):

    type = forms.ModelChoiceField(models.ProjectType.objects.all(), empty_label=None)
    button_prefix = "Create"

    class Meta:
        model = models.Project
        fields = [
            'name',
            'type',
            'description',
        ]

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.layout = Layout(
            'name',
            'type',
            'description',
            ButtonHolder(
                Submit('submit', '%s Project' % self.button_prefix, css_class='button')
            )
        )

        super(ProjectCreateForm, self).__init__(*args, **kwargs)


class ProjectUpdateForm(ProjectCreateForm):

    button_prefix = "Update"
    

class ConfigurationUpdateForm(forms.ModelForm):

    button_prefix = "Update"

    class Meta:
        model = models.Configuration
        fields = [
            'key',
            'value',
            'prompt_me_for_input',
            'sensitive_value',
        ]

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.layout = Layout(
            'key',
            'value',
            'prompt_me_for_input',
            'sensitive_value',
            ButtonHolder(
                Submit('submit', '%s Configuration' % self.button_prefix, css_class='button')
            )
        )

        super(ConfigurationUpdateForm, self).__init__(*args, **kwargs)


class ConfigurationCreateForm(ConfigurationUpdateForm):

    button_prefix = "Create"

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

        self.fields['key'].validators.append(RegexValidator(r'^[a-zA-Z_]+[0-9a-zA-Z_]*$')) # valid python variable name


class DeploymentForm(forms.ModelForm):

    class Meta:
        fields = ['comments']
        model = models.Deployment

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

        self.helper = FormHelper()

        self.helper.layout = Layout(
            'comments',
            ButtonHolder(
                Submit('submit', 'Go!', css_class='btn btn-success')
            )
        )


class StageCreateForm(forms.ModelForm):
    button_prefix = "Create"

    class Meta:
        model = models.Stage
        fields = [
            'name',
        ]

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.layout = Layout(
            'name',
            ButtonHolder(
                Submit('submit', '%s Stage' % self.button_prefix, css_class='button')
            )
        )

        super(StageCreateForm, self).__init__(*args, **kwargs)


class StageUpdateForm(StageCreateForm):
    button_prefix = "Update"

    class Meta:
        model = models.Stage
        fields = [
            'name',
        ]
{'fraction_non_alphanumeric': 0.11612496055538024, 'fraction_numerical': 0.0006311139160618492, 'mean_word_length': 2.0652804642166345, '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': '4366165', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1707, 'n_words': 358}