• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python provides.get_provide_objects函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shoop.apps.provides.get_provide_objects函数的典型用法代码示例。如果您正苦于以下问题:Python get_provide_objects函数的具体用法?Python get_provide_objects怎么用?Python get_provide_objects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_provide_objects函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_form_parts

 def get_form_parts(self, object):
     form_parts = super(ServiceEditView, self).get_form_parts(object)
     if not object.pk:
         return form_parts
     for form in get_provide_objects(self.form_provide_key):
         form_parts.append(self._get_behavior_form_part(form, object))
     for form_class in get_provide_objects(self.form_part_provide_key):
         form_parts.append(form_class(self.request, object))
     return form_parts
开发者ID:00WhengWheng,项目名称:shuup,代码行数:9,代码来源:_edit.py


示例2: get_form_parts

    def get_form_parts(self, object):
        form_parts = super(CampaignEditView, self).get_form_parts(object)
        if not object.pk:
            return form_parts

        for form in get_provide_objects(self.condition_key):
            form_parts.append(self._get_rules_form_part(form, object))

        for form in get_provide_objects(self.effect_key):
            form_parts.append(self._get_effects_form_part(form, object))

        return form_parts
开发者ID:monokrome,项目名称:shuup,代码行数:12,代码来源:_edit.py


示例3: get_toolbar

    def get_toolbar(self):
        order = self.object
        toolbar = Toolbar()
        toolbar.append(URLActionButton(
            text=_("Create Shipment"),
            icon="fa fa-truck",
            disable_reason=_("There are no products to ship") if not order.get_unshipped_products() else None,
            url=reverse("shoop_admin:order.create-shipment", kwargs={"pk": order.pk}),
            extra_css_class="btn-info"
        ))

        toolbar.append(PostActionButton(
            post_url=reverse("shoop_admin:order.set-status", kwargs={"pk": order.pk}),
            name="status",
            value=OrderStatus.objects.get_default_complete().pk,
            text=_("Set Complete"),
            icon="fa fa-check-circle",
            disable_reason=(
                _("This order can not be set as complete at this point")
                if not order.can_set_complete()
                else None
            ),
            extra_css_class="btn-success"
        ))

        for button in get_provide_objects("admin_order_toolbar_button"):
            toolbar.append(button(order))

        return toolbar
开发者ID:Carolina061,项目名称:shoop,代码行数:29,代码来源:detail.py


示例4: __init__

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop("request")
        super(CampaignFormMixin, self).__init__(*args, **kwargs)

        for provide_key in self.provide_keys:
            for cls in sorted(get_provide_objects(provide_key), key=lambda x: x.name):
                obj = cls()
                if obj.identifier in self.fields:
                    continue

                for field in obj._meta.get_fields(include_parents=False):
                    if isinstance(field, OneToOneField):
                        continue

                    self.rule_ids.add(obj.identifier)
                    kwargs = {
                        "required": False,  # rules are not required by default, validation is made later on
                        "help_text": obj.description
                    }
                    if isinstance(field, ManyToManyField):
                        kwargs.update({
                            "initial": self._get_many_to_many_initial_values(obj),
                            "widget": Select2Multiple(model=obj.model)
                        })
                        formfield = forms.CharField(**kwargs)
                        value = kwargs.get("initial")
                        if value:
                            formfield.widget.choices = [
                                (object.pk, force_text(object)) for object in obj.model.objects.filter(pk__in=value)]
                    else:
                        kwargs.update({
                            "initial": self.get_initial_value(obj.identifier)
                        })
                        formfield = field.formfield(**kwargs)
                    self.fields[obj.identifier] = formfield
开发者ID:lapetitejasmine,项目名称:shoop,代码行数:35,代码来源:forms.py


示例5: _postprocess

 def _postprocess(self, context, content):
     for inject_func in get_provide_objects("xtheme_resource_injection"):
         if callable(inject_func):
             inject_func(context, content)
     add_edit_resources(context)
     content = inject_resources(context, content)
     return content
开发者ID:00WhengWheng,项目名称:shuup,代码行数:7,代码来源:engine.py


