Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use list comprehension for ajax variants list

Anna Siwik81ea4ff78969
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 3cc3d9635e..72bd9f2e05 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -13,9 +13,11 @@ from payments import PaymentStatus
from prices import Price
from .forms import (
- CancelGroupForm, CancelLinesForm, CancelOrderForm, CapturePaymentForm,
- ChangeStockForm, ChangeQuantityForm, MoveLinesForm, OrderNoteForm,
- RefundPaymentForm, ReleasePaymentForm, RemoveVoucherForm, ShipGroupForm)
+ AddDeliveryGroupItemForm, CancelGroupForm, CancelLinesForm,
+ CancelOrderForm, CapturePaymentForm, ChangeStockForm, ChangeQuantityForm,
+ MoveLinesForm, OrderNoteForm, RefundPaymentForm, ReleasePaymentForm,
+ RemoveVoucherForm, ShipGroupForm)
+
from .utils import (create_packing_slip_pdf, create_invoice_pdf,
get_statics_absolute_url)
from ..order.forms import OrderFilterForm
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 67ce66b562..a35180d8ac 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -672,6 +672,12 @@ def product_bulk_update(request):
@staff_member_required
def ajax_variants_list(request):
+ def get_variant_label(variant):
+ return {
+ 'id': variant.id,
+ 'text': '%s, %s' % (
+ variant.display_product(), gross(variant.product.price))}
+
queryset = ProductVariant.objects.prefetch_related('product')
search_query = request.GET.get('q', '')
if search_query:
@@ -681,11 +687,6 @@ def ajax_variants_list(request):
Q(price_override__icontains=search_query) |
Q(product__name__icontains=search_query) |
Q(product__price__icontains=search_query))
- variants = []
- for variant in queryset:
- variants.append({
- 'id': variant.id,
- 'text': '%s, %s' % (
- variant.display_product(), gross(variant.product.price))})
+ variants = [get_variant_label(variant) for variant in queryset]
results = {'results': variants}
return JsonResponse(results)