当前位置: 首页>>代码示例>>Python>>正文


Python urls.get_model_url函数代码示例

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


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

示例1: test_model_url

def test_model_url():
    with admin_only_urls():
        with pytest.raises(NoModelUrl):
            get_model_url(Counter)  # That's silly!
        p = get_default_product()

        assert get_model_url(p)
开发者ID:gurch101,项目名称:shuup,代码行数:7,代码来源:test_urls.py

示例2: test_edit_object_view

def test_edit_object_view(rf, admin_user, creator_fn):
    shop = factories.get_default_shop()
    view = EditObjectView.as_view()
    object_instance = creator_fn()
    model = ".".join(ContentType.objects.get_for_model(object_instance).natural_key())

    # correct shop
    response = _get_edit_object_view(rf, view, model, object_instance.id, admin_user, shop)
    assert response.status_code == 302

    urls = []

    try:
        urls.append(get_model_url(object_instance, kind="edit", user=admin_user, shop=shop))
    except NoModelUrl:
        pass

    try:
        urls.append(get_model_url(object_instance, kind="detail", user=admin_user, shop=shop))
    except NoModelUrl:
        pass

    assert response.url in urls

    # pass the mode query parameter
    response = _get_edit_object_view(rf, view, model, object_instance.id, admin_user, shop, mode="test")
    assert response.status_code == 302
    assert "mode=test" in response.url
开发者ID:ruqaiya,项目名称:shuup,代码行数:28,代码来源:test_edit_object_view.py

示例3: get_success_url

    def get_success_url(self):  # noqa (C901)
        if self.request.GET.get("mode", "") == "iframe":
            params = ["mode=iframe", "iframe_close=yes"]

            quick_add_target = self.request.GET.get("quick_add_target")
            if quick_add_target:
                params.append("quick_add_target=%s" % quick_add_target)

            quick_add_callback = self.request.GET.get("quick_add_callback")
            if quick_add_callback:
                params.append("quick_add_callback=%s" % quick_add_callback)

            return "%s?%s" % (get_model_url(self.object, shop=self.request.shop), "&".join(params))

        next = self.request.POST.get("__next")
        try:
            if next == "return":
                return self.get_return_url()
            elif next == "new":
                return self.get_new_url()
        except NoModelUrl:
            pass

        try:
            return super(CreateOrUpdateView, self).get_success_url()
        except ImproperlyConfigured:
            pass

        try:
            return get_model_url(self.object, shop=self.request.shop)
        except NoModelUrl:
            pass
开发者ID:ruqaiya,项目名称:shuup,代码行数:32,代码来源:views.py

示例4: _get_parent_and_sibling_items

 def _get_parent_and_sibling_items(self, parent, siblings):
     yield DropdownItem(
         text=_("Parent: %s") % parent,
         icon="fa fa-eye",
         url=get_model_url(parent),
     )
     for sib in siblings:
         yield DropdownItem(
             text=_("Sibling: %s") % sib,
             icon="fa fa-eye",
             url=get_model_url(sib),
         )
开发者ID:ahmadzai,项目名称:shuup,代码行数:12,代码来源:toolbars.py

示例5: get

    def get(self, request):     # noqa (C901)
        model_name = request.GET.get("model")
        object_id = request.GET.get("pk", request.GET.get("id"))

        if not model_name or not object_id:
            return HttpResponseBadRequest(_("Invalid object."))

        url = None

        try:
            model = apps.get_model(model_name)
        except LookupError:
            return HttpResponseBadRequest(_("Invalid model."))

        instance = model.objects.filter(pk=object_id).first()
        if instance:
            try:
                # try edit first
                try:
                    url = get_model_url(
                        instance,
                        kind="edit",
                        user=request.user,
                        shop=get_shop(request),
                        raise_permission_denied=True
                    )
                except NoModelUrl:
                    # try detail
                    try:
                        url = get_model_url(
                            instance,
                            kind="detail",
                            user=request.user,
                            shop=get_shop(request),
                            raise_permission_denied=True
                        )
                    except NoModelUrl:
                        pass
            except PermissionDenied as exception:
                from django.utils.encoding import force_text
                raise Problem(force_text(exception))

            if url:
                # forward the mode param
                if request.GET.get("mode"):
                    url = "{}?mode={}".format(url, request.GET["mode"])

                return HttpResponseRedirect(url)

        raise Http404(_("Object not found"))