示例6: get_form

 def get_form(self, form_class=None):
     form_classes = list(get_provide_objects(self.form_provide_key))
     form_infos = _FormInfoMap(form_classes)
     if self.object and self.object.pk:
         return self._get_concrete_form(form_infos)
     else:
         return self._get_type_choice_form(form_infos)
开发者ID:00WhengWheng,项目名称:shuup,代码行数:7,代码来源:_edit.py


示例7: get_context_data

 def get_context_data(self, **kwargs):
     context = super(ThemeConfigView, self).get_context_data(**kwargs)
     context["theme_classes"] = sorted(
         [t for t in get_provide_objects("xtheme") if t.identifier],
         key=lambda t: (t.name or t.identifier)
     )
     context["current_theme"] = get_current_theme()
     return context
开发者ID:taedori81,项目名称:shoop,代码行数:8,代码来源:views.py


示例8: test_provides

def test_provides():
    IDENTIFIED_OBJECT_SPEC = "%s:IdentifiedObject" % __name__
    category = str(uuid.uuid4())
    with override_provides(category, [
        IDENTIFIED_OBJECT_SPEC,
        "%s:UnidentifiedObject" % __name__,
        "%s:VeryUnidentifiedObject" % __name__,
    ]):
        objects = get_provide_objects(category)
        assert set(objects) == set((IdentifiedObject, UnidentifiedObject, VeryUnidentifiedObject))
        assert get_identifier_to_object_map(category)["identifier"] == IdentifiedObject
        assert get_identifier_to_spec_map(category)["identifier"] == IDENTIFIED_OBJECT_SPEC
        assert get_provide_specs_and_objects(category)[IDENTIFIED_OBJECT_SPEC] == IdentifiedObject

    # Test the context manager clears things correctly
    assert empty_iterable(get_provide_objects(category))
    assert empty_iterable(get_provide_specs_and_objects(category))
    assert empty_iterable(get_identifier_to_object_map(category))
    assert empty_iterable(get_identifier_to_spec_map(category))
开发者ID:taedori81,项目名称:shoop,代码行数:19,代码来源:test_provides.py


示例9: get_module_choices

    def get_module_choices(cls, empty_label=None):
        if empty_label is None:
            empty_label = _("No Choice")
        choices = [("", empty_label)]

        for module in get_provide_objects(cls.module_provides_key):
            if module.identifier:
                choices.append((module.identifier, getattr(module, "name", None) or module.identifier))
        choices.sort()
        return choices
开发者ID:DemOneEh,项目名称:shoop,代码行数:10,代码来源:interface.py


示例10: _save_effects

 def _save_effects(self, effect_key, instance):
     for cls in get_provide_objects(effect_key):
         if not self.cleaned_data[cls.identifier]:
             continue
         field_value = self.cleaned_data[cls.identifier]
         effect = cls.objects.create(campaign=instance)
         if effect.model:
             effect.values = effect.model.objects.filter(pk__in=ast.literal_eval(field_value))
         else:
             effect.value = field_value
         effect.campaign = instance
         effect.save()
开发者ID:00WhengWheng,项目名称:shuup,代码行数:12,代码来源:forms.py


示例11: _get_helpers

def _get_helpers():
    helpers = HelpersNamespace()
    from shoop.front.template_helpers import general, product, category, urls

    helpers.general = general
    helpers.product = product
    helpers.category = category
    helpers.urls = urls
    for namespace in get_provide_objects("front_template_helper_namespace"):
        if namespace and getattr(namespace, "name", None):
            if callable(namespace):  # If it's a class, instantiate it
                namespace = namespace()
            setattr(helpers, namespace.name, namespace)
    return helpers
开发者ID:charn,项目名称:shoop,代码行数:14,代码来源:shoop_front.py


示例12: get_theme_by_identifier

def get_theme_by_identifier(identifier, settings_obj=None):
    """
    Get an instantiated theme by identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :param settings_obj: Optional ThemeSettings object for the theme constructor
    :type settings_obj: shoop.xtheme.models.ThemeSettings
    :return: Theme object or None
    :rtype: Theme
    """
    for theme_cls in get_provide_objects("xtheme"):
        if theme_cls.identifier == identifier:
            return theme_cls(settings_obj=settings_obj)
    return None  # No such thing.
开发者ID:ShunyaHumm,项目名称:shoop,代码行数:15,代码来源:theme.py


示例13: get_context_data

    def get_context_data(self, **kwargs):
        context = super(OrderDetailView, self).get_context_data(**kwargs)
        context["toolbar"] = self.get_toolbar()
        context["title"] = force_text(self.object)
        context["order_sections"] = []

        order_sections_provides = sorted(get_provide_objects("admin_order_section"), key=lambda x: x.order)
        for admin_order_section in order_sections_provides:
            # Check whether the OrderSection should be visible for the current object
            if admin_order_section.visible_for_order(self.object):
                context["order_sections"].append(admin_order_section)
                # add additional context data where the key is the order_section identifier
                context[admin_order_section.identifier] = admin_order_section.get_context_data(self.object)

        return context
开发者ID:00WhengWheng,项目名称:shuup,代码行数:15,代码来源:detail.py


示例14: _save_conditions_and_filters

    def _save_conditions_and_filters(self, provide_key, instance):
        for cls in get_provide_objects(provide_key):
            if not self.cleaned_data[cls.identifier]:
                continue

            field_value = self.cleaned_data[cls.identifier]
            rule = cls.objects.create()
            if rule.model:
                rule.values = rule.model.objects.filter(pk__in=ast.literal_eval(field_value))
            else:
                rule.value = field_value
            rule.save()
            if "condition" in cls.identifier:  # a bit weak but to rely this
                instance.conditions.add(rule)
            else:
                instance.filters.add(rule)
开发者ID:00WhengWheng,项目名称:shuup,代码行数:16,代码来源:forms.py


示例15: get_checkout_phases_for_service

def get_checkout_phases_for_service(checkout_process, service):
    """
    Get checkout phases for given service.

    :type checkout_process: shoop.front.checkout.CheckoutProcess
    :type service: shoop.core.models.Service
    :rtype: Iterable[shoop.front.checkout.CheckoutPhaseViewMixin]
    """
    classes = get_provide_objects("front_service_checkout_phase_provider")
    for provider_cls in classes:
        provider = provider_cls()
        assert isinstance(provider, ServiceCheckoutPhaseProvider)
        phase = provider.get_checkout_phase(checkout_process, service)
        if phase:
            assert isinstance(phase, CheckoutPhaseViewMixin)
            yield phase
开发者ID:00WhengWheng,项目名称:shuup,代码行数:16,代码来源:_services.py


示例16: test_theme_selection

def test_theme_selection():
    """
    Test that a theme with a `template_dir` actually affects template directory selection.
    """
    with override_current_theme_class(), override_provides("xtheme", [
        "shoop_tests.xtheme.utils:FauxTheme",
        "shoop_tests.xtheme.utils:FauxTheme2",
        "shoop_tests.xtheme.utils:H2G2Theme",
    ]):
        ThemeSettings.objects.all().delete()
        for theme in get_provide_objects("xtheme"):
            set_current_theme(theme.identifier)
            je = get_jinja2_engine()
            wrapper = (noop() if theme.identifier == "h2g2" else pytest.raises(TemplateDoesNotExist))
            with wrapper:
                t = je.get_template("42.jinja")
                content = t.render().strip()
                assert "a slice of lemon wrapped around a large gold brick" in content.replace("\n", " ")
开发者ID:00WhengWheng,项目名称:shuup,代码行数:18,代码来源:test_theme_selection.py


