def _load_phases(self): phases = OrderedDict() for phase_spec in self.phase_specs: phase_class = load(phase_spec) phases[phase_class.identifier] = self.instantiate_phase_class( phase_class) return list(phases.values())
def test_list_view(rf, class_spec): view = load(class_spec).as_view() request = rf.get("/", { "jq": json.dumps({"perPage": 100, "page": 1}) }) response = view(request) assert 200 <= response.status_code < 300
def encode_enum(enum_val): enum_cls = enum_val.__class__ spec = "%s:%s" % (enum_cls.__module__, enum_cls.__name__) try: if load(spec) != enum_cls: raise ImproperlyConfigured("That's not the same class!") except ImproperlyConfigured: # Also raised by `load` return enum_val.value # Fall back to the bare value. return [spec, enum_val.value]
def get_module_choices(cls, empty_label=None): if empty_label is None: empty_label = _('No Choice') choices = [("", empty_label)] for impl_id, spec in cls.get_module_implementation_map().items(): choices.append((impl_id, load(spec).name or impl_id)) choices.sort() return choices
def test_detail_view(rf, admin_user, model_and_class): get_default_shop() # obvious prerequisite model_func, class_spec = model_and_class model = model_func() view = load(class_spec).as_view() request = apply_request_middleware(rf.get("/"), user=admin_user) response = view(request, pk=model.pk) if hasattr(response, "render"): response.render() assert 200 <= response.status_code < 300
def _load_provide_objects(category): provide_specs = _get_provide_specs_from_apps(category) loaded_provides = _loaded_provides[category] if set(provide_specs) != set(loaded_provides.keys()): # Changes occurred, reload provides _uncache(category) explanation = "Loading provides %s" % category loaded_provides = OrderedDict() for spec in provide_specs: loaded_provides[spec] = load(spec, explanation) _loaded_provides[category] = loaded_provides return _loaded_provides.get(category, {})
def get_order_identifier(order): if order.identifier: raise ValueError("Order passed to get_order_identifier() already has an identifier") order_identifier_method = settings.SHOOP_ORDER_IDENTIFIER_METHOD if order_identifier_method == "id": return force_text(order.id) elif callable(order_identifier_method): return order_identifier_method(order) else: getter = load(order_identifier_method, "Order identifier generator") return getter(order)
def _load_provide_objects(category): provide_specs = _get_provide_specs_from_apps(category) loaded_provides = _loaded_provides[category] if set(provide_specs) != set( loaded_provides.keys()): # Changes occurred, reload provides _uncache(category) explanation = "Loading provides %s" % category loaded_provides = OrderedDict() for spec in provide_specs: loaded_provides[spec] = load(spec, explanation) _loaded_provides[category] = loaded_provides return _loaded_provides.get(category, {})
def dispatch(self, request, *args, **kwargs): # This view only dispatches further to the method module's own detail view class object = self.get_object() module = object.module if not module.admin_detail_view_class: raise Problem("Module %s has no admin detail view" % module.name) if isinstance(module.admin_detail_view_class, six.text_type): view_class = load(module.admin_detail_view_class) else: view_class = module.admin_detail_view_class kwargs["object"] = object return view_class(model=self.model).dispatch(request, *args, **kwargs)
def get_order_identifier(order): if order.identifier: raise ValueError( "Order passed to get_order_identifier() already has an identifier") order_identifier_method = settings.SHOOP_ORDER_IDENTIFIER_METHOD if order_identifier_method == "id": return force_text(order.id) elif callable(order_identifier_method): return order_identifier_method(order) else: getter = load(order_identifier_method, "Order identifier generator") return getter(order)
def test_toolbar_button(rf, admin_user): shop = get_default_shop() supplier = get_default_supplier() product = create_product("simple-test-product", shop) order = create_order_with_product(product, supplier, 6, 6, shop=shop) view = load("shoop.admin.modules.orders.views.OrderDetailView").as_view() request = apply_request_middleware(rf.get("/"), user=admin_user) response = view(request, pk=order.pk) expected_button_class = "SimplePrintoutsToolbarButton" toolbar = response.context_data.get("toolbar") assert any(button.__class__.__name__ == expected_button_class for button in toolbar) assert response.status_code == 200
def _load_module(self): spec = self.default_module_spec module_identifier = self.module_identifier if module_identifier: impls = self.get_module_implementation_map() if module_identifier not in impls: raise ModuleNotFound("Invalid module identifier %r in %r" % (module_identifier, self)) spec = impls[module_identifier] cls = load(spec, context_explanation="Loading module for %r" % self) options = getattr(self, self.module_options_field, None) or {} return cls(self, options)
def get_reference_number(order): if order.reference_number: raise ValueError("Order passed to get_reference_number() already has a reference number") reference_number_method = settings.SHOOP_REFERENCE_NUMBER_METHOD if reference_number_method == "unique": return get_unique_reference_number(order) elif reference_number_method == "running": return get_running_reference_number(order) elif reference_number_method == "shop_running": return get_shop_running_reference_number(order) elif callable(reference_number_method): return reference_number_method(order) else: getter = load(reference_number_method, "Reference number generator") return getter(order)
def get_reference_number(order): if order.reference_number: raise ValueError( "Order passed to get_reference_number() already has a reference number" ) reference_number_method = settings.SHOOP_REFERENCE_NUMBER_METHOD if reference_number_method == "unique": return get_unique_reference_number(order) elif reference_number_method == "running": return get_running_reference_number(order) elif reference_number_method == "shop_running": return get_shop_running_reference_number(order) elif callable(reference_number_method): return reference_number_method(order) else: getter = load(reference_number_method, "Reference number generator") return getter(order)
def decode_enum(val): spec, value = val cls = load(spec) if issubclass(cls, Enum): return cls(value) return value # Fall back to the bare value. Not optimal, I know.
def _load_phases(self): phases = OrderedDict() for phase_spec in self.phase_specs: phase_class = load(phase_spec) phases[phase_class.identifier] = self.instantiate_phase_class(phase_class) return list(phases.values())
def register(module_class): if isinstance(module_class, six.string_types): module_class = load(module_class, "Admin Module") _registry.append(module_class())