<commit_before>from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError, transaction
from django.utils.text import slugify

from recurrence.forms import RecurrenceField
from utils.db import get_max_order

from . models import Action, Behavior, Category, Goal, Trigger
from . utils import read_uploaded_csv


class ActionForm(forms.ModelForm):
    """A Form for creating/updating actions. This form orders related behaviors
    alphabetically."""
    behavior = forms.ModelChoiceField(queryset=Behavior.objects.all().order_by("title"))

    class Meta:
        model = Action
        fields = [
            'sequence_order', 'behavior', 'title', 'description',
            'more_info', 'external_resource', 'default_trigger',
            'notification_text', 'icon', 'source_link', 'source_notes', 'notes',

        ]
        labels = {"notes": "Scratchpad"}


class BehaviorForm(forms.ModelForm):
    """A Form for creating/updating behaviors. This form orders related
    goals alphabetically."""
    goals = forms.ModelMultipleChoiceField(
        queryset=Goal.objects.all().order_by("title")
    )

    class Meta:
        model = Behavior
        fields = [
            'title', 'description', 'more_info', 'informal_list',
            'external_resource', 'goals', 'icon', 'source_link', 'source_notes',
            'notes',
        ]
        labels = {"notes": "Scratchpad", 'informal_list': 'Action List'}


class CategoryForm(forms.ModelForm):
    """A Form for creating/updateing Categories. This form customizes the widget
    for the color field."""

    class Meta:
        model = Category
        fields = [
            'order', 'title', 'description', 'icon', 'image', 'color', 'notes',
        ]
        labels = {"order": "Default Order", "notes": "Scratchpad"}
        widgets = {
            "color": forms.TextInput(attrs={'class': 'color-picker', 'type': 'color'}),
        }


class GoalForm(forms.ModelForm):
    """A Form for creating/updating goals. This form orders related categories
    alphabetically."""
    categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all().order_by("title"))

    class Meta:
        model = Goal<commit_msg>re-include default_trigger in the behavior form; set the first as a default value<commit_after>from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError, transaction
from django.utils.text import slugify

from recurrence.forms import RecurrenceField
from utils.db import get_max_order

from . models import Action, Behavior, Category, Goal, Trigger
from . utils import read_uploaded_csv


class ActionForm(forms.ModelForm):
    """A Form for creating/updating actions. This form orders related behaviors
    alphabetically."""
    behavior = forms.ModelChoiceField(queryset=Behavior.objects.all().order_by("title"))

    class Meta:
        model = Action
        fields = [
            'sequence_order', 'behavior', 'title', 'description',
            'more_info', 'external_resource', 'default_trigger',
            'notification_text', 'icon', 'source_link', 'source_notes', 'notes',

        ]
        labels = {"notes": "Scratchpad"}


class BehaviorForm(forms.ModelForm):
    """A Form for creating/updating behaviors. This form orders related
    goals alphabetically."""
    goals = forms.ModelMultipleChoiceField(
        queryset=Goal.objects.all().order_by("title")
    )
    default_trigger = forms.ModelChoiceField(
        queryset=Trigger.objects.all()
    )

    def __init__(self, *args, **kwargs):
        if 'instance' in kwargs and kwargs['instance'].default_trigger is None:
            kwargs['instance'].default_trigger = Trigger.objects.get(pk=1)
        elif 'initial' in kwargs and kwargs.get('initial') is None:
            kwargs['intitial'].update({
                'default_trigger': Trigger.objects.get(pk=1)
            })
        super().__init__(*args, **kwargs)

    class Meta:
        model = Behavior
        fields = [
            'title', 'description', 'more_info', 'informal_list',
            'external_resource', 'goals', 'icon', 'default_trigger',
            'source_link', 'source_notes',
            'notes',
        ]
        labels = {"notes": "Scratchpad", 'informal_list': 'Action List'}


class CategoryForm(forms.ModelForm):
    """A Form for creating/updateing Categories. This form customizes the widget
    for the color field."""

    class Meta:
        model = Category
        fields = [
            'order', 'title', 'description', 'icon', 'image', 'color', 'notes',
        ]
        labels = {"order": "Default Order", "notes": "Scratchpad"}
        widgets = {
            "color": forms.TextInput(attrs={'class': 'color-picker', 'type': 'color'}),
        }


class GoalForm(forms.ModelForm):
    """A Form for creating/updating goals. This form orders related categories
    alphabetically."""
    categories = forms.ModelMultipleChoiceField(queryset=Category.objects.all().order_by("title"))

    class Meta:
        model = Goal
{'fraction_non_alphanumeric': 0.12301353737492643, 'fraction_numerical': 0.00039238767902687857, 'mean_word_length': 3.1179321486268177, 'pattern_counts': {'":': 10, '<': 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': '1981168', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1387, 'n_words': 378}