Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Code style improvements
Adam Janik45591144b339
diff --git a/saleor/dashboard/urls.py b/saleor/dashboard/urls.pyindex 50634bc99a..ebb016202e 100644--- a/saleor/dashboard/urls.py+++ b/saleor/dashboard/urls.py@@ -33,5 +33,4 @@ urlpatterns = [url(r'^shipping/', include(shipping_urls)),url(r'^style-guide/', core_views.styleguide, name='styleguide'),url(r'^search/', include(search_urls)),- url(r'^taxes/', include(taxes_urls)),- url(r'^next/', TemplateView.as_view(template_name='dashboard/next.html'))]+ url(r'^taxes/', include(taxes_urls))]diff --git a/saleor/graphql/account/fields.py b/saleor/graphql/account/fields.pyindex 2bf0496630..fc476b5d4d 100644--- a/saleor/graphql/account/fields.py+++ b/saleor/graphql/account/fields.py@@ -3,6 +3,7 @@ from graphene_django.converter import convert_django_fieldfrom ...account.models import PossiblePhoneNumberField+@convert_django_field.register(PossiblePhoneNumberField)def convert_json_field_to_string(field, registry=None):return graphene.String()diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.pyindex 90526825a1..b879191fab 100644--- a/saleor/graphql/account/resolvers.py+++ b/saleor/graphql/account/resolvers.py@@ -1,11 +1,10 @@from django.contrib.auth import models as auth_models-from graphql_jwt.decorators import staff_member_required, permission_required+from graphql_jwt.decorators import permission_required, staff_member_requiredfrom ...account import modelsfrom ..utils import filter_by_query_param, get_nodefrom .types import User-USER_SEARCH_FIELDS = ('email', 'default_shipping_address__first_name','default_shipping_address__last_name', 'default_shipping_address__city',diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.pyindex 874f3c2327..af0d81a369 100644--- a/saleor/graphql/account/types.py+++ b/saleor/graphql/account/types.py@@ -1,6 +1,5 @@import graphene-from django.contrib.auth import get_user_model-from django.contrib.auth import models as auth_models+from django.contrib.auth import get_user_model, models as auth_modelsfrom graphene import relayfrom graphene_django.fields import DjangoConnectionFielddiff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 2caa539f35..4d779c2758 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -33,7 +33,7 @@ from .order.mutations.draft_orders import (DraftOrderComplete, DraftOrderCreate, DraftOrderDelete, DraftOrderUpdate)from .order.mutations.fulfillments import (FulfillmentCancel, FulfillmentCreate, FulfillmentUpdate)-from .order.mutations.orders import (+from .order.mutations.orders import (OrderAddNote, OrderCancel, OrderCapture, OrderMarkAsPaid, OrderRefund,OrderRelease, OrderUpdate)from .page.resolvers import resolve_pages, resolve_pagediff --git a/saleor/graphql/core/connection.py b/saleor/graphql/core/connection.pyindex 0a16816cef..db73f20012 100644--- a/saleor/graphql/core/connection.py+++ b/saleor/graphql/core/connection.py@@ -1,6 +1,6 @@import graphene-from graphene import Field, ObjectType, String, NonNull, List-from graphene.relay.connection import ConnectionOptions, Connection+from graphene import Field, List, NonNull, ObjectType, String+from graphene.relay.connection import Connection, ConnectionOptionsclass NonNullConnection(Connection):@@ -12,7 +12,7 @@ class NonNullConnection(Connection):def __init_subclass_with_meta__(cls, node=None, name=None, **options):super().__init_subclass_with_meta__(node=node, name=name, **options)- # Override the original EdgeBase type to make to `node`` field required.+ # Override the original EdgeBase type to make to `node` field required.class EdgeBase(object):node = Field(cls._meta.node, description='The item at the end of the edge',@@ -26,7 +26,8 @@ class NonNullConnection(Connection):edge = type(edge_name, edge_bases, {})cls.Edge = edge- # Override the `edges` field to make it non-null list of non-null edges.+ # Override the `edges` field to make it non-null list+ # of non-null edges.cls._meta.fields['edges'] = Field(NonNull(List(NonNull(cls.Edge))))diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex 6aa94458de..2a92e5c0b4 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -55,7 +55,8 @@ class ModelMutation(BaseMutation):@classmethoddef __init_subclass_with_meta__(- cls, arguments=None, model=None, exclude=None, _meta=None, **options):+ cls, arguments=None, model=None, exclude=None, _meta=None,+ **options):if not model:raise ImproperlyConfigured('model is required for ModelMutation')if not _meta:@@ -116,10 +117,13 @@ class ModelMutation(BaseMutation):if field_name in input:value = input[field_name]# FIXME: maybe we could have custom input field type that takes- # the type of IDs e.g. graphene.IdList(graphene.ID, type=Product).+ # the type of IDs+ # e.g. graphene.IdList(graphene.ID, type=Product).# handle list of IDs field- if value is not None and isinstance(field.type, graphene.List) and field.type.of_type == graphene.ID:+ if value is not None and isinstance(+ field.type, graphene.List) and (+ field.type.of_type == graphene.ID):instances = get_nodes(value) if value else []cleaned_input[field_name] = instances@@ -151,7 +155,8 @@ class ModelMutation(BaseMutation):opts = instance._metafor f in opts.fields:- if not f.editable or isinstance(f, models.AutoField) or f.name not in cleaned_data:+ if not f.editable or isinstance(+ f, models.AutoField) or f.name not in cleaned_data:continueelse:f.save_form_data(instance, cleaned_data[f.name])diff --git a/saleor/graphql/descriptions.py b/saleor/graphql/descriptions.pyindex 2866c60afa..c645ffd959 100644--- a/saleor/graphql/descriptions.py+++ b/saleor/graphql/descriptions.py@@ -1,4 +1,4 @@-from .account.resolvers import USER_SEARCH_FIELDS, GROUP_SEARCH_FIELDS+from .account.resolvers import GROUP_SEARCH_FIELDS, USER_SEARCH_FIELDSfrom .discount.resolvers import SALE_SEARCH_FIELDS, VOUCHER_SEARCH_FIELDSfrom .menu.resolvers import MENU_ITEM_SEARCH_FIELDS, MENU_SEARCH_FIELDSfrom .order.resolvers import ORDER_SEARCH_FIELDS@@ -8,7 +8,6 @@ from .product.resolvers import (PRODUCT_SEARCH_FIELDS)from .utils import generate_query_argument_description-DESCRIPTIONS = {'attributes': generate_query_argument_description(ATTRIBUTES_SEARCH_FIELDS),diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.pyindex 9adb010ef5..ece6812a26 100644--- a/saleor/graphql/menu/mutations.py+++ b/saleor/graphql/menu/mutations.py@@ -71,7 +71,7 @@ class MenuItemCreate(ModelMutation):input = MenuItemInput(required=True,description="""Fields required to update a menu item.- Only one of 'url', 'category', 'page', 'collection' is allowed+ Only one of 'url', 'category', 'page', 'collection' is allowedper item""")class Meta:@@ -103,7 +103,7 @@ class MenuItemUpdate(MenuItemCreate):input = MenuItemInput(required=True,description="""Fields required to update a menu item.- Only one of 'url', 'category', 'page', 'collection' is allowed+ Only one of 'url', 'category', 'page', 'collection' is allowedper item""")class Meta:diff --git a/saleor/graphql/menu/resolvers.py b/saleor/graphql/menu/resolvers.pyindex 8837a4feb3..f177ecc0dd 100644--- a/saleor/graphql/menu/resolvers.py+++ b/saleor/graphql/menu/resolvers.py@@ -4,6 +4,7 @@ from ..utils import filter_by_query_paramMENU_SEARCH_FIELDS = ('name',)MENU_ITEM_SEARCH_FIELDS = ('name',)+def resolve_menus(info, query):queryset = models.Menu.objects.all()queryset = filter_by_query_param(queryset, query, MENU_SEARCH_FIELDS)diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.pyindex 9088c3971b..a90cc2e273 100644--- a/saleor/graphql/menu/types.py+++ b/saleor/graphql/menu/types.py@@ -16,6 +16,7 @@ class Menu(CountableDjangoObjectType):class MenuItem(CountableDjangoObjectType):url = graphene.String(description='URL to the menu item.')+class Meta:description = """Represents a single item of the related menu.Can store categories, collection or pages."""diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.pyindex ab191fc49f..0e54b2b218 100644--- a/saleor/graphql/middleware.py+++ b/saleor/graphql/middleware.py@@ -4,10 +4,12 @@ from graphql_jwt.middleware import JSONWebTokenMiddlewaredef jwt_middleware(get_response):- """Authenticate user using JSONWebTokenMiddleware ignoring the session-based authentication.+ """Authenticate user using JSONWebTokenMiddleware+ ignoring the session-based authentication.This middleware resets authentication made by any previous middlewares- and authenticates the user with graphql_jwt.middleware.JSONWebTokenMiddleware.+ and authenticates the user+ with graphql_jwt.middleware.JSONWebTokenMiddleware."""jwt_middleware = JSONWebTokenMiddleware(get_response=get_response)diff --git a/saleor/graphql/order/filters.py b/saleor/graphql/order/filters.pyindex 0753ceb4b0..162cfaa4c1 100644--- a/saleor/graphql/order/filters.py+++ b/saleor/graphql/order/filters.py@@ -1,5 +1,5 @@from django.db.models import Q-from django_filters import (CharFilter, NumberFilter)+from django_filters import CharFilter, NumberFilterfrom graphene_django.filter.filterset import GlobalIDMultipleChoiceFilterfrom ...order import modelsdiff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex acb8dd7958..e10d678213 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -45,7 +45,7 @@ class DraftOrderInput(InputObjectType):discount = Decimal(description='Discount amount for the order.')lines = graphene.List(OrderLineInput,- description="""Variant line input consisting of variant ID+ description="""Variant line input consisting of variant IDand quantity of products.""")shipping_address = AddressInput(description='Shipping address of the customer.')@@ -125,7 +125,6 @@ class DraftOrderCreate(ModelMutation):return cleaned_input-@classmethoddef user_is_allowed(cls, user, input):return user.has_perm('order.edit_order')diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex ee2f76aea4..89bf5c5bf1 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -2,6 +2,7 @@ import graphenefrom django.utils.translation import npgettext_lazy, pgettext_lazyfrom graphql_jwt.decorators import permission_required+from ....dashboard.order.utils import fulfill_order_linefrom ....graphql.core.mutations import BaseMutation, ModelMutationfrom ....graphql.core.types import Errorfrom ....graphql.order.types import Fulfillment@@ -9,7 +10,6 @@ from ....graphql.utils import get_node, get_nodesfrom ....order import modelsfrom ....order.emails import send_fulfillment_confirmationfrom ....order.utils import cancel_fulfillment, update_order_status-from ....dashboard.order.utils import fulfill_order_linefrom ..types import OrderLine@@ -120,7 +120,7 @@ class FulfillmentCreate(ModelMutation):'Fulfilled %(quantity_fulfilled)d item','Fulfilled %(quantity_fulfilled)d items','quantity_fulfilled') % {- 'quantity_fulfilled': quantity_fulfilled}+ 'quantity_fulfilled': quantity_fulfilled}order.history.create(content=msg, user=info.context.user)super().save(info, instance, cleaned_input)@@ -158,7 +158,6 @@ class FulfillmentCancel(BaseMutation):description = """Cancels existing fulfillmentand optionally restocks items."""-fulfillment = graphene.Field(Fulfillment, description='A canceled fulfillment.')diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.pyindex a3884300bc..e7aa64ccec 100644--- a/saleor/graphql/order/resolvers.py+++ b/saleor/graphql/order/resolvers.py@@ -13,7 +13,7 @@ def resolve_orders(info, query):user = info.context.userqueryset = user.orders.confirmed().distinct()if user.get_all_permissions() & {'order.view_order', 'order.edit_order'}:- queryset = models.Order.objects.all().distinct()+ queryset = models.Order.objects.all().distinct()queryset = filter_by_query_param(queryset, query, ORDER_SEARCH_FIELDS)return queryset.prefetch_related('lines')diff --git a/saleor/graphql/page/resolvers.py b/saleor/graphql/page/resolvers.pyindex e43d0ac685..23f9d7418d 100644--- a/saleor/graphql/page/resolvers.py+++ b/saleor/graphql/page/resolvers.py@@ -2,7 +2,6 @@ from ...page import modelsfrom ..utils import filter_by_query_param, get_nodefrom .types import Page-PAGE_SEARCH_FIELDS = ('content', 'slug', 'title')diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 1cfb35038b..54df580974 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -320,7 +320,8 @@ class ProductVariantCreate(ModelMutation):# the value's PK.attributes = cleaned_input.pop('attributes', [])- product = instance.product if instance.pk else cleaned_input.get('product')+ product = instance.product if instance.pk else cleaned_input.get(+ 'product')product_type = product.product_typeif attributes and product_type:diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 37eae33d06..9617f8f18f 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -21,15 +21,15 @@ def resolve_attribute_list(attributes):attributes_map = {att.pk: att for att in models.ProductAttribute.objects.filter(- pk__in=keys)}+ pk__in=keys)}values_map = {val.pk: val for val in models.AttributeChoiceValue.objects.filter(- pk__in=values)}+ pk__in=values)}attributes_list = [SelectedAttribute(attribute=attributes_map.get(int(k)),value=values_map.get(int(v)))- for k,v in attributes.items()]+ for k, v in attributes.items()]return attributes_list@@ -70,9 +70,11 @@ class Margin(graphene.ObjectType):class SelectedAttribute(graphene.ObjectType):- attribute = graphene.Field(ProductAttribute,+ attribute = graphene.Field(+ ProductAttribute,default_value=None, description='Name of an attribute')- value = graphene.Field(ProductAttributeValue,+ value = graphene.Field(+ ProductAttributeValue,default_value=None, description='Value of an attribute.')class Meta:@@ -211,7 +213,6 @@ class Collection(CountableDjangoObjectType):interfaces = [relay.Node]model = models.Collection-def resolve_products(self, info, **kwargs):user = info.context.userreturn products_visible_to_user(diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.pyindex 450b489b49..be8234ef84 100644--- a/saleor/graphql/utils.py+++ b/saleor/graphql/utils.py@@ -8,7 +8,6 @@ from graphql_relay import from_global_idfrom ..product.models import AttributeChoiceValue, ProductAttributefrom .core.types import PermissionDisplay-registry = get_global_registry()@@ -110,7 +109,7 @@ def filter_by_query_param(queryset, query, search_fields):field, 'icontains'): query for field in search_fields}query_objects = Q()for q in query_by:- query_objects |= Q(**{q:query_by[q]})+ query_objects |= Q(**{q: query_by[q]})return queryset.filter(query_objects)return querysetdiff --git a/saleor/settings.py b/saleor/settings.pyindex 4db9aa6b8e..878efb35f7 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -6,7 +6,6 @@ import dj_email_urlimport django_cache_urlfrom django.contrib.messages import constants as messagesfrom django.utils.translation import gettext_lazy as _, pgettext_lazy-from django_prices.templatetags.prices_i18n import get_currency_fractionfrom . import __version__@@ -180,7 +179,7 @@ MIDDLEWARE = ['saleor.core.middleware.taxes','social_django.middleware.SocialAuthExceptionMiddleware','impersonate.middleware.ImpersonateMiddleware',- # 'saleor.graphql.middleware.jwt_middleware'+ 'saleor.graphql.middleware.jwt_middleware']INSTALLED_APPS = [