<commit_before>from django import forms

from .models import Category, Product, ProductImage


def categories_choices():
    CATEGORIES_CHOICES = []
    all_cats = Category.objects.all()
    main_cats = [cat for cat in all_cats if not cat.has_parent_category()]

    for cat in main_cats:
        CATEGORIES_CHOICES.append([int(cat.id), cat.name])
        if cat.subcategories() is None:
            continue
        for subcat in cat.subcategories():
            CATEGORIES_CHOICES.append([subcat.id, "-   {}".format(subcat.name)])
            if subcat.subcategories() is None:
                continue
            for subcat_ in subcat.subcategories():
                choice = [subcat_.id, " -- {}".format(subcat_.name)]
                CATEGORIES_CHOICES.append(choice)

    return CATEGORIES_CHOICES


class ProductForm(forms.ModelForm):
    category = forms.ChoiceField(label='Категорія',
                                 choices=categories_choices(),)

    class Meta:
        model = Product
        fields = (
            'name', 'model_name', 'category', 'main_image', 'description',
            'price', 'stock', 'available'
        )


class ImageForm(forms.ModelForm):
    image = forms.ImageField(label='Зображення')

    class Meta:
        Model = ProductImage
        fields = ('image', )<commit_msg>Update ProductForm<commit_after>from django import forms

from .models import Category, Product, ProductImage


def categories_choices():
    CATEGORIES_CHOICES = []
    all_cats = Category.objects.all()
    main_cats = [cat for cat in all_cats if not cat.has_parent_category()]

    for cat in main_cats:
        CATEGORIES_CHOICES.append([int(cat.id), cat.name])
        if cat.subcategories() is None:
            continue
        for subcat in cat.subcategories():
            CATEGORIES_CHOICES.append([subcat.id, "-   {}".format(subcat.name)])
            if subcat.subcategories() is None:
                continue
            for subcat_ in subcat.subcategories():
                choice = [subcat_.id, " -- {}".format(subcat_.name)]
                CATEGORIES_CHOICES.append(choice)

    return CATEGORIES_CHOICES


class ProductForm(forms.ModelForm):
    category = forms.ChoiceField(label='Категорія',
                                 choices=categories_choices(),)

    class Meta:
        model = Product
        fields = (
            'name', 'model_name', 'category', 'main_image', 'description',
            'price', 'stock', 'available'
        )

    def clean_category(self):
        category = Category.objects.filter(
            pk=int(self.cleaned_data['category'])
        ).first()
        return category


class ImageForm(forms.ModelForm):
    image = forms.ImageField(label='Зображення')

    class Meta:
        Model = ProductImage
        fields = ('image', )
{'fraction_non_alphanumeric': 0.11146723646723647, 'fraction_numerical': 0.0, 'mean_word_length': 2.344047619047619, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '611255', 'n_tokens_mistral': 836, 'n_tokens_neox': 809, 'n_words': 177}