Пример #1
0
 class Meta:
     model = ShopProduct
     fields = (
         "default_price_value",
         "minimum_price_value",
         "suppliers",
         "visibility",
         "purchasable",
         "visibility_limit",
         "visibility_groups",
         "purchase_multiple",
         "minimum_purchase_quantity",
         "backorder_maximum",
         "display_unit",
         "limit_shipping_methods",
         "limit_payment_methods",
         "shipping_methods",
         "payment_methods",
         "primary_category",
         "categories",
         # i18n
         "status_text",
         # TODO: "shop_primary_image",
     )
     help_texts = {
         "backorder_maximum": _("Number of units that can be purchased after the product is out of stock. "
                                "Set to blank for product to be purchasable without limits")
     }
     widgets = {
         "display_unit": QuickAddDisplayUnitSelect(editable_model="shuup.DisplayUnit"),
         "primary_category": QuickAddCategorySelect(editable_model="shuup.Category"),
         "categories": QuickAddCategoryMultiSelect(),
         "payment_methods": QuickAddPaymentMethodsSelect(),
         "shipping_methods": QuickAddShippingMethodsSelect(),
     }
Пример #2
0
 class Meta:
     model = Slide
     exclude = ("carousel",)
     widgets = {
         "active_dot_color": HexColorWidget(),
         "inactive_dot_color": HexColorWidget(),
         "category_link": QuickAddCategorySelect(editable_model="shuup.Category"),
     }
Пример #3
0
 class Meta:
     model = Discount
     exclude = ("shops", "created_by", "modified_by")
     widgets = {
         "category": QuickAddCategorySelect(editable_model="shuup.Category"),
         "contact_group": QuickAddContactGroupSelect(editable_model="shuup.ContactGroup"),
         "coupon_code": QuickAddCouponCodeSelect(editable_model="discounts.CouponCode"),
         "availability_exceptions": QuickAddAvailabilityExceptionMultiSelect(),
         "happy_hours": QuickAddHappyHourMultiSelect()
     }
Пример #4
0
class MassEditForm(forms.Form):
    name = forms.CharField(max_length=255, required=False)
    default_price_value = forms.DecimalField(label="Default Price", required=False)
    visibility = EnumIntegerField(ShopProductVisibility).formfield(label=_("Visibility"), required=False)
    primary_category = forms.ModelChoiceField(
        label=_("Primary Category"), queryset=Category.objects.all_except_deleted(), required=False,
        widget=QuickAddCategorySelect())
    categories = forms.ModelMultipleChoiceField(
        label=_("Additional Categories"), queryset=Category.objects.all_except_deleted(), required=False,
        widget=QuickAddCategoryMultiSelect())
    purchasable = forms.BooleanField(label=_("Purchasable"), required=False)
Пример #5
0
 class Meta:
     model = Discount
     exclude = ("shop", "created_by", "modified_by")
     widgets = {
         "category":
         QuickAddCategorySelect(editable_model="shuup.Category"),
         "contact_group":
         QuickAddContactGroupSelect(editable_model="shuup.ContactGroup"),
         "happy_hours":
         QuickAddHappyHourMultiSelect(),
     }
Пример #6
0
    def __init__(self, **kwargs):
        # TODO: Revise this. Since this is shop product form then maybe we should have shop available insted of request
        self.request = kwargs.pop("request", None)
        super(ShopProductForm, self).__init__(**kwargs)
        payment_methods_qs = PaymentMethod.objects.all()
        shipping_methods_qs = ShippingMethod.objects.all()
        if self.request:
            shop = self.request.shop
            payment_methods_qs = payment_methods_qs.filter(shop=shop)
            shipping_methods_qs = ShippingMethod.objects.filter(shop=shop)
        self.fields["payment_methods"].queryset = payment_methods_qs
        self.fields["shipping_methods"].queryset = shipping_methods_qs
        self.fields["default_price_value"].required = True

        initial_suppliers = []
        initial_categories = []

        if self.instance.pk:
            initial_suppliers = self.instance.suppliers.all()
            initial_categories = self.instance.categories.all()

        self.fields["suppliers"] = Select2ModelMultipleField(
            initial=initial_suppliers,
            model=Supplier,
            widget=QuickAddSupplierMultiSelect(
                initial=initial_suppliers,
                attrs={"data-search-mode": "enabled"}
            ),
            required=False
        )
        self.fields["primary_category"] = Select2ModelField(
            initial=(self.instance.primary_category if self.instance.pk else None),
            model=Category,
            widget=QuickAddCategorySelect(
                editable_model="shuup.Category",
                initial=(self.instance.primary_category if self.instance.pk else None),
                attrs={"data-placeholder": ugettext("Select a category")}
            ),
            required=False
        )
        self.fields["categories"] = Select2ModelMultipleField(
            initial=initial_categories,
            model=Category,
            widget=QuickAddCategoryMultiSelect(initial=initial_categories),
            required=False
        )
Пример #7
0
    class Meta:
        model = Category
        fields = (
            "parent",
            "status",
            "ordering",
            "visibility",
            "visible_in_menu",
            "visibility_groups",
            "name",
            "image",
            "description",
            "slug",
        )

        widgets = {
            "status": forms.RadioSelect,
            "visibility": forms.RadioSelect,
            "description": TextEditorWidget(),
            "parent": QuickAddCategorySelect(editable_model="shuup.Category")
        }
Пример #8
0
    def __init__(self, **kwargs):
        # TODO: Revise this. Since this is shop product form then maybe we should have shop available insted of request
        self.request = kwargs.pop("request", None)
        super(ShopProductForm, self).__init__(**kwargs)
        payment_methods_qs = PaymentMethod.objects.all()
        shipping_methods_qs = ShippingMethod.objects.all()
        if self.request:
            shop = self.request.shop
            payment_methods_qs = payment_methods_qs.filter(shop=shop)
            shipping_methods_qs = ShippingMethod.objects.filter(shop=shop)
        self.fields["payment_methods"].queryset = payment_methods_qs
        self.fields["shipping_methods"].queryset = shipping_methods_qs
        self.fields["default_price_value"].required = True

        initial_categories = []
        initial_suppliers = []

        if self.instance.pk:
            initial_categories = self.instance.categories.all()
            initial_suppliers = self.instance.suppliers.all()
        elif not settings.SHUUP_ENABLE_MULTIPLE_SUPPLIERS:
            supplier = Supplier.objects.first()
            initial_suppliers = ([supplier] if supplier else [])

        if settings.SHUUP_ADMIN_LOAD_SELECT_OBJECTS_ASYNC.get("suppliers"):
            self.fields["suppliers"] = Select2ModelMultipleField(
                initial=initial_suppliers,
                model=Supplier,
                widget=QuickAddSupplierMultiSelect(
                    initial=initial_suppliers,
                    attrs={"data-search-mode": "enabled"}
                ),
                required=False
            )
        else:
            self.fields["suppliers"].widget = QuickAddSupplierMultiSelect(initial=initial_suppliers)

        if settings.SHUUP_ADMIN_LOAD_SELECT_OBJECTS_ASYNC.get("categories"):
            self.fields["primary_category"] = Select2ModelField(
                initial=(self.instance.primary_category if self.instance.pk else None),
                model=Category,
                widget=QuickAddCategorySelect(
                    editable_model="shuup.Category",
                    initial=(self.instance.primary_category if self.instance.pk else None),
                    attrs={"data-placeholder": ugettext("Select a category")}
                ),
                required=False
            )
            self.fields["categories"] = Select2ModelMultipleField(
                initial=initial_categories,
                model=Category,
                widget=QuickAddCategoryMultiSelect(initial=initial_categories),
                required=False
            )
        else:
            categories_choices = [
                (cat.pk, cat.get_hierarchy())
                for cat in Category.objects.all_except_deleted(shop=get_shop(self.request))
            ]
            self.fields["primary_category"].widget = QuickAddCategorySelect(
                initial=(
                    self.instance.primary_category if self.instance.pk and self.instance.primary_category else None
                ),
                editable_model="shuup.Category",
                attrs={"data-placeholder": ugettext("Select a category")},
                choices=categories_choices,
                model=NoModel()
            )
            self.fields["categories"].widget = QuickAddCategoryMultiSelect(
                initial=initial_categories,
                choices=categories_choices,
                model=NoModel()
            )