本文整理汇总了Python中shoop.apps.provides.get_provide_objects函数的典型用法代码示例。如果您正苦于以下问题:Python get_provide_objects函数的具体用法?Python get_provide_objects怎么用?Python get_provide_objects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_provide_objects函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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))
示例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
示例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()
示例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
示例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.
示例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
示例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)
示例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