Source code for shuup.campaigns.admin_module.forms._basket_conditions

# This file is part of Shuup.
#
# Copyright (c) 2012-2021, Shuup Commerce Inc. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from django import forms

from shuup.admin.forms.fields import WeekdayField
from shuup.admin.forms.widgets import TimeInput
from shuup.campaigns.models.basket_conditions import (
    BasketMaxTotalAmountCondition,
    BasketMaxTotalProductAmountCondition,
    BasketTotalAmountCondition,
    BasketTotalProductAmountCondition,
    BasketTotalUndiscountedProductAmountCondition,
    CategoryProductsBasketCondition,
    ChildrenProductCondition,
    ContactBasketCondition,
    ContactGroupBasketCondition,
    HourBasketCondition,
    ProductsInBasketCondition,
)
from shuup.core.models import Category

from ._base import BaseRuleModelForm


[docs]class BasketTotalProductAmountConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = BasketTotalProductAmountCondition
[docs]class BasketTotalAmountConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = BasketTotalAmountCondition
[docs]class BasketTotalUndiscountedProductAmountConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = BasketTotalUndiscountedProductAmountCondition
[docs]class ProductsInBasketConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = ProductsInBasketCondition
def __init__(self, *args, **kwargs): super(ProductsInBasketConditionForm, self).__init__(*args, **kwargs) self.fields["products"].widget = forms.SelectMultiple(attrs={"data-model": "shuup.product"})
[docs]class ContactGroupBasketConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = ContactGroupBasketCondition
[docs]class ContactBasketConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = ContactBasketCondition
[docs]class BasketMaxTotalProductAmountConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = BasketMaxTotalProductAmountCondition
[docs]class BasketMaxTotalAmountConditionForm(BaseRuleModelForm):
[docs] class Meta(BaseRuleModelForm.Meta): model = BasketMaxTotalAmountCondition
[docs]class ChildrenProductConditionForm(BaseRuleModelForm): def __init__(self, *args, **kwargs): super(ChildrenProductConditionForm, self).__init__(*args, **kwargs) self.fields["product"].widget = forms.Select( attrs={"data-model": "shuup.product", "data-search-mode": "parent_product"} )
[docs] class Meta(BaseRuleModelForm.Meta): model = ChildrenProductCondition
[docs]class CategoryProductsBasketConditionForm(BaseRuleModelForm): def __init__(self, **kwargs): super(CategoryProductsBasketConditionForm, self).__init__(**kwargs) self.fields["categories"].queryset = Category.objects.all_except_deleted() self.fields["excluded_categories"].queryset = Category.objects.all_except_deleted()
[docs] class Meta(BaseRuleModelForm.Meta): model = CategoryProductsBasketCondition
[docs]class HourBasketConditionForm(BaseRuleModelForm): days = WeekdayField()
[docs] class Meta(BaseRuleModelForm.Meta): model = HourBasketCondition widgets = { "hour_start": TimeInput(), "hour_end": TimeInput(), }