Esempio n. 1
0
class CategoryForm(SlugifyForm):
    parent = AutocompleteSelectField(model=Category,
                                     help_text=None,
                                     label='Родительская',
                                     required=False)
    image = ImageField(widget=ImageWidget(), label='Logo', required=False)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['image'].widget.model = self.instance
        self.fields['description'].required = False
        self.fields['bgcolor'].required = False

    class Meta:
        model = Category
        fields = '__all__'
        fieldsets = [
            ('main', {
                'fields': ['slug', 'bgcolor', 'active', 'image'],
                'legend': 'Общее'
            }),
            ('related', {
                'fields': ['parent'],
                'legend': 'Связи'
            }),
        ]
Esempio n. 2
0
class GoogleFeedForm(BetterModelForm):
    product = AutocompleteSelectField(model=Product,
                                      help_text=None,
                                      label='Товар')

    class Meta:
        model = GoogleFeed
        fields = '__all__'
Esempio n. 3
0
class TigresCategoryForm(BetterModelForm):
    category = AutocompleteSelectField(model=Category,
                                       help_text=None,
                                       label='Категория')

    class Meta:
        model = TigresCategory
        fields = '__all__'
Esempio n. 4
0
class SpecialForm(BetterModelForm):
    class Meta:
        model = Special
        fields = ('product', 'price')
        fieldsets = [
            ('main', {
                'fields': ['product', 'price'],
                'legend': 'Общее'
            }),
        ]

    product = AutocompleteSelectField(model=Product,
                                      help_text=None,
                                      label='Товар')
Esempio n. 5
0
class PopularForm(BetterModelForm):
    class Meta:
        fields = ('product', )
        model = Popular
        fieldsets = [
            ('main', {
                'fields': [
                    'product',
                ],
                'legend': 'Общее'
            }),
        ]

    product = AutocompleteSelectField(model=Product,
                                      help_text=None,
                                      label='Товар')
Esempio n. 6
0
class FeaturedForm(BetterModelForm):
    class Meta:
        model = Featured
        fields = ('products', 'category')
        fieldsets = [
            ('main', {
                'fields': ['products', 'category'],
                'legend': 'Общее'
            }),
        ]

    products = AutocompleteSelectMultipleField(model=Product,
                                               help_text=None,
                                               label='Товары')
    category = AutocompleteSelectField(model=Category,
                                       help_text=None,
                                       label='Категория')
Esempio n. 7
0
class ProductForm(SlugifyForm):
    height = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Высота'}),
        label='Высота',
        required=False)
    width = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Ширина'}),
        label='Ширина',
        required=False)
    length = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Длина'}),
        label='Длина',
        required=False)
    counter = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Ед. изм.'}),
        label='Ед. изм.',
        required=False)
    category = AutocompleteSelectMultipleField(model=Category,
                                               help_text=None,
                                               label='Категории',
                                               required=False)
    tags = AutocompleteSelectMultipleField(model=Tag,
                                           help_text=None,
                                           label='Теги',
                                           required=False)
    is_available = forms.BooleanField(label='В наличии',
                                      widget=SwitcherWidget(),
                                      required=False)
    featured = AutocompleteSelectMultipleField(model=Product,
                                               help_text=None,
                                               label='Похожие товары',
                                               required=False)
    model = forms.CharField(
        widget=forms.TextInput(attrs={'placeholder': 'Артикул'}),
        label='Артикул')
    retail_price = forms.FloatField(label='Розничная', required=False)
    big_opt_price = forms.FloatField(label='Биг-оптовая', required=False)
    special = forms.IntegerField(label='Спец.цена', required=False)
    brand = AutocompleteSelectField(model=Brand,
                                    help_text=None,
                                    label='Производитель',
                                    required=False)
    gallery = forms.CharField(widget=GalleryWidget(), label='', required=False)
    add_model = forms.CharField(widget=FgkWidget(),
                                label='Доп.артикулы',
                                required=False)
    storage_choices = STORAGE_CHOICES
    storage = forms.ChoiceField(choices=storage_choices,
                                label='Склад',
                                widget=CustomSelectWidget(),
                                required=True)
    attributes = forms.ModelMultipleChoiceField(queryset=Value.objects.all(),
                                                widget=AttributesWidget(),
                                                label="",
                                                required=False)
    price_fixed = forms.BooleanField(label="Фикс. цена",
                                     widget=SwitcherWidget(),
                                     required=False,
                                     initial=False)
    is_top = forms.BooleanField(label="Топ?",
                                widget=SwitcherWidget(),
                                required=False,
                                initial=False)

    currency_choices = ((0, 'UAH'), (1, 'EUR'), (2, 'USD'))
    currency = forms.ChoiceField(choices=currency_choices,
                                 label='Валюта',
                                 widget=CustomSelectWidget(),
                                 required=True)

    class Meta:
        model = Product
        fields = '__all__'
        widgets = {
            'big_opt_price':
            forms.TextInput(attrs={'placeholder': 'Биг-опт.'}),
            'purchase_price': forms.TextInput(attrs={'placeholder': 'Закуп.'}),
        }
        fieldsets = [
            ('main', {
                'fields':
                ['slug', 'model', 'is_available', 'storage', 'is_top'],
                'legend': 'Общее'
            }),
            ('prices', {
                'fields': [
                    'retail_price', 'big_opt_price', 'special', 'price_fixed',
                    'purchase_price', 'currency', 'counter'
                ],
                'legend':
                'Цены',
                'classes': ['prices']
            }),
            ('related', {
                'fields':
                ['category', 'brand', 'featured', 'add_model', 'tags'],
                'legend': 'Связи'
            }),
            ('attributes', {
                'fields': ['attributes'],
                'legend': 'Атрибуты',
                'classes': ['attributes'],
                'description': 'dynamic'
            }),
            ('parameters', {
                'fields': ['height', 'width', 'length'],
                'legend': 'Параметры',
                'classes': ['parameters']
            }),
            ('gallery', {
                'fields': ['gallery'],
                'legend': 'Картины',
                'classes': ['gallery']
            }),
        ]

    def __str__(self):
        return self.fields['name'].value

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        obj = getattr(self, 'instance', None)
        if obj and hasattr(obj, 'special'):
            self.fields['special'].initial = obj.special.price
        self.fields['gallery'].widget.model = self.instance
        self.fields['add_model'].widget.instance = self.instance
        self.fields['add_model'].widget.related_name = 'add_model'
        self.fields['add_model'].widget.model = 'add_model'
        self.fields['add_model'].widget.field = 'model'
        self.fields['storage'].widget.model = self.instance
        self.fields['attributes'].widget.instance = self.instance
        self.fields['rating'].required = False
        self.fields['qty'].required = False
        self.fields['description'].required = False
        self.fields['purchase_price'].required = False

    def save(self, *args, **kwargs):
        product = super().save(*args, **kwargs)
        try:
            if self.cleaned_data['special']:
                special = Special(product=product,
                                  price=self.cleaned_data['special'])
                special.save()
            elif hasattr(product,
                         'special') and not self.cleaned_data['special']:
                special = Special.objects.get(product=product)
                special.delete()
        except:
            pass

        return product