本文整理汇总了Python中shoop.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 = Product()
p.pk = 3
assert get_model_url(p)
示例2: _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),
)
示例3: 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)
)
try:
shipment = order.create_shipment(
supplier=form.cleaned_data["supplier"],
product_quantities=products_to_quantities
)
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))
示例4: _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),
)
示例5: get_breadcrumb_parents
def get_breadcrumb_parents(self):
return [
MenuEntry(
text=self.object,
url=get_model_url(self.object)
)
]
示例6: 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
示例7: 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
示例8: 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
示例9: get_toolbar
def get_toolbar(self):
try:
new_url = get_model_url(self.model, kind="new")
except NoModelUrl:
new_url = None
if new_url:
return Toolbar([NewActionButton(new_url)])
示例10: get_search_results
def get_search_results(self, request, query):
minimum_query_length = 3
if len(query) >= minimum_query_length:
users = get_user_model().objects.filter(Q(username__icontains=query) | Q(email=query))
for i, user in enumerate(users[:10]):
relevance = 100 - i
yield SearchResult(
text=six.text_type(user), url=get_model_url(user), category=self.category, relevance=relevance
)
示例11: test_product_module_search
def test_product_module_search(rf, admin_user):
get_default_shop()
request = apply_request_middleware(rf.get("/"), user=admin_user)
with replace_modules([ProductModule]):
with admin_only_urls():
default_product = get_default_product()
model_url = get_model_url(default_product)
sku = default_product.sku
assert any(sr.url == model_url for sr in get_search_results(request, query=sku)) # Queries work
assert any(sr.is_action for sr in get_search_results(request, query=sku[:5])) # Actions work
assert empty_iterable(get_search_results(request, query=sku[:2])) # Short queries don't
示例12: post
def post(self, request, *args, **kwargs):
order = self.object = self.get_object()
new_status = OrderStatus.objects.get(pk=int(request.POST["status"]))
if new_status.role == OrderStatusRole.COMPLETE and not order.can_set_complete():
raise Problem(_("Unable to set order as completed at this point"))
old_status = order.status
order.status = new_status
order.save(update_fields=("status",))
message = _("Order status changed: %s \u2192 %s") % (old_status, new_status)
order.add_log_entry(message, user=request.user, identifier="status_change")
messages.success(self.request, message)
return HttpResponseRedirect(get_model_url(self.get_object()))
示例13: form_valid
def form_valid(self, form):
order = self.object
amount = Money(form.cleaned_data["amount"], order.currency)
if amount.value == 0:
messages.error(self.request, _("Payment amount cannot be 0"))
return self.form_invalid(form)
try:
payment = order.create_payment(amount, description="Manual payment")
messages.success(self.request, _("Payment %s created.") % payment.payment_identifier)
except NoPaymentToCreateException:
messages.error(self.request, _("Order has already been paid"))
return self.form_invalid(form)
else:
return HttpResponseRedirect(get_model_url(order))
示例14: get_search_results
def get_search_results(self, request, query):
minimum_query_length = 3
if len(query) >= minimum_query_length:
categories = Category.objects.filter(
Q(translations__name__icontains=query) |
Q(identifier__icontains=query)
).distinct().order_by("tree_id", "lft")
for i, category in enumerate(categories[:10]):
relevance = 100 - i
yield SearchResult(
text=six.text_type(category),
url=get_model_url(category),
category=self.category,
relevance=relevance
)
示例15: get_search_results
def get_search_results(self, request, query):
minimum_query_length = 3
if len(query) >= minimum_query_length:
orders = Order.objects.filter(
Q(identifier__istartswith=query)
| Q(reference_number__istartswith=query)
| Q(email__icontains=query)
| Q(phone__icontains=query)
).order_by("-id")[:15]
for i, order in enumerate(orders):
relevance = 100 - i
yield SearchResult(
text=six.text_type(order), url=get_model_url(order), category=_("Orders"), relevance=relevance
)