开发者ID:ruqaiya,项目名称:shuup,代码行数:50,代码来源:edit.py

示例6: form_valid

    def form_valid(self, form):
        product_ids_to_quantities = dict(
            (int(key.replace("q_", "")), value)
            for (key, value)
            in six.iteritems(form.cleaned_data)
            if key.startswith("q_") and value > 0
        )
        order = self.object
        product_map = Product.objects.in_bulk(set(product_ids_to_quantities.keys()))
        products_to_quantities = dict(
            (product_map[product_id], quantity)
            for (product_id, quantity)
            in six.iteritems(product_ids_to_quantities)
        )

        unsaved_shipment = Shipment(order=order, supplier=form.cleaned_data["supplier"])
        for extend_class in get_provide_objects(FORM_MODIFIER_PROVIDER_KEY):
            extend_class().form_valid_hook(form, unsaved_shipment)
        try:
            shipment = order.create_shipment(
                product_quantities=products_to_quantities,
                shipment=unsaved_shipment
            )
        except NoProductsToShipException:
            messages.error(self.request, _("No products to ship."))
            return self.form_invalid(form)
        else:
            messages.success(self.request, _("Shipment %s created.") % shipment.id)
            return HttpResponseRedirect(get_model_url(order))
开发者ID:ahmadzai,项目名称:shuup,代码行数:29,代码来源:shipment.py

示例7: get_breadcrumb_parents

 def get_breadcrumb_parents(self):
     return [
         MenuEntry(
             text="%s" % self.object,
             url=get_model_url(self.object)
         )
     ]
开发者ID:suutari,项目名称:shoop,代码行数:7,代码来源:edit_media.py

示例8: handle_product_data

    def handle_product_data(self, request):
        product_id = request.GET["id"]
        shop_id = request.GET["shop_id"]
        customer_id = request.GET.get("customer_id")
        supplier_id = request.GET.get("supplier_id")
        quantity = decimal.Decimal(request.GET.get("quantity", 1))
        product = Product.objects.filter(pk=product_id).first()
        if not product:
            return {"errorText": _("Product %s does not exist.") % product_id}
        shop = Shop.objects.get(pk=shop_id)
        try:
            shop_product = product.get_shop_instance(shop)
        except ShopProduct.DoesNotExist:
            return {
                "errorText": _("Product %(product)s is not available in the %(shop)s shop.") %
                {"product": product.name, "shop": shop.name}
            }

        min_quantity = shop_product.minimum_purchase_quantity
        # Make quantity to be at least minimum quantity
        quantity = (min_quantity if quantity < min_quantity else quantity)
        customer = Contact.objects.filter(pk=customer_id).first() if customer_id else None
        price_info = get_price_info(shop, customer, product, quantity)

        supplier = None
        if supplier_id:
            supplier = shop_product.suppliers.enabled().filter(id=supplier_id).first()

        if not supplier:
            supplier = shop_product.get_supplier(customer, quantity)

        stock_status = supplier.get_stock_status(product.pk) if supplier else None
        return {
            "id": product.id,
            "sku": product.sku,
            "name": product.name,
            "quantity": quantity,
            "logicalCount": stock_status.logical_count if stock_status else 0,
            "physicalCount": stock_status.physical_count if stock_status else 0,
            "salesDecimals": product.sales_unit.decimals if product.sales_unit else 0,
            "salesUnit": product.sales_unit.symbol if product.sales_unit else "",
            "purchaseMultiple": shop_product.purchase_multiple,
            "taxClass": {
                "id": product.tax_class.id,
                "name": force_text(product.tax_class),
            },
            "baseUnitPrice": {
                "value": price_info.base_unit_price.value,
                "includesTax": price_info.base_unit_price.includes_tax
            },
            "unitPrice": {
                "value": price_info.discounted_unit_price.value,
                "includesTax": price_info.base_unit_price.includes_tax
            },
            "product": {
                "text": product.name,
                "id": product.id,
                "url": get_model_url(product, shop=request.shop)
            }
        }