示例17: _add_fields

    def _add_fields(self, provide_key, is_provide=True):
        for cls in sorted(get_provide_objects(provide_key), key=lambda x: x.name):
            obj = cls()
            if obj.identifier in self.fields:
                continue

            for field in obj._meta.get_fields(include_parents=False):
                if isinstance(field, OneToOneField):
                    continue

                if is_provide:
                    self.rule_ids.add(obj.identifier)
                else:
                    self.effect_ids.add(obj.identifier)

                kwargs = {
                    "required": False,  # rules are not required by default, validation is made later on
                    "help_text": obj.description
                }

                if hasattr(obj, "admin_form_class") and obj.admin_form_class:
                    kwargs.update({
                        "form_class": obj.admin_form_class
                    })

                if isinstance(field, ManyToManyField):
                    kwargs.update({
                        "initial": self._get_many_to_many_initial_values(obj),
                        "widget": Select2Multiple(model=obj.model)
                    })
                    formfield = forms.CharField(**kwargs)
                    value = kwargs.get("initial")
                    if value:
                        formfield.widget.choices = [
                            (object.pk, force_text(object)) for object in obj.model.objects.filter(pk__in=value)]
                else:
                    kwargs.update({
                        "initial": self.get_initial_value(obj.identifier)
                    })
                    formfield = field.formfield(**kwargs)

                self.fields[obj.identifier] = formfield
开发者ID:00WhengWheng,项目名称:shuup,代码行数:42,代码来源:forms.py


示例18: clean

    def clean(self):
        data = super(CampaignFormMixin, self).clean()

        # Ensure at least 1 effect is set
        effect_count = 0
        for key in self.effect_keys:
            for cls in get_provide_objects(key):
                if data[cls.identifier]:
                    effect_count += 1

                if effect_count > 1:
                    raise ValidationError(_("You should only define one effect."))
        if not effect_count:
            raise ValidationError(_("At least one effect must be defined."))

        start_datetime = data.get("start_datetime")
        end_datetime = data.get("end_datetime")
        if start_datetime and end_datetime and end_datetime < start_datetime:
            raise ValidationError(_("Campaign end date can't be before start date."), code="end_is_before_start")

        return data
开发者ID:00WhengWheng,项目名称:shuup,代码行数:21,代码来源:forms.py


示例19: __init__

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop("request")
        super(CampaignFormMixin, self).__init__(*args, **kwargs)

        for provide_key in self.provide_keys:
            for cls in sorted(get_provide_objects(provide_key), key=lambda x: x.name):
                obj = cls()
                if obj.identifier in self.fields:
                    continue

                for field in obj._meta.get_fields(include_parents=False):
                    if isinstance(field, OneToOneField):
                        continue

                    kwargs = {
                        "initial": self.get_initial_value(obj.identifier),
                        "required": False,  # rules are not required by default, validation is made later on
                        "help_text": obj.description
                    }
                    self.rule_ids.add(obj.identifier)
                    self.fields[obj.identifier] = field.formfield(**kwargs)
开发者ID:LuanaF,项目名称:shoop,代码行数:21,代码来源:forms.py


示例20: save

    def save(self, commit=True):
        instance = super(CampaignFormMixin, self).save(commit)
        if self.cleaned_data.get("coupon"):
            instance.coupon = Coupon.objects.get(pk=self.cleaned_data.get("coupon"))

        if hasattr(instance, "conditions"):
            instance.conditions.clear()

        if hasattr(instance, "filters"):
            instance.filters.clear()

        instance.save()

        for provide_key in self.provide_keys:
            for cls in get_provide_objects(provide_key):
                if not self.cleaned_data[cls.identifier]:
                    continue

                field_value = self.cleaned_data[cls.identifier]
                rule = cls.objects.create()
                if rule.model:
                    rule.values = rule.model.objects.filter(pk__in=field_value)
                else:
                    rule.value = field_value
                rule.save()
                if "condition" in cls.identifier:  # a bit weak but to rely this
                    instance.conditions.add(rule)
                else:
                    instance.filters.add(rule)

        instance.save()

        if not instance.created_by:
            instance.created_by = self.request.user
            instance.modified_by = self.request.user
            instance.save()

        return instance
开发者ID:LuanaF,项目名称:shoop,代码行数:38,代码来源:forms.py



注:本文中的shoop.apps.provides.get_provide_objects函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.get_person_contact函数代码示例发布时间:2022-05-27
下一篇:
Python urls.get_model_url函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap