Пример #1
0
    def __init__(self, **kwargs):
        self.product = kwargs.pop("product")
        self.allowed_media_kinds = kwargs.pop("allowed_media_kinds")
        default_shop = kwargs.pop("default_shop")
        super(BaseProductMediaForm, self).__init__(**kwargs)

        self.fields["file"].widget = MediaChoiceWidget(
        )  # Filer misimplemented the field; we need to do this manually.
        self.fields["file"].required = True

        if self.allowed_media_kinds:
            # multiple media kinds allowed, filter the choices list to reflect the `self.allowed_media_kinds`
            allowed_kinds_values = set(v.value
                                       for v in self.allowed_media_kinds)
            self.fields["kind"].choices = [
                (value, choice)
                for value, choice in self.fields["kind"].choices
                if value in allowed_kinds_values
            ]

            if len(self.allowed_media_kinds) == 1:
                # only one media kind given, no point showing the dropdown
                self.fields["kind"].widget = forms.HiddenInput()

            self.fields["kind"].initial = self.allowed_media_kinds[0]

        if not self.instance.pk:
            self.fields["shops"].initial = [default_shop]

        self.file_url = self.instance.url
Пример #2
0
 def __init__(self, **kwargs):
     super(ShopBaseForm, self).__init__(**kwargs)
     self.fields["logo"].widget = MediaChoiceWidget(clearable=True)
     locale = get_current_babel_locale()
     self.fields["currency"] = forms.ChoiceField(choices=sorted(
         locale.currencies.items()),
                                                 required=True,
                                                 label=_("Currency"))
     self.disable_protected_fields()
Пример #3
0
 def __init__(self, **kwargs):
     super(ShopBaseForm, self).__init__(**kwargs)
     self.fields["logo"].widget = MediaChoiceWidget(clearable=True)
     self.fields["currency"] = forms.ChoiceField(
         choices=get_currency_choices(),
         required=True,
         label=_("Currency"),
         help_text=
         _("The primary shop currency. This is the currency used when selling your products."
           ))
     self.disable_protected_fields()
Пример #4
0
    def __init__(self, **kwargs):
        super(CategoryBaseForm, self).__init__(**kwargs)
        # Exclude `DELETED`. We don't want people to use that field to set a category as deleted.
        filter_form_field_choices(self.fields["status"],
                                  (CategoryStatus.DELETED.value, ),
                                  invert=True)

        # Exclude current category from parents, because it cannot be its own child anyways
        filter_form_field_choices(self.fields["parent"],
                                  (kwargs["instance"].pk, ),
                                  invert=True)
        self.fields["image"].widget = MediaChoiceWidget(clearable=True)
Пример #5
0
 def __init__(self, **kwargs):
     initial_languages = [i[0] for i in kwargs.get("languages", [])]
     super(ShopBaseForm, self).__init__(**kwargs)
     self.fields["logo"].widget = MediaChoiceWidget(clearable=True)
     locale = get_current_babel_locale()
     self.fields["currency"] = forms.ChoiceField(choices=sorted(
         locale.currencies.items()),
                                                 required=True,
                                                 label=_("Currency"))
     self.fields["languages"] = forms.MultipleChoiceField(
         choices=settings.LANGUAGES,
         initial=initial_languages,
         required=True,
         label=_("Languages"))
     self.disable_protected_fields()
Пример #6
0
 def __init__(self, **kwargs):
     super(ShuupAdminForm, self).__init__(**kwargs)
     for field in self.fields:
         if issubclass(self.fields[field].widget.__class__,
                       AdminFileWidget):
             self.fields[field].widget = MediaChoiceWidget(clearable=True)
Пример #7
0
 def __init__(self, **kwargs):
     self.product = kwargs.pop("product")
     super(ProductMediaForm, self).__init__(**kwargs)
     # Filer has a misimplemented field; we need to do this manually.
     self.fields["file"].widget = MediaChoiceWidget()
Пример #8
0
 def __init__(self, **kwargs):
     super(ShopBaseForm, self).__init__(**kwargs)
     self.fields["logo"].widget = MediaChoiceWidget(clearable=True)
     self.fields["currency"] = forms.ChoiceField(
         choices=get_currency_choices(), required=True, label=_("Currency"))
     self.disable_protected_fields()
Пример #9
0
 def __init__(self, **kwargs):
     super(ShopBaseForm, self).__init__(**kwargs)
     self.fields["logo"].widget = MediaChoiceWidget(clearable=True)