开发者ID:ruqaiya,项目名称:shuup,代码行数:60,代码来源:edit.py

示例9: _get_children_items

 def _get_children_items(self, children):
     for child in children:
         yield DropdownItem(
             text=_("Child: %s") % child,
             icon="fa fa-eye",
             url=get_model_url(child),
         )
开发者ID:ahmadzai,项目名称:shuup,代码行数:7,代码来源:toolbars.py

示例10: get_breadcrumb_parents

 def get_breadcrumb_parents(self):
     return [
         MenuEntry(
             text="%s" % self.object,
             url=get_model_url(self.object, shop=self.request.shop)
         )
     ]
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:edit_media.py

示例11: render_text

    def render_text(self, obj):
        url = getattr(obj, "url", None)
        text = ""
        if obj:
            text = force_text(obj)
            self.empty_text = False
            if not url:
                try:
                    url = get_model_url(obj)
                except NoModelUrl:
                    pass

        if not url:
            url = "#"

        css_style = ""

        if self.empty_text or not text:
            css_style = "display: none"

        icon = "<i class='%s'></i>" % self.external_icon

        return mark_safe(
            ("<a class=\"btn btn-inverse browse-text btn-sm\" style=\"%(css_style)s\" \
            href=\"%(url)s\" target=\"_blank\">%(icon)s %(text)s</a>") % {
                "css_style": css_style,
                "icon": icon,
                "text": escape(text),
                "url": escape(url),
            })
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:widgets.py

示例12: save_form_parts

    def save_form_parts(self, form):
        is_new = (not self.object.pk)
        form_parts = self.get_form_parts(self.object)
        for form_part in form_parts:
            retval = form_part.form_valid(form)

            if retval is not None:  # Allow a form part to change the identity of the object
                self.object = retval
                for form_part in form_parts:
                    form_part.object = self.object
        if is_new:
            object_created.send(sender=type(self.object), object=self.object)

        self._add_create_or_change_message(self.request, self.object, is_new)

        if self.request.GET.get("redirect") and not self.request.POST.get("__next"):
            return HttpResponseRedirect(self.request.GET.get("redirect"))

        if hasattr(self, "get_success_url"):
            return HttpResponseRedirect(self.get_success_url())

        if is_new:
            return HttpResponseRedirect(get_model_url(self.object, shop=self.request.shop))
        else:
            return HttpResponseRedirect(self.request.path)
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:form_part.py

示例13: get_toolbar

 def get_toolbar(self):
     toolbar = get_default_edit_toolbar(
         self,
         "change_password_form",
         discard_url=get_model_url(self.object),
         with_split_save=False
     )
     return toolbar
开发者ID:NamiStudio,项目名称:shuup,代码行数:8,代码来源:password.py

示例14: check_for_delete

def check_for_delete(view, request, object):
    can_delete = object.can_delete()
    delete_url = get_model_url(object, "delete")
    response = view(request, pk=object.pk)
    if hasattr(response, "render"):
        response.render()
    assert response.status_code in [200, 302]
    assert bool(delete_url in force_text(response.content)) == can_delete
开发者ID:NamiStudio,项目名称:shuup,代码行数:8,代码来源:test_services.py

示例15: get_toolbar

 def get_toolbar(self):
     toolbar = get_default_edit_toolbar(
         self,
         self.get_save_form_id(),
         discard_url=(get_model_url(self.object) if self.object.pk else None)
     )
     # TODO: Add extensibility
     return toolbar
开发者ID:ahmadzai,项目名称:shuup,代码行数:8,代码来源:edit.py


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