Skip to content

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

Added pydocstyle to pre-commit and tox

NyanKiyoshib0334726d4e1
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index bd6eb59e40..876c1b6303 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -21,3 +21,8 @@ repos:
rev: v4.3.21
hooks:
- id: isort
+
+- repo: https://github.com/pycqa/pydocstyle
+ rev: 4.0.0
+ hooks:
+ - id: pydocstyle
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff3fb5a6fe..deb6b0b9dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Update JSON menu representation in mutations - #4524 by @maarcingebala
- Display menu item form errors - #4551 by @dominik-zeglen
- Add voucher settings - #4556 by @benekex2
+- Enforced pydocstyle for Python docstrings over the project - #4562 by @NyanKiyoshi
## 2.8.0
diff --git a/saleor/account/migrations/0001_initial.py b/saleor/account/migrations/0001_initial.py
index 0050d26e3b..8345eaf6ac 100644
--- a/saleor/account/migrations/0001_initial.py
+++ b/saleor/account/migrations/0001_initial.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
-import django.utils.timezone
import django.db.models.deletion
+import django.utils.timezone
+from django.db import migrations, models
class Migration(migrations.Migration):
@@ -29,7 +29,10 @@ class Migration(migrations.Migration):
"is_superuser",
models.BooleanField(
default=False,
- help_text="Designates that this user has all permissions without explicitly assigning them.",
+ help_text=(
+ "Designates that this user has all permissions "
+ "without explicitly assigning them."
+ ),
verbose_name="superuser status",
),
),
@@ -419,7 +422,10 @@ class Migration(migrations.Migration):
related_name="user_set",
to="auth.Group",
blank=True,
- help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
+ help_text=(
+ "The groups this user belongs to. "
+ "A user will get all permissions granted to each of their groups."
+ ),
verbose_name="groups",
),
),
diff --git a/saleor/account/migrations/0002_auto_20150907_0602.py b/saleor/account/migrations/0002_auto_20150907_0602.py
index 7b7164b012..213150e51e 100644
--- a/saleor/account/migrations/0002_auto_20150907_0602.py
+++ b/saleor/account/migrations/0002_auto_20150907_0602.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/account/migrations/0003_auto_20151104_1102.py b/saleor/account/migrations/0003_auto_20151104_1102.py
index f8ff8ef1db..2920381e36 100644
--- a/saleor/account/migrations/0003_auto_20151104_1102.py
+++ b/saleor/account/migrations/0003_auto_20151104_1102.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/account/migrations/0004_auto_20160114_0419.py b/saleor/account/migrations/0004_auto_20160114_0419.py
index 528bdc2141..6745ef09e9 100644
--- a/saleor/account/migrations/0004_auto_20160114_0419.py
+++ b/saleor/account/migrations/0004_auto_20160114_0419.py
@@ -2,8 +2,8 @@
# Generated by Django 1.9.1 on 2016-01-14 10:19
from __future__ import unicode_literals
-from django.db import migrations
import django_countries.fields
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/account/migrations/0013_auto_20171120_0521.py b/saleor/account/migrations/0013_auto_20171120_0521.py
index 4e3be8a5fe..c8dac4ea97 100644
--- a/saleor/account/migrations/0013_auto_20171120_0521.py
+++ b/saleor/account/migrations/0013_auto_20171120_0521.py
@@ -2,10 +2,10 @@
# Generated by Django 1.11.5 on 2017-11-20 11:21
from __future__ import unicode_literals
-from django.db import migrations
-from phonenumbers.phonenumberutil import NumberParseException
import phonenumber_field.modelfields
import phonenumbers
+from django.db import migrations
+from phonenumbers.phonenumberutil import NumberParseException
def convert_phone_number_to_phonenumberfield(apps, schema_editor):
diff --git a/saleor/account/migrations/0015_auto_20171213_0734.py b/saleor/account/migrations/0015_auto_20171213_0734.py
index f6b584ad09..d17df20b42 100644
--- a/saleor/account/migrations/0015_auto_20171213_0734.py
+++ b/saleor/account/migrations/0015_auto_20171213_0734.py
@@ -3,6 +3,7 @@
from __future__ import unicode_literals
from django.db import migrations
+
import saleor.account.models
diff --git a/saleor/account/migrations/0016_auto_20180108_0814.py b/saleor/account/migrations/0016_auto_20180108_0814.py
index 693d69e816..53b6b17369 100644
--- a/saleor/account/migrations/0016_auto_20180108_0814.py
+++ b/saleor/account/migrations/0016_auto_20180108_0814.py
@@ -2,10 +2,11 @@
# Generated by Django 1.11.5 on 2018-01-08 14:14
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import django_countries.fields
+from django.db import migrations, models
+
import saleor.account.models
diff --git a/saleor/account/migrations/0018_auto_20180426_0641.py b/saleor/account/migrations/0018_auto_20180426_0641.py
index d9a1706e6e..1e5de1081a 100644
--- a/saleor/account/migrations/0018_auto_20180426_0641.py
+++ b/saleor/account/migrations/0018_auto_20180426_0641.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.3 on 2018-04-26 11:41
+import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
class Migration(migrations.Migration):
diff --git a/saleor/account/migrations/0020_user_token.py b/saleor/account/migrations/0020_user_token.py
index c62f04f9d8..050db66303 100644
--- a/saleor/account/migrations/0020_user_token.py
+++ b/saleor/account/migrations/0020_user_token.py
@@ -1,6 +1,7 @@
# Generated by Django 2.0.3 on 2018-05-30 12:26
from django.db import migrations, models
+
import saleor.account.models
diff --git a/saleor/account/migrations/0026_user_avatar.py b/saleor/account/migrations/0026_user_avatar.py
index a9e4c6e536..a4654849d4 100644
--- a/saleor/account/migrations/0026_user_avatar.py
+++ b/saleor/account/migrations/0026_user_avatar.py
@@ -1,7 +1,7 @@
# Generated by Django 2.1.7 on 2019-03-25 09:40
-from django.db import migrations
import versatileimagefield.fields
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/account/migrations/0028_user_private_meta.py b/saleor/account/migrations/0028_user_private_meta.py
index 8f447ed348..4c9212394e 100644
--- a/saleor/account/migrations/0028_user_private_meta.py
+++ b/saleor/account/migrations/0028_user_private_meta.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/account/migrations/0029_user_meta.py b/saleor/account/migrations/0029_user_meta.py
index ea3a8128e4..8d318f4490 100644
--- a/saleor/account/migrations/0029_user_meta.py
+++ b/saleor/account/migrations/0029_user_meta.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/account/migrations/0030_auto_20190719_0733.py b/saleor/account/migrations/0030_auto_20190719_0733.py
index 99b1e24472..d1ccbaa82d 100644
--- a/saleor/account/migrations/0030_auto_20190719_0733.py
+++ b/saleor/account/migrations/0030_auto_20190719_0733.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/account/migrations/0031_auto_20190719_0745.py b/saleor/account/migrations/0031_auto_20190719_0745.py
index efc1ce6c12..25b9666d1c 100644
--- a/saleor/account/migrations/0031_auto_20190719_0745.py
+++ b/saleor/account/migrations/0031_auto_20190719_0745.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/account/thumbnails.py b/saleor/account/thumbnails.py
index c220b52c6d..41d97d12d6 100644
--- a/saleor/account/thumbnails.py
+++ b/saleor/account/thumbnails.py
@@ -5,7 +5,7 @@ from .models import User
@app.task
def create_user_avatar_thumbnails(user_id):
- """Creates thumbnails for user avatar."""
+ """Create thumbnails for user avatar."""
create_thumbnails(
pk=user_id, model=User, size_set="user_avatars", image_attr="avatar"
)
diff --git a/saleor/account/utils.py b/saleor/account/utils.py
index ec9782724a..9541f731f9 100644
--- a/saleor/account/utils.py
+++ b/saleor/account/utils.py
@@ -46,8 +46,10 @@ def change_user_default_address(user, address, address_type):
def get_user_first_name(user):
- """Return user first name if not exist return first name from
- default billing address or None."""
+ """Return a user's first name from their default belling address.
+
+ Return nothing if none where found.
+ """
if user.first_name:
return user.first_name
if user.default_billing_address:
@@ -56,8 +58,10 @@ def get_user_first_name(user):
def get_user_last_name(user):
- """Return user last name if not exist return first name from
- default billing address or None."""
+ """Return a user's last name from their default belling address.
+
+ Return nothing if none where found.
+ """
if user.last_name:
return user.last_name
if user.default_billing_address:
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.py
index 3eca7e888e..bccd856825 100644
--- a/saleor/checkout/forms.py
+++ b/saleor/checkout/forms.py
@@ -200,9 +200,7 @@ class CountryForm(forms.Form):
)
def get_shipping_price_estimate(self, checkout, discounts):
- """Return a shipping price range for given order for the selected
- country.
- """
+ """Return a shipping price range for given order for the selected country."""
from .utils import get_shipping_price_estimate
country = self.cleaned_data["country"]
diff --git a/saleor/checkout/migrations/0001_auto_20170113_0435.py b/saleor/checkout/migrations/0001_auto_20170113_0435.py
index 226a92314b..128d5ad580 100644
--- a/saleor/checkout/migrations/0001_auto_20170113_0435.py
+++ b/saleor/checkout/migrations/0001_auto_20170113_0435.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.3 on 2017-01-13 10:35
from __future__ import unicode_literals
-from django.db import migrations
from django.contrib.postgres import fields
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0001_initial.py b/saleor/checkout/migrations/0001_initial.py
index ebeea5ce16..840cfc2b51 100644
--- a/saleor/checkout/migrations/0001_initial.py
+++ b/saleor/checkout/migrations/0001_initial.py
@@ -3,10 +3,10 @@ from __future__ import unicode_literals
import uuid
-from django.db import models, migrations
-from django.conf import settings
import django.core.validators
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0002_auto_20170206_0407.py b/saleor/checkout/migrations/0002_auto_20170206_0407.py
index 351c83d6a5..7dcdda32a5 100644
--- a/saleor/checkout/migrations/0002_auto_20170206_0407.py
+++ b/saleor/checkout/migrations/0002_auto_20170206_0407.py
@@ -2,11 +2,11 @@
# Generated by Django 1.10.5 on 2017-02-06 10:07
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
from django.contrib.postgres import fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0005_auto_20180108_0814.py b/saleor/checkout/migrations/0005_auto_20180108_0814.py
index 3d79fee098..cf50530338 100644
--- a/saleor/checkout/migrations/0005_auto_20180108_0814.py
+++ b/saleor/checkout/migrations/0005_auto_20180108_0814.py
@@ -4,12 +4,12 @@ from __future__ import unicode_literals
import uuid
-from django.conf import settings
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
from django.contrib.postgres import fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0007_merge_cart_with_checkout.py b/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
index 5935d63d32..e330bf8d5a 100644
--- a/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
+++ b/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
@@ -1,9 +1,9 @@
# Generated by Django 2.0.3 on 2018-05-29 08:18
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
def fix_blank_emails_in_carts(apps, schema_editor):
diff --git a/saleor/checkout/migrations/0010_auto_20180822_0720.py b/saleor/checkout/migrations/0010_auto_20180822_0720.py
index b7d7814f30..c405b6a3d6 100644
--- a/saleor/checkout/migrations/0010_auto_20180822_0720.py
+++ b/saleor/checkout/migrations/0010_auto_20180822_0720.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.3 on 2018-08-22 12:20
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0011_auto_20180913_0817.py b/saleor/checkout/migrations/0011_auto_20180913_0817.py
index b86ad3485d..a5eb471793 100644
--- a/saleor/checkout/migrations/0011_auto_20180913_0817.py
+++ b/saleor/checkout/migrations/0011_auto_20180913_0817.py
@@ -1,8 +1,9 @@
# Generated by Django 2.0.8 on 2018-09-13 13:17
+import json
+
import django.contrib.postgres.fields.jsonb
from django.db import migrations
-import json
class Migration(migrations.Migration):
diff --git a/saleor/checkout/migrations/0020_auto_20190723_0722.py b/saleor/checkout/migrations/0020_auto_20190723_0722.py
index c9a8fbaa09..cc77c55ad3 100644
--- a/saleor/checkout/migrations/0020_auto_20190723_0722.py
+++ b/saleor/checkout/migrations/0020_auto_20190723_0722.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 33a325b592..604b505616 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -261,6 +261,7 @@ def get_user_checkout(
user: User, checkout_queryset=Checkout.objects.all(), auto_create=False
) -> Tuple[Optional[Checkout], bool]:
"""Return an active checkout for given user or None if no auto create.
+
If auto create is enabled, it will retrieve an active checkout or create it
(safer for concurrency).
"""
@@ -364,7 +365,7 @@ def update_checkout_quantity(checkout):
def check_variant_in_stock(
checkout, variant, quantity=1, replace=False, check_quantity=True
) -> Tuple[int, Optional[CheckoutLine]]:
- """Check if a given variant is in stock and return the new quantity + line"""
+ """Check if a given variant is in stock and return the new quantity + line."""
line = checkout.lines.filter(variant=variant).first()
line_quantity = 0 if line is None else line.quantity
@@ -414,7 +415,7 @@ def add_variant_to_checkout(
def get_shipping_address_forms(checkout, user_addresses, data, country):
- """Forms initialized with data depending on shipping address in checkout."""
+ """Retrieve a form initialized with data based on the checkout shipping address."""
shipping_address = (
checkout.shipping_address or checkout.user.default_shipping_address
)
@@ -567,7 +568,7 @@ def update_billing_address_in_checkout_with_shipping(
def get_anonymous_summary_without_shipping_forms(checkout, data, country):
- """Forms initialized with data depending on addresses in checkout."""
+ """Build a form initialized with data depending on addresses in checkout."""
billing_address = checkout.billing_address
if billing_address:
@@ -607,7 +608,7 @@ def update_billing_address_in_anonymous_checkout(checkout, data, country):
def get_summary_without_shipping_forms(checkout, user_addresses, data, country):
- """Forms initialized with data depending on addresses in checkout."""
+ """Build a forms initialized with data depending on addresses in checkout."""
billing_address = checkout.billing_address
if billing_address and billing_address in user_addresses:
@@ -727,7 +728,7 @@ def change_shipping_address_in_checkout(checkout, address):
def get_checkout_context(checkout, discounts, currency=None, shipping_range=None):
- """Data shared between views in checkout process."""
+ """Retrieve the data shared between views in checkout process."""
manager = get_extensions_manager()
checkout_total = (
manager.calculate_checkout_total(checkout=checkout, discounts=discounts)
@@ -796,8 +797,7 @@ def _get_shipping_voucher_discount_for_checkout(voucher, checkout, discounts=Non
def _get_products_voucher_discount(checkout, voucher, discounts=None):
- """Calculate products discount value for a voucher, depending on its type.
- """
+ """Calculate products discount value for a voucher, depending on its type."""
prices = None
if voucher.type == VoucherType.SPECIFIC_PRODUCT:
prices = get_prices_of_discounted_specific_product(checkout, voucher, discounts)
@@ -998,7 +998,7 @@ def is_valid_shipping_method(checkout, discounts):
def get_shipping_price_estimate(checkout: Checkout, discounts, country_code):
- """Returns estimated price range for shipping for given order."""
+ """Return the estimated price range for shipping for given order."""
shipping_methods = get_valid_shipping_methods_for_checkout(
checkout, discounts, country_code=country_code
@@ -1023,8 +1023,7 @@ def clear_shipping_method(checkout):
def _get_voucher_data_for_order(checkout):
- """
- Fetch, process and return voucher/discount data from checkout.
+ """Fetch, process and return voucher/discount data from checkout.
Careful! It should be called inside a transaction.
@@ -1105,8 +1104,9 @@ def validate_gift_cards(checkout: Checkout):
def create_line_for_order(checkout_line: "CheckoutLine", discounts) -> OrderLine:
- """
- :raises InsufficientStock: when there is not enough items in stock for this variant
+ """Create a line for the given order.
+
+ :raises InsufficientStock: when there is not enough items in stock for this variant.
"""
quantity = checkout_line.quantity
@@ -1139,8 +1139,7 @@ def create_line_for_order(checkout_line: "CheckoutLine", discounts) -> OrderLine
def prepare_order_data(*, checkout: Checkout, tracking_code: str, discounts) -> dict:
- """
- Runs checks and returns all the data from a given checkout to create an order.
+ """Run checks and return all the data from a given checkout to create an order.
:raises NotApplicable InsufficientStock:
"""
@@ -1246,7 +1245,9 @@ def create_order(*, checkout: Checkout, order_data: dict, user: User) -> Order:
def is_fully_paid(checkout: Checkout, discounts):
"""Check if provided payment methods cover the checkout's total amount.
- Note that these payments may not be captured or charged at all."""
+
+ Note that these payments may not be captured or charged at all.
+ """
payments = [payment for payment in checkout.payments.all() if payment.is_active]
total_paid = sum([p.total for p in payments])
manager = get_extensions_manager()
diff --git a/saleor/core/management/commands/populatedb.py b/saleor/core/management/commands/populatedb.py
index aed7c65553..ac7fa6cfdf 100644
--- a/saleor/core/management/commands/populatedb.py
+++ b/saleor/core/management/commands/populatedb.py
@@ -72,7 +72,7 @@ class Command(BaseCommand):
call_command("search_index", "--rebuild", force=True)
def sequence_reset(self):
- """Runs SQL sequence reset on all saleor.* apps.
+ """Run a SQL sequence reset on all saleor.* apps.
When a value is manually assigned to an auto-incrementing field
it doesn't update the field's sequence, which might cause a conflict
diff --git a/saleor/core/middleware.py b/saleor/core/middleware.py
index 4ee6b52564..d5e71853f7 100644
--- a/saleor/core/middleware.py
+++ b/saleor/core/middleware.py
@@ -96,7 +96,7 @@ def site(get_response):
def extensions(get_response):
- """Assign extensions manager"""
+ """Assign extensions manager."""
def _get_manager():
return get_extensions_manager(plugins=settings.PLUGINS)
diff --git a/saleor/core/taxes.py b/saleor/core/taxes.py
index 5e285d298e..79b8d3a1ff 100644
--- a/saleor/core/taxes.py
+++ b/saleor/core/taxes.py
@@ -9,11 +9,14 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
class TaxError(Exception):
- """Default tax error"""
+ """Default tax error."""
def zero_money(currency=settings.DEFAULT_CURRENCY):
- """Function used as a model's default."""
+ """Return a money object set to zero.
+
+ This is a function used as a model's default.
+ """
return Money(0, currency)
@@ -37,7 +40,7 @@ def charge_taxes_on_shipping():
def get_display_price(
base: Union[TaxedMoney, TaxedMoneyRange], display_gross=None
) -> Money:
- """Return price amount that should be displayed based on settings"""
+ """Return the price amount that should be displayed based on settings."""
if not display_gross:
display_gross = display_gross_prices()
if isinstance(base, TaxedMoneyRange):
@@ -61,7 +64,7 @@ def quantize_price(
@dataclass(frozen=True)
class TaxType:
- """Dataclass for unifying tax type object that comes from tax gateway"""
+ """Dataclass for unifying tax type object that comes from tax gateway."""
code: str
description: str
diff --git a/saleor/core/templatetags/attributes.py b/saleor/core/templatetags/attributes.py
index 71213fbb04..4055a08d78 100644
--- a/saleor/core/templatetags/attributes.py
+++ b/saleor/core/templatetags/attributes.py
@@ -5,7 +5,7 @@ register = Library()
@register.simple_tag
def get_object_properties(object, properties):
- """Returns first non empty property of given object."""
+ """Return first non empty property of given object."""
properties = properties.split(",")
for property in properties:
attribute = getattr(object, property, "")
diff --git a/saleor/core/utils/draftjs.py b/saleor/core/utils/draftjs.py
index bb1c5739fa..1aaec53ad9 100644
--- a/saleor/core/utils/draftjs.py
+++ b/saleor/core/utils/draftjs.py
@@ -2,7 +2,7 @@ from typing import Dict
def json_content_to_raw_text(content: Dict[str, dict], sep: str = "\n") -> str:
- """Converts DraftJS JSON content to plain text."""
+ """Convert DraftJS JSON content to plain text."""
if not isinstance(content, dict) or "blocks" not in content:
return ""
diff --git a/saleor/core/utils/json_serializer.py b/saleor/core/utils/json_serializer.py
index ed8d456d15..c726940d96 100644
--- a/saleor/core/utils/json_serializer.py
+++ b/saleor/core/utils/json_serializer.py
@@ -26,8 +26,11 @@ class CustomJsonEncoder(DjangoJSONEncoder):
class HTMLSafeJSON(SafeJSONEncoder, DjangoJSONEncoder):
- """Escapes dangerous characters for integrating JSON into HTML content
- and serializes Django objects."""
+ """Escape dangerous characters from JSON.
+
+ It is used for integrating JSON into HTML content in addition to
+ serializing Django objects.
+ """
def object_hook(obj):
@@ -37,9 +40,11 @@ def object_hook(obj):
def Deserializer(stream_or_string, **options):
- """Deserialize a stream or string of JSON data. This is a slightly modified
- copy of Django implementation with additional argument <object_hook> in
- json.loads"""
+ """Deserialize a stream or string of JSON data.
+
+ This is a slightly modified copy of Django implementation with additional
+ argument <object_hook> in json.loads.
+ """
if not isinstance(stream_or_string, (bytes, str)):
stream_or_string = stream_or_string.read()
if isinstance(stream_or_string, bytes):
diff --git a/saleor/core/utils/text.py b/saleor/core/utils/text.py
index 2c0bc018c7..d392096932 100644
--- a/saleor/core/utils/text.py
+++ b/saleor/core/utils/text.py
@@ -6,23 +6,24 @@ from html5lib.serializer import HTMLSerializer
def get_cleaner(**serializer_kwargs: bool):
- """
+ """Build a bleach cleaner from the passed parameters.
+
:param serializer_kwargs:
- options:
- - alphabetical_attributes
- - escape_lt_in_attrs
- - escape_rcdata
- - inject_meta_charset
- - minimize_boolean_attributes
- - omit_optional_tags
- - quote_attr_values
- - quote_char
- - resolve_entities
- - sanitize
- - space_before_trailing_solidus
- - strip_whitespace
- - use_best_quote_char
- - use_trailing_solidus
+ options:
+ - alphabetical_attributes
+ - escape_lt_in_attrs
+ - escape_rcdata
+ - inject_meta_charset
+ - minimize_boolean_attributes
+ - omit_optional_tags
+ - quote_attr_values
+ - quote_char
+ - resolve_entities
+ - sanitize
+ - space_before_trailing_solidus
+ - strip_whitespace
+ - use_best_quote_char
+ - use_trailing_solidus
:type serializer_kwargs: Dict[str, bool]
:rtype: bleach.Cleaner
@@ -38,7 +39,8 @@ def get_cleaner(**serializer_kwargs: bool):
def strip_html(text: str, **serializer_kwargs: bool):
- """Removes (strips) HTML tags from text.
+ """Remove (strip) HTML tags from text.
+
Can also take additional parameters
to be passed to the serializer (see `get_cleaner`).
@@ -54,8 +56,7 @@ def strip_html(text: str, **serializer_kwargs: bool):
def strip_html_and_truncate(html_text: str, max_length: int):
- """Strips HTML tags and whitespaces from text,
- then trim the description."""
+ """Strip HTML tags and whitespaces from the text, then trim the description."""
text = strip_html(html_text, strip_whitespace=True)
text = truncatechars(text, max_length)
return text
diff --git a/saleor/dashboard/forms.py b/saleor/dashboard/forms.py
index d3cb9f0862..c24c4fc1e5 100644
--- a/saleor/dashboard/forms.py
+++ b/saleor/dashboard/forms.py
@@ -153,7 +153,7 @@ class AjaxSelect2MultipleChoiceField(forms.MultipleChoiceField):
class PermissionMultipleChoiceField(forms.ModelMultipleChoiceField):
- """ Permission multiple choice field with label override."""
+ """Permission multiple choice field with label override."""
def label_from_instance(self, obj):
return obj.name
diff --git a/saleor/dashboard/menu/forms.py b/saleor/dashboard/menu/forms.py
index 43c48e8670..d2084e6a5d 100644
--- a/saleor/dashboard/menu/forms.py
+++ b/saleor/dashboard/menu/forms.py
@@ -105,6 +105,7 @@ class ReorderMenuItemsForm(forms.ModelForm):
Args:
ordered_menu_items - sorted menu items
+
"""
ordered_menu_items = OrderedModelMultipleChoiceField(
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index eb232449fd..ea284416e3 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -118,8 +118,7 @@ def get_prices_of_products_in_discounted_categories(order, discounted_categories
def get_products_voucher_discount_for_order(order, voucher):
- """Calculate products discount value for a voucher, depending on its type.
- """
+ """Calculate products discount value for a voucher, depending on its type."""
prices = None
if voucher.type == VoucherType.PRODUCT:
prices = get_prices_of_discounted_products(order, voucher.products.all())
diff --git a/saleor/dashboard/templatetags/orders.py b/saleor/dashboard/templatetags/orders.py
index 6f79848034..91f5a1001f 100644
--- a/saleor/dashboard/templatetags/orders.py
+++ b/saleor/dashboard/templatetags/orders.py
@@ -24,7 +24,9 @@ EMAIL_CHOICES = {
def get_money_from_params(amount):
- """Money serialization changed at one point, as for now it's serialized
+ """Retrieve the correct money amount from the given object.
+
+ Money serialization changed at one point, as for now it's serialized
as a dict. But we keep those settings for the legacy data.
Can be safely removed after migrating to Dashboard 2.0
@@ -38,10 +40,10 @@ def get_money_from_params(amount):
@register.simple_tag
def display_order_event(order_event: OrderEvent):
- """This function is used to keep the backwards compatibility
- with the old dashboard and new type of order events
- (storing enums instead of messages)
- """
+ """Keep the backwards compatibility with the old dashboard and new type of events.
+
+ The new one is storing enums values instead of raw messages.
+ """
event_type = order_event.type
params = order_event.parameters
if event_type == events.OrderEvents.PLACED_FROM_DRAFT:
diff --git a/saleor/dashboard/widgets.py b/saleor/dashboard/widgets.py
index 2203e70c02..9ec9db7a9b 100644
--- a/saleor/dashboard/widgets.py
+++ b/saleor/dashboard/widgets.py
@@ -37,6 +37,7 @@ class RichTextEditorWidget(Textarea):
class CharsLeftWidget(TextInput):
- """Displays number of characters left on the right side of the label,
- requires different rendering on the frontend.
+ """Display the number of characters left on the right side of the label.
+
+ Require different rendering on the frontend.
"""
diff --git a/saleor/discount/migrations/0002_voucher.py b/saleor/discount/migrations/0002_voucher.py
index 9ba86ebb8c..3e281c21d1 100644
--- a/saleor/discount/migrations/0002_voucher.py
+++ b/saleor/discount/migrations/0002_voucher.py
@@ -3,10 +3,11 @@
from __future__ import unicode_literals
import datetime
-from django.conf import settings
-from django.db import migrations, models
+
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0004_auto_20170206_0407.py b/saleor/discount/migrations/0004_auto_20170206_0407.py
index 87ab72bdb7..2bae7cfae0 100644
--- a/saleor/discount/migrations/0004_auto_20170206_0407.py
+++ b/saleor/discount/migrations/0004_auto_20170206_0407.py
@@ -2,10 +2,10 @@
# Generated by Django 1.10.5 on 2017-02-06 10:07
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0007_auto_20180108_0814.py b/saleor/discount/migrations/0007_auto_20180108_0814.py
index dfa8f38a0d..fb57119d44 100644
--- a/saleor/discount/migrations/0007_auto_20180108_0814.py
+++ b/saleor/discount/migrations/0007_auto_20180108_0814.py
@@ -3,10 +3,11 @@
from __future__ import unicode_literals
import datetime
-from django.conf import settings
-from django.db import migrations, models
+
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0010_auto_20180724_1251.py b/saleor/discount/migrations/0010_auto_20180724_1251.py
index 32152548b0..7fcb353780 100644
--- a/saleor/discount/migrations/0010_auto_20180724_1251.py
+++ b/saleor/discount/migrations/0010_auto_20180724_1251.py
@@ -1,8 +1,9 @@
# Generated by Django 2.0.3 on 2018-07-24 17:51
import datetime
-from django.db import migrations, models
+
import django_countries.fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0011_auto_20180803_0528.py b/saleor/discount/migrations/0011_auto_20180803_0528.py
index 83a34c9ca7..3f31dab922 100644
--- a/saleor/discount/migrations/0011_auto_20180803_0528.py
+++ b/saleor/discount/migrations/0011_auto_20180803_0528.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.3 on 2018-08-03 10:28
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0012_auto_20190329_0836.py b/saleor/discount/migrations/0012_auto_20190329_0836.py
index 9491e86c6f..28e7f4d9e3 100644
--- a/saleor/discount/migrations/0012_auto_20190329_0836.py
+++ b/saleor/discount/migrations/0012_auto_20190329_0836.py
@@ -1,7 +1,7 @@
# Generated by Django 2.1.7 on 2019-03-29 13:36
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/discount/migrations/0013_auto_20190618_0733.py b/saleor/discount/migrations/0013_auto_20190618_0733.py
index 54ce740f22..761aa88ad0 100644
--- a/saleor/discount/migrations/0013_auto_20190618_0733.py
+++ b/saleor/discount/migrations/0013_auto_20190618_0733.py
@@ -1,7 +1,7 @@
# Generated by Django 2.2.2 on 2019-06-18 12:33
-from django.db import migrations, models
import django.utils.timezone
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/extensions/base_plugin.py b/saleor/extensions/base_plugin.py
index 2966f8dfa7..f13b796b8c 100644
--- a/saleor/extensions/base_plugin.py
+++ b/saleor/extensions/base_plugin.py
@@ -13,10 +13,12 @@ if TYPE_CHECKING:
class BasePlugin:
- """Abstract class for storing all methods available for any plugin. All methods
- take previous_value parameter. previous_value contains a value calculated by the
- previous plugin in the queue. If the plugin is first, it will use default value
- calculated by the manager"""
+ """Abstract class for storing all methods available for any plugin.
+
+ All methods take previous_value parameter.
+ previous_value contains a value calculated by the previous plugin in the queue.
+ If the plugin is first, it will use default value calculated by the manager.
+ """
def calculate_checkout_total(
self,
diff --git a/saleor/extensions/manager.py b/saleor/extensions/manager.py
index 5da1120eda..0cf586c58c 100644
--- a/saleor/extensions/manager.py
+++ b/saleor/extensions/manager.py
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
class ExtensionsManager:
- """Base manager for handling a plugins logic"""
+ """Base manager for handling plugins logic."""
plugins = None
@@ -30,8 +30,7 @@ class ExtensionsManager:
def __run_method_on_plugins(
self, method_name: str, default_value: Any, *args, **kwargs
):
- """It takes all declared plugins and tries to run method with the given name on
- each plugin"""
+ """Try to run a method with the given name on each declared plugin."""
value = default_value
for plugin in self.plugins:
value = self.__run_method_on_single_plugin(
@@ -47,9 +46,12 @@ class ExtensionsManager:
*args,
**kwargs,
) -> Any:
- """Run method_name on plugin. Method will return value returned from plugin's
+ """Run method_name on plugin.
+
+ Method will return value returned from plugin's
method. If plugin doesn't have own implementation of expected method_name, it
- will return previous_value."""
+ will return previous_value.
+ """
plugin_method = getattr(plugin, method_name, NotImplemented)
if plugin_method == NotImplemented:
return previous_value
diff --git a/saleor/extensions/plugins/avatax/__init__.py b/saleor/extensions/plugins/avatax/__init__.py
index f906f4d1da..12a6d5c55d 100644
--- a/saleor/extensions/plugins/avatax/__init__.py
+++ b/saleor/extensions/plugins/avatax/__init__.py
@@ -52,7 +52,7 @@ class CustomerErrors:
def get_api_url() -> str:
- """Based on settings return sanbox or production url"""
+ """Based on settings return sanbox or production url."""
if settings.AVATAX_USE_SANDBOX:
return "https://sandbox-rest.avatax.com/api/v2/"
return "https://rest.avatax.com/api/v2/"
@@ -102,8 +102,7 @@ def _validate_adddress_details(
def _validate_order(order: "Order") -> bool:
- """Validate if order object contains enough information to generate a request to
- avatax"""
+ """Validate the order object if it is ready to generate a request to avatax."""
if not order.lines.count():
return False
shipping_address = order.shipping_address
@@ -115,8 +114,7 @@ def _validate_order(order: "Order") -> bool:
def _validate_checkout(checkout: "Checkout") -> bool:
- """Validate if checkout object contains enough information to generate a request to
- avatax"""
+ """Validate the checkout object if it is ready to generate a request to avatax."""
if not checkout.lines.count():
return False
@@ -135,8 +133,11 @@ def _retrieve_from_cache(token):
def checkout_needs_new_fetch(data, checkout_token: str) -> bool:
- """We store the response from avatax for checkout object for given time. If object
- doesn't exist in cache or something has changed, then we fetch data from avatax."""
+ """Check if avatax's checkout response is cached or not.
+
+ We store the response from avatax for checkout object for given time. If object
+ doesn't exist in cache or something has changed, then we fetch data from avatax.
+ """
cached_checkout = _retrieve_from_cache(checkout_token)
@@ -150,8 +151,11 @@ def checkout_needs_new_fetch(data, checkout_token: str) -> bool:
def taxes_need_new_fetch(data: Dict[str, Any], taxes_token: str) -> bool:
- """We store the response from avatax. If object doesn't exist in cache or
- something has changed, then we fetch data from avatax."""
+ """Check if Avatax's taxes data need to be refetched.
+
+ The response from Avatax is stored in a cache. If an object doesn't exist in cache
+ or something has changed, taxes need to be refetched.
+ """
cached_data = _retrieve_from_cache(taxes_token)
if not cached_data:
@@ -356,8 +360,10 @@ def _fetch_new_taxes_data(data: List[Dict], data_cache_key: str):
def get_cached_response_or_fetch(data, token_in_cache, force_refresh=False):
- """Try to find response in cache. Return cached response if requests data are
- the same. Fetch new data in other cases"""
+ """Try to find response in cache.
+
+ Return cached response if requests data are the same. Fetch new data in other cases.
+ """
data_cache_key = CACHE_KEY + token_in_cache
if taxes_need_new_fetch(data, token_in_cache) or force_refresh:
response = _fetch_new_taxes_data(data, data_cache_key)
@@ -407,8 +413,10 @@ def generate_tax_codes_dict(
def get_cached_tax_codes_or_fetch(cache_time: int = TAX_CODES_CACHE_TIME):
- """Try to get cached tax codes. If cache is empty fetch the newest taxcodes from
- avatax"""
+ """Try to get cached tax codes.
+
+ If the cache is empty, fetch the newest taxcodes from avatax.
+ """
tax_codes = cache.get(TAX_CODES_CACHE_KEY, {})
if not tax_codes:
tax_codes_url = urljoin(get_api_url(), "definitions/taxcodes")
diff --git a/saleor/extensions/plugins/avatax/plugin.py b/saleor/extensions/plugins/avatax/plugin.py
index 6b9974ec4b..d779d7b0c9 100644
--- a/saleor/extensions/plugins/avatax/plugin.py
+++ b/saleor/extensions/plugins/avatax/plugin.py
@@ -155,8 +155,10 @@ class AvataxPlugin(BasePlugin):
def preprocess_order_creation(
self, checkout: "Checkout", discounts: List["DiscountInfo"], previous_value: Any
):
- """Confirm that all data is correct and we can proceed with creation of order.
- Raise error when can't receive taxes"""
+ """Ensure all the data is correct and we can proceed with creation of order.
+
+ Raise an error when can't receive taxes.
+ """
if not self._enabled:
return
data = generate_request_data_from_checkout(
diff --git a/saleor/extensions/plugins/vatlayer/__init__.py b/saleor/extensions/plugins/vatlayer/__init__.py
index 05bed5aa08..8326aa06f3 100644
--- a/saleor/extensions/plugins/vatlayer/__init__.py
+++ b/saleor/extensions/plugins/vatlayer/__init__.py
@@ -77,8 +77,11 @@ DEFAULT_TAX_RATE_NAME = TaxRateType.STANDARD
def _convert_to_naive_taxed_money(base, taxes, rate_name):
- """Naively convert Money to TaxedMoney for consistency with price
- handling logic across the codebase, passthrough other money types"""
+ """Naively convert Money to TaxedMoney.
+
+ It is meant for consistency with price handling logic across the codebase,
+ passthrough other money types.
+ """
if isinstance(base, Money):
return TaxedMoney(net=base, gross=base)
if isinstance(base, MoneyRange):
diff --git a/saleor/extensions/plugins/vatlayer/plugin.py b/saleor/extensions/plugins/vatlayer/plugin.py
index 5fe166bf67..d79e4f7f2d 100644
--- a/saleor/extensions/plugins/vatlayer/plugin.py
+++ b/saleor/extensions/plugins/vatlayer/plugin.py
@@ -73,7 +73,7 @@ class VatlayerPlugin(BasePlugin):
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
- """Calculate subtotal gross for checkout"""
+ """Calculate subtotal gross for checkout."""
if self._skip_plugin(previous_value):
return previous_value
@@ -90,8 +90,11 @@ class VatlayerPlugin(BasePlugin):
return lines_total
def _get_taxes_for_country(self, country: Country):
- """Tries to fetch cached taxes on the plugin level. If the plugin doesn't have
- cached taxes for a given country it will fetch it from cache or db"""
+ """Try to fetch cached taxes on the plugin level.
+
+ If the plugin doesn't have cached taxes for a given country it will fetch it
+ from cache or db.
+ """
if not country:
country = Country(settings.DEFAULT_COUNTRY)
country_code = country.code
@@ -107,7 +110,7 @@ class VatlayerPlugin(BasePlugin):
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
- """Calculate shipping gross for checkout"""
+ """Calculate shipping gross for checkout."""
if self._skip_plugin(previous_value):
return previous_value
@@ -268,8 +271,7 @@ class VatlayerPlugin(BasePlugin):
def get_tax_rate_percentage_value(
self, obj: Union["Product", "ProductType"], country: Country, previous_value
) -> Decimal:
- """Return tax rate percentage value for given tax rate type in current
- country."""
+ """Return tax rate percentage value for given tax rate type in the country."""
if not self._enabled:
return previous_value
taxes = self._get_taxes_for_country(country)
diff --git a/saleor/giftcard/migrations/0001_initial.py b/saleor/giftcard/migrations/0001_initial.py
index 55a89d152e..cbc8cd78da 100644
--- a/saleor/giftcard/migrations/0001_initial.py
+++ b/saleor/giftcard/migrations/0001_initial.py
@@ -1,10 +1,11 @@
# Generated by Django 2.2.1 on 2019-06-07 09:43
import datetime
-from django.conf import settings
-from django.db import migrations, models
+
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/graphql/account/i18n.py b/saleor/graphql/account/i18n.py
index e913b46a3a..65c102db42 100644
--- a/saleor/graphql/account/i18n.py
+++ b/saleor/graphql/account/i18n.py
@@ -7,8 +7,9 @@ from ...account.validators import validate_possible_number
class I18nMixin:
- """Mixin to be used with BaseMutation or ModelMutation, providing methods
- necessary to fulfill the internationalization process.
+ """A mixin providing methods necessary to fulfill the internationalization process.
+
+ It is to be used with BaseMutation or ModelMutation.
"""
@classmethod
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index f905028d6f..2376aade6f 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -232,8 +232,10 @@ class CustomerUpdate(CustomerCreate):
@classmethod
def perform_mutation(cls, _root, info, **data):
- """Override the base method `perform_mutation` of ModelMutation
- to generate events by comparing the old instance with the new data."""
+ """Generate events by comparing the old instance with the new data.
+
+ It overrides the `perform_mutation` base method of ModelMutation.
+ """
# Retrieve the data
original_instance = cls.get_instance(info, **data)
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index de6158bcfa..d0869b6d2d 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -68,7 +68,8 @@ class Address(CountableDjangoObjectType):
@staticmethod
def resolve_is_default_shipping_address(root: models.Address, _info):
- """
+ """Look if the address is the default shipping address of the user.
+
This field is added through annotation when using the
`resolve_addresses` resolver. It's invalid for
`resolve_default_shipping_address` and
@@ -86,7 +87,8 @@ class Address(CountableDjangoObjectType):
@staticmethod
def resolve_is_default_billing_address(root: models.Address, _info):
- """
+ """Look if the address is the default billing address of the user.
+
This field is added through annotation when using the
`resolve_addresses` resolver. It's invalid for
`resolve_default_shipping_address` and
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 739bbffa39..b1b6c5f9f8 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -50,10 +50,7 @@ from .types import Checkout, CheckoutLine
def clean_shipping_method(
checkout: models.Checkout, method: Optional[models.ShippingMethod], discounts
) -> bool:
- """
- Check if current shipping method is valid. If so - return True.
- It returns whether the selected shipping method is valid
- """
+ """Check if current shipping method is valid."""
if not method:
# no shipping method was provided, it is valid
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py
index d92a048a3c..343ca6f547 100644
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@ -15,8 +15,7 @@ class ReportingPeriod(graphene.Enum):
def to_enum(enum_cls, *, type_name=None, **options) -> graphene.Enum:
- """
- Create a graphene enum from a class containing a set of options.
+ """Create a Graphene enum from a class containing a set of options.
:param enum_cls:
The class to build the enum from.
diff --git a/saleor/graphql/core/filters.py b/saleor/graphql/core/filters.py
index 45012ae850..dd0c937a82 100644
--- a/saleor/graphql/core/filters.py
+++ b/saleor/graphql/core/filters.py
@@ -26,8 +26,10 @@ class DefaultMultipleChoiceField(MultipleChoiceField):
class EnumFilter(django_filters.CharFilter):
- """ Filter class for graphene enum object.
- enum_class needs to be passed explicitly as well as the method."""
+ """Filter class for Graphene enum object.
+
+ enum_class needs to be passed explicitly as well as the method.
+ """
def __init__(self, input_class, *args, **kwargs):
assert kwargs.get(
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
index 5b0d16f678..fd4f23b530 100644
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -97,7 +97,7 @@ class IntRangeInput(graphene.InputObjectType):
class TaxType(graphene.ObjectType):
- """Representation of tax types fetched from tax gateway"""
+ """Representation of tax types fetched from tax gateway."""
description = graphene.String(description="Description of the tax type")
tax_code = graphene.String(
diff --git a/saleor/graphql/core/types/filter_input.py b/saleor/graphql/core/types/filter_input.py
index 9ef25912d5..b32f223e74 100644
--- a/saleor/graphql/core/types/filter_input.py
+++ b/saleor/graphql/core/types/filter_input.py
@@ -9,8 +9,10 @@ from .converter import convert_form_field
class FilterInputObjectType(InputObjectType):
"""Class for storing and serving django-filtres as graphQL input.
+
FilterSet class which inherits from django-filters.FilterSet should be
- provided with using fitlerset_class argument."""
+ provided with using fitlerset_class argument.
+ """
@classmethod
def __init_subclass_with_meta__(
@@ -35,9 +37,10 @@ class FilterInputObjectType(InputObjectType):
@classmethod
def get_filtering_args_from_filterset(cls):
- """ Inspect a FilterSet and produce the arguments to pass to
- a Graphene Field. These arguments will be available to
- filter against in the GraphQL
+ """Retrieve the filtering arguments from the queryset.
+
+ Inspect a FilterSet and produce the arguments to pass to a Graphene field.
+ These arguments will be available to filter against in the GraphQL.
"""
if not cls.custom_filterset_class:
assert cls.model and cls.fields, (
diff --git a/saleor/graphql/middleware.py b/saleor/graphql/middleware.py
index ead93a98cb..43bed4e0ba 100644
--- a/saleor/graphql/middleware.py
+++ b/saleor/graphql/middleware.py
@@ -5,8 +5,7 @@ from graphql_jwt.middleware import JSONWebTokenMiddleware
def jwt_middleware(get_response):
- """Authenticate user using JSONWebTokenMiddleware
- ignoring the session-based authentication.
+ """Authenticate a user using JWT and ignore the session-based authentication.
This middleware resets authentication made by any previous middlewares
and authenticates the user
diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.py
index d171f7763c..11738a427e 100644
--- a/saleor/graphql/order/utils.py
+++ b/saleor/graphql/order/utils.py
@@ -29,10 +29,13 @@ def validate_order_lines(order):
def validate_draft_order(order):
- """Checks, if given order has a proper customer data, shipping
- address and method set up and return list of errors if not.
- Checks if product variants for order lines still exists in
- database, too.
+ """Check if the given order contains the proper data.
+
+ - Has proper customer data,
+ - Shipping address and method are set up,
+ - Product variants for order lines still exists in database.
+
+ Returns a list of errors if any were found.
"""
if order.is_shipping_required():
validate_shipping_method(order)
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index a5c1dbcc08..aff11dec60 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -184,9 +184,7 @@ class AttributeUpdate(AttributeMixin, ModelMutation):
@classmethod
def clean_remove_values(cls, cleaned_input, instance):
- """Check if AttributeValues to be removed are assigned to given
- Attribute.
- """
+ """Check if the values to be removed are assigned to the given attribute."""
remove_values = cleaned_input.get("remove_values", [])
for value in remove_values:
if value.attribute != instance:
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 8de3cb121a..944ac07cd5 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -45,6 +45,7 @@ from .digital_contents import DigitalContent
def prefetch_products(info, *_args, **_kwargs):
"""Prefetch products visible to the current user.
+
Can be used with models that have the `products` relationship. The queryset
of products being prefetched is filtered based on permissions of the
requesting user, to restrict access to unpublished products from non-staff
@@ -71,6 +72,7 @@ def prefetch_products_collection_sorted(info, *_args, **_kwargs):
def resolve_attribute_list(attributes_hstore, attributes_qs):
"""Resolve attributes dict into a list of `SelectedAttribute`s.
+
keys = list(attributes.keys())
values = list(attributes.values())
diff --git a/saleor/graphql/translations/resolvers.py b/saleor/graphql/translations/resolvers.py
index dccd51ebb0..ed8ef4bcd5 100644
--- a/saleor/graphql/translations/resolvers.py
+++ b/saleor/graphql/translations/resolvers.py
@@ -5,7 +5,7 @@ from ...shipping import models as shipping_models
def resolve_translation(instance, _info, language_code):
- """Gets translation object from instance based on language code."""
+ """Get translation object from instance based on language code."""
return instance.translations.filter(language_code=language_code).first()
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index b9d78d9dfb..a60c5ce01c 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -95,10 +95,11 @@ def get_nodes(ids, graphene_type=None):
def filter_by_query_param(queryset, query, search_fields):
"""Filter queryset according to given parameters.
- Keyword arguments:
- queryset - queryset to be filtered
- query - search string
- search_fields - fields considered in filtering
+ Keyword Arguments:
+ queryset - queryset to be filtered
+ query - search string
+ search_fields - fields considered in filtering
+
"""
if query:
query_by = {
@@ -138,8 +139,9 @@ def generate_query_argument_description(search_fields):
def format_permissions_for_display(permissions):
"""Transform permissions queryset into PermissionDisplay list.
- Keyword arguments:
- permissions - queryset with permissions
+ Keyword Arguments:
+ permissions - queryset with permissions
+
"""
formatted_permissions = []
for permission in permissions:
diff --git a/saleor/menu/migrations/0001_initial.py b/saleor/menu/migrations/0001_initial.py
index d3803379dc..97ade669bf 100644
--- a/saleor/menu/migrations/0001_initial.py
+++ b/saleor/menu/migrations/0001_initial.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.2 on 2018-03-12 15:29
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/menu/migrations/0006_auto_20180803_0528.py b/saleor/menu/migrations/0006_auto_20180803_0528.py
index dc31cfb15e..8e81504ef8 100644
--- a/saleor/menu/migrations/0006_auto_20180803_0528.py
+++ b/saleor/menu/migrations/0006_auto_20180803_0528.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.3 on 2018-08-03 10:28
-from django.db import migrations, models
import django.db.models.deletion
from django.contrib.postgres import fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/menu/migrations/0007_auto_20180807_0547.py b/saleor/menu/migrations/0007_auto_20180807_0547.py
index 576a25353b..e6a028407c 100644
--- a/saleor/menu/migrations/0007_auto_20180807_0547.py
+++ b/saleor/menu/migrations/0007_auto_20180807_0547.py
@@ -1,10 +1,11 @@
# Generated by Django 2.0.3 on 2018-08-07 10:47
import json
-from django.db import migrations
+
from django.contrib.postgres import fields
+from django.db import migrations
from saleor.page.models import Page
-from saleor.product.models import Collection, Category
+from saleor.product.models import Category, Collection
def get_linked_object_kwargs(object):
@@ -39,8 +40,9 @@ def get_menu_item_as_dict(menu_item):
def get_menu_as_json(menu):
- """Builds Tree-like structure from top menu items,
- its children and its grandchildren.
+ """Build Tree-like JSON structure from the top menu.
+
+ From the top menu items, its children and its grandchildren.
"""
top_items = menu.items.filter(parent=None)
menu_data = []
diff --git a/saleor/menu/migrations/0008_menu_json_content_new.py b/saleor/menu/migrations/0008_menu_json_content_new.py
index fdbe8e5736..b82ced7435 100644
--- a/saleor/menu/migrations/0008_menu_json_content_new.py
+++ b/saleor/menu/migrations/0008_menu_json_content_new.py
@@ -1,8 +1,9 @@
# Generated by Django 2.0.8 on 2018-09-13 13:17
+import json
+
import django.contrib.postgres.fields.jsonb
from django.db import migrations
-import json
class Migration(migrations.Migration):
diff --git a/saleor/menu/utils.py b/saleor/menu/utils.py
index 94c9f14dc8..6752dc131b 100644
--- a/saleor/menu/utils.py
+++ b/saleor/menu/utils.py
@@ -23,9 +23,10 @@ def update_menu_item_linked_object(menu_item, linked_object):
def get_menus_that_need_update(collection=None, categories=None, page=None):
- """Returns primary keys of Menu instances that will be affected by
- deleting one of the listed objects, therefore needs to be updated
- afterwards.
+ """Return the primary keys of the Menu instances.
+
+ They that will be affected by deleting one of the listed objects,
+ therefore needs to be updated afterwards.
"""
if not any([page, collection, categories]):
return []
@@ -57,9 +58,7 @@ def get_menu_item_as_dict(menu_item):
def get_menu_as_json(menu):
- """Builds Tree-like structure from top menu items,
- its children and its grandchildren.
- """
+ """Build a tree structure from top menu items, its children and grandchildren."""
top_items = menu.items.filter(parent=None).prefetch_related(
"category",
"page",
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 6030d9eb56..979e3abc6f 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -16,11 +16,12 @@ CONFIRM_PAYMENT_TEMPLATE = "order/payment/confirm_payment"
def collect_data_for_email(order_pk, template):
- """Collects data required for email sending.
+ """Collect the required data for sending emails.
Args:
order_pk (int): order primary key
template (str): email template path
+
"""
order = Order.objects.get(pk=order_pk)
recipient_email = order.get_customer_email()
@@ -62,7 +63,7 @@ def collect_data_for_fullfillment_email(order_pk, template, fulfillment_pk):
@app.task
def send_order_confirmation(order_pk, user_pk=None):
- """Sends order confirmation email."""
+ """Send order confirmation email."""
email_data = collect_data_for_email(order_pk, CONFIRM_ORDER_TEMPLATE)
send_templated_mail(**email_data)
events.email_sent_event(
@@ -106,6 +107,6 @@ def send_fulfillment_update(order_pk, fulfillment_pk):
@app.task
def send_payment_confirmation(order_pk):
- """Sends payment confirmation email."""
+ """Send the payment confirmation email."""
email_data = collect_data_for_email(order_pk, CONFIRM_PAYMENT_TEMPLATE)
send_templated_mail(**email_data)
diff --git a/saleor/order/migrations/0001_initial.py b/saleor/order/migrations/0001_initial.py
index c909b82d8b..d05ce999aa 100644
--- a/saleor/order/migrations/0001_initial.py
+++ b/saleor/order/migrations/0001_initial.py
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
-import django.db.models.deletion
-from django.conf import settings
-import django_prices.models
import django.core.validators
+import django.db.models.deletion
import django.utils.timezone
+import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0002_auto_20150820_1955.py b/saleor/order/migrations/0002_auto_20150820_1955.py
index 86fdc2c812..d9029d4931 100644
--- a/saleor/order/migrations/0002_auto_20150820_1955.py
+++ b/saleor/order/migrations/0002_auto_20150820_1955.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0003_auto_20150825_1433.py b/saleor/order/migrations/0003_auto_20150825_1433.py
index d240065e3e..646e0853ea 100644
--- a/saleor/order/migrations/0003_auto_20150825_1433.py
+++ b/saleor/order/migrations/0003_auto_20150825_1433.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import models, migrations
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0004_order_total.py b/saleor/order/migrations/0004_order_total.py
index 1d86bc92a9..ece5bde776 100644
--- a/saleor/order/migrations/0004_order_total.py
+++ b/saleor/order/migrations/0004_order_total.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import migrations
-from django.conf import settings
import django_prices.models
+from django.conf import settings
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0008_auto_20151026_0820.py b/saleor/order/migrations/0008_auto_20151026_0820.py
index 26f4b37772..622ed252d8 100644
--- a/saleor/order/migrations/0008_auto_20151026_0820.py
+++ b/saleor/order/migrations/0008_auto_20151026_0820.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0009_auto_20151201_0820.py b/saleor/order/migrations/0009_auto_20151201_0820.py
index 79a55ec579..e38b543f6d 100644
--- a/saleor/order/migrations/0009_auto_20151201_0820.py
+++ b/saleor/order/migrations/0009_auto_20151201_0820.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import django_prices.models
from django.conf import settings
from django.db import migrations, models
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0011_auto_20160207_0534.py b/saleor/order/migrations/0011_auto_20160207_0534.py
index 7e20dbc4aa..f3def9a868 100644
--- a/saleor/order/migrations/0011_auto_20160207_0534.py
+++ b/saleor/order/migrations/0011_auto_20160207_0534.py
@@ -2,10 +2,10 @@
# Generated by Django 1.9.1 on 2016-02-07 11:34
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0013_auto_20160906_0741.py b/saleor/order/migrations/0013_auto_20160906_0741.py
index 82697e25f6..6fb5efcf55 100644
--- a/saleor/order/migrations/0013_auto_20160906_0741.py
+++ b/saleor/order/migrations/0013_auto_20160906_0741.py
@@ -2,9 +2,9 @@
# Generated by Django 1.10.1 on 2016-09-06 12:41
from __future__ import unicode_literals
+import django_prices.models
from django.conf import settings
from django.db import migrations, models
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0015_auto_20170206_0407.py b/saleor/order/migrations/0015_auto_20170206_0407.py
index f03c0be4ec..ef35eaddba 100644
--- a/saleor/order/migrations/0015_auto_20170206_0407.py
+++ b/saleor/order/migrations/0015_auto_20170206_0407.py
@@ -2,10 +2,10 @@
# Generated by Django 1.10.5 on 2017-02-06 10:07
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0019_auto_20171109_1423.py b/saleor/order/migrations/0019_auto_20171109_1423.py
index 5e575f13e4..0c2b31785a 100644
--- a/saleor/order/migrations/0019_auto_20171109_1423.py
+++ b/saleor/order/migrations/0019_auto_20171109_1423.py
@@ -2,9 +2,9 @@
# Generated by Django 1.11.5 on 2017-11-09 20:23
from __future__ import unicode_literals
+import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0022_auto_20171205_0428.py b/saleor/order/migrations/0022_auto_20171205_0428.py
index 930e12fcc4..4786948cc1 100644
--- a/saleor/order/migrations/0022_auto_20171205_0428.py
+++ b/saleor/order/migrations/0022_auto_20171205_0428.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.5 on 2017-12-05 10:28
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0023_auto_20171206_0506.py b/saleor/order/migrations/0023_auto_20171206_0506.py
index 724ff8dd34..376a1f393d 100644
--- a/saleor/order/migrations/0023_auto_20171206_0506.py
+++ b/saleor/order/migrations/0023_auto_20171206_0506.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.5 on 2017-12-06 11:06
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0026_auto_20171218_0428.py b/saleor/order/migrations/0026_auto_20171218_0428.py
index 27e165a850..ae97d37874 100644
--- a/saleor/order/migrations/0026_auto_20171218_0428.py
+++ b/saleor/order/migrations/0026_auto_20171218_0428.py
@@ -2,9 +2,9 @@
# Generated by Django 1.11.5 on 2017-12-18 10:28
from __future__ import unicode_literals
+import django_prices.models
from django.conf import settings
from django.db import migrations, models
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0027_auto_20180108_0814.py b/saleor/order/migrations/0027_auto_20180108_0814.py
index 86c4417ffa..9841f08b10 100644
--- a/saleor/order/migrations/0027_auto_20180108_0814.py
+++ b/saleor/order/migrations/0027_auto_20180108_0814.py
@@ -2,12 +2,12 @@
# Generated by Django 1.11.5 on 2018-01-08 14:14
from __future__ import unicode_literals
-from django.conf import settings
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0029_auto_20180111_0845.py b/saleor/order/migrations/0029_auto_20180111_0845.py
index 3e3be908cc..f34dd2ffc2 100644
--- a/saleor/order/migrations/0029_auto_20180111_0845.py
+++ b/saleor/order/migrations/0029_auto_20180111_0845.py
@@ -2,9 +2,9 @@
# Generated by Django 1.11.5 on 2018-01-11 14:45
from __future__ import unicode_literals
+import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0034_auto_20180221_1056.py b/saleor/order/migrations/0034_auto_20180221_1056.py
index 8a3148086b..7e5f4264b9 100644
--- a/saleor/order/migrations/0034_auto_20180221_1056.py
+++ b/saleor/order/migrations/0034_auto_20180221_1056.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.2 on 2018-02-21 16:56
+import django_prices.models
from django.conf import settings
from django.db import migrations
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0037_auto_20180228_0450.py b/saleor/order/migrations/0037_auto_20180228_0450.py
index 13a1870ec0..f9aa0273a9 100644
--- a/saleor/order/migrations/0037_auto_20180228_0450.py
+++ b/saleor/order/migrations/0037_auto_20180228_0450.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.2 on 2018-02-28 10:50
+import django_prices.models
from django.conf import settings
from django.db import migrations
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0039_auto_20180312_1203.py b/saleor/order/migrations/0039_auto_20180312_1203.py
index dd680faed6..1c13c4416d 100644
--- a/saleor/order/migrations/0039_auto_20180312_1203.py
+++ b/saleor/order/migrations/0039_auto_20180312_1203.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.2 on 2018-03-12 17:03
+import django_prices.models
from django.conf import settings
from django.db import migrations
-import django_prices.models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0040_auto_20180210_0422.py b/saleor/order/migrations/0040_auto_20180210_0422.py
index 040db3f62d..21bc6b18c0 100644
--- a/saleor/order/migrations/0040_auto_20180210_0422.py
+++ b/saleor/order/migrations/0040_auto_20180210_0422.py
@@ -1,9 +1,9 @@
# Generated by Django 2.0.2 on 2018-02-10 10:22
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0042_auto_20180227_0436.py b/saleor/order/migrations/0042_auto_20180227_0436.py
index a9951c33ce..1db27db23c 100644
--- a/saleor/order/migrations/0042_auto_20180227_0436.py
+++ b/saleor/order/migrations/0042_auto_20180227_0436.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.2 on 2018-02-27 10:36
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0044_auto_20180326_1055.py b/saleor/order/migrations/0044_auto_20180326_1055.py
index 581796853a..89eebaa435 100644
--- a/saleor/order/migrations/0044_auto_20180326_1055.py
+++ b/saleor/order/migrations/0044_auto_20180326_1055.py
@@ -1,9 +1,9 @@
# Generated by Django 2.0.3 on 2018-03-26 15:55
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0045_auto_20180329_0142.py b/saleor/order/migrations/0045_auto_20180329_0142.py
index 09e85666b6..22f9e6f292 100644
--- a/saleor/order/migrations/0045_auto_20180329_0142.py
+++ b/saleor/order/migrations/0045_auto_20180329_0142.py
@@ -1,9 +1,9 @@
# Generated by Django 2.0.3 on 2018-03-29 06:42
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0048_auto_20180629_1055.py b/saleor/order/migrations/0048_auto_20180629_1055.py
index 05d9ba39a8..181146a6db 100644
--- a/saleor/order/migrations/0048_auto_20180629_1055.py
+++ b/saleor/order/migrations/0048_auto_20180629_1055.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.3 on 2018-06-29 15:55
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0052_auto_20180822_0720.py b/saleor/order/migrations/0052_auto_20180822_0720.py
index 34aa03e454..3713f2d283 100644
--- a/saleor/order/migrations/0052_auto_20180822_0720.py
+++ b/saleor/order/migrations/0052_auto_20180822_0720.py
@@ -1,8 +1,9 @@
# Generated by Django 2.0.3 on 2018-08-22 12:20
-from django.db import migrations, models
import django.db.models.deletion
import django_measurement.models
+from django.db import migrations, models
+
import saleor.core.weight
diff --git a/saleor/order/migrations/0053_orderevent.py b/saleor/order/migrations/0053_orderevent.py
index 36f0d91c4f..b73ca97b1f 100644
--- a/saleor/order/migrations/0053_orderevent.py
+++ b/saleor/order/migrations/0053_orderevent.py
@@ -1,9 +1,9 @@
# Generated by Django 2.0.8 on 2018-09-11 06:09
-from django.conf import settings
-from django.db import migrations, models
import django.utils.timezone
+from django.conf import settings
from django.contrib.postgres import fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0054_move_data_to_order_events.py b/saleor/order/migrations/0054_move_data_to_order_events.py
index 52073ddb3b..6fa45fbdfd 100644
--- a/saleor/order/migrations/0054_move_data_to_order_events.py
+++ b/saleor/order/migrations/0054_move_data_to_order_events.py
@@ -1,12 +1,14 @@
# Generated by Django 2.0.8 on 2018-09-11 06:09
from django.db import migrations
+
from saleor.order import OrderEvents
def move_order_note_to_events(apps, schema_editor):
- """Move legacy OrderNote content to OrderEvent to prevent
- data loss during the migration.
+ """Move legacy OrderNote content to OrderEvent.
+
+ It's meant to prevent data loss during the migration.
"""
OrderNote = apps.get_model("order", "OrderNote")
OrderEvent = apps.get_model("order", "OrderEvent")
@@ -22,8 +24,9 @@ def move_order_note_to_events(apps, schema_editor):
def move_order_history_entry_to_events(apps, schema_editor):
- """Move legacy OrderHistoryEntry content to OrderEvent to prevent
- data loss during the migration.
+ """Move legacy OrderHistoryEntry content to OrderEvent.
+
+ It is meant to prevent data loss during the migration.
"""
OrderHistoryEntry = apps.get_model("order", "OrderHistoryEntry")
OrderEvent = apps.get_model("order", "OrderEvent")
diff --git a/saleor/order/migrations/0056_auto_20180911_1541.py b/saleor/order/migrations/0056_auto_20180911_1541.py
index 0eb79936c1..ed8d49662f 100644
--- a/saleor/order/migrations/0056_auto_20180911_1541.py
+++ b/saleor/order/migrations/0056_auto_20180911_1541.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/order/migrations/0057_orderevent_parameters_new.py b/saleor/order/migrations/0057_orderevent_parameters_new.py
index 47d41816c2..12f4924903 100644
--- a/saleor/order/migrations/0057_orderevent_parameters_new.py
+++ b/saleor/order/migrations/0057_orderevent_parameters_new.py
@@ -1,9 +1,11 @@
# Generated by Django 2.0.8 on 2018-09-13 13:17
+import json
+
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
-import json
class Migration(migrations.Migration):
diff --git a/saleor/order/migrations/0064_auto_20181016_0819.py b/saleor/order/migrations/0064_auto_20181016_0819.py
index 6696883447..61f371db00 100644
--- a/saleor/order/migrations/0064_auto_20181016_0819.py
+++ b/saleor/order/migrations/0064_auto_20181016_0819.py
@@ -1,7 +1,7 @@
# Generated by Django 2.1.2 on 2018-10-16 13:19
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 5dd01c6ad6..55acce7208 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -309,13 +309,13 @@ class Order(models.Model):
class OrderLineQueryset(models.QuerySet):
def digital(self):
- """Returns lines with digital products"""
+ """Return lines with digital products."""
for line in self.all():
if line.is_digital:
yield line
def physical(self):
- """Returns lines with physical products"""
+ """Return lines with physical products."""
for line in self.all():
if not line.is_digital:
yield line
@@ -375,8 +375,7 @@ class OrderLine(models.Model):
@property
def is_digital(self) -> bool:
- """Return true if product variant is a digital type and has assigned
- digital content"""
+ """Check if a variant is digital and contains digital content."""
is_digital = self.variant.is_digital()
has_digital = hasattr(self.variant, "digital_content")
return is_digital and has_digital
@@ -437,6 +436,7 @@ class OrderEvent(models.Model):
Args:
parameters: Values needed to display the event on the storefront
type: Type of an order
+
"""
date = models.DateTimeField(default=now, editable=False)
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index e5f6ac6202..186d2090be 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -28,7 +28,7 @@ from . import events
def order_line_needs_automatic_fulfillment(line: OrderLine) -> bool:
- """Check if given line is digital and should be automatically fulfilled"""
+ """Check if given line is digital and should be automatically fulfilled."""
digital_content_settings = get_default_digital_content_settings()
default_automatic_fulfillment = digital_content_settings["automatic_fulfillment"]
content = line.variant.digital_content
@@ -40,8 +40,7 @@ def order_line_needs_automatic_fulfillment(line: OrderLine) -> bool:
def order_needs_automatic_fullfilment(order: Order) -> bool:
- """Check if order has digital products which should be automatically
- fulfilled"""
+ """Check if order has digital products which should be automatically fulfilled."""
for line in order.lines.digital():
if order_line_needs_automatic_fulfillment(line):
return True
@@ -57,8 +56,10 @@ def fulfill_order_line(order_line, quantity):
def automatically_fulfill_digital_lines(order: Order):
- """Fulfill all digital lines which have enabled automatic fulfillment
- setting and send confirmation email."""
+ """Fulfill all digital lines which have enabled automatic fulfillment setting.
+
+ Send confirmation email afterward.
+ """
digital_lines = order.lines.filter(
is_shipping_required=False, variant__digital_content__isnull=False
)
diff --git a/saleor/page/migrations/0004_auto_20180803_0528.py b/saleor/page/migrations/0004_auto_20180803_0528.py
index 0e917aa80c..82dcc5d3ca 100644
--- a/saleor/page/migrations/0004_auto_20180803_0528.py
+++ b/saleor/page/migrations/0004_auto_20180803_0528.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.3 on 2018-08-03 10:28
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.py
index 964e3fe94b..68059c8746 100644
--- a/saleor/payment/gateways/braintree/__init__.py
+++ b/saleor/payment/gateways/braintree/__init__.py
@@ -39,7 +39,7 @@ ERROR_CODES_WHITELIST = {
def get_customer_data(payment_information: PaymentData) -> Dict:
- """Provides customer info, use only for new customer creation"""
+ """Provide customer info, use only for new customer creation."""
billing = payment_information.billing
return {
"order_id": payment_information.order_id,
@@ -60,9 +60,7 @@ def get_customer_data(payment_information: PaymentData) -> Dict:
def get_error_for_client(errors: List) -> str:
- """Filters all error messages and decides which one is visible for the
- client side.
- """
+ """Filter all error messages and decides which one is visible for the client."""
if not errors:
return ""
default_msg = pgettext_lazy(
diff --git a/saleor/payment/gateways/braintree/errors.py b/saleor/payment/gateways/braintree/errors.py
index 6abfb0556a..753f7d37ee 100644
--- a/saleor/payment/gateways/braintree/errors.py
+++ b/saleor/payment/gateways/braintree/errors.py
@@ -1,18 +1,17 @@
-"""We are NOT handling errors from:
-- Braintree Marketplace
-- Dispute
-- Apple Pay
-- OAuth
-- Venmo
-- Search
-- Recurring Billing
-- 3D Secure
-- Customer
-as they are not currently supported.
-
-For the full list of errors please refer to:
-https://developers.braintreepayments.com/reference/general/validation-errors/all/python#transaction
-"""
+# We are NOT handling errors from:
+# - Braintree Marketplace
+# - Dispute
+# - Apple Pay
+# - OAuth
+# - Venmo
+# - Search
+# - Recurring Billing
+# - 3D Secure
+# - Customer
+# as they are not currently supported.
+#
+# For the full list of errors please refer to:
+# https://developers.braintreepayments.com/reference/general/validation-errors/all/python#transaction
from ... import TransactionError
INVALID_EXPIRY_DATE_ERRORS = [
diff --git a/saleor/payment/gateways/dummy/forms.py b/saleor/payment/gateways/dummy/forms.py
index 4aaa438c06..dba24a0f7e 100644
--- a/saleor/payment/gateways/dummy/forms.py
+++ b/saleor/payment/gateways/dummy/forms.py
@@ -35,6 +35,8 @@ class DummyPaymentForm(forms.Form):
def get_payment_token(self):
"""Return selected charge status instead of token for testing only.
- Gateways used for production should return an actual token instead."""
+
+ Gateways used for production should return an actual token instead.
+ """
charge_status = self.cleaned_data["charge_status"]
return charge_status
diff --git a/saleor/payment/gateways/razorpay/__init__.py b/saleor/payment/gateways/razorpay/__init__.py
index 18cf9a1dcd..b2ee531ee4 100644
--- a/saleor/payment/gateways/razorpay/__init__.py
+++ b/saleor/payment/gateways/razorpay/__init__.py
@@ -31,8 +31,7 @@ logger = logging.getLogger(__name__)
def _generate_response(
payment_information: PaymentData, kind: str, data: Dict
) -> GatewayResponse:
- """Generate Saleor transaction information from
- Razorpay's success payload or from passed data."""
+ """Generate Saleor transaction information from the payload or from passed data."""
return GatewayResponse(
transaction_id=data.get("id", payment_information.token),
kind=kind,
@@ -45,14 +44,16 @@ def _generate_response(
def check_payment_supported(payment_information: PaymentData):
- """Checks that a given payment is supported."""
+ """Check that a given payment is supported."""
if payment_information.currency not in SUPPORTED_CURRENCIES:
return errors.UNSUPPORTED_CURRENCY % {"currency": payment_information.currency}
def get_error_message_from_razorpay_error(exc: BaseException):
- """Convert a error razorpay error to a user friendly error message
- and log the exception to stderr."""
+ """Convert a Razorpay error to a user-friendly error message.
+
+ It also logs the exception to stderr.
+ """
logger.exception(exc)
if isinstance(exc, razorpay.errors.BadRequestError):
return errors.INVALID_REQUEST
@@ -61,8 +62,11 @@ def get_error_message_from_razorpay_error(exc: BaseException):
def clean_razorpay_response(response: Dict):
- """As the Razorpay response payload contains the final amount
- in Indian rupees, we convert the amount to paisa (by dividing by 100)."""
+ """Convert the Razorpay response to our internal representation for easier processing.
+
+ As the Razorpay response payload contains the final amount
+ in Indian rupees, we convert the amount to paisa (by dividing by 100).
+ """
response["amount"] = Decimal(response["amount"]) / 100
@@ -88,13 +92,13 @@ def get_client_token(**_):
def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:
"""Capture a authorized payment using the razorpay client.
+
But it first check if the given payment instance is supported
by the gateway.
- If an error from razorpay occurs,
- we flag the transaction as failed and return
- a short user friendly description of the error
- after logging the error to stderr."""
+ If an error from Razorpay occurs, we flag the transaction as failed and return
+ a short user friendly description of the error after logging the error to stderr.
+ """
error = check_payment_supported(payment_information=payment_information)
razorpay_client = get_client(**config.connection_params)
razorpay_amount = get_amount_for_razorpay(payment_information.amount)
@@ -131,7 +135,8 @@ def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayRe
It first retrieve a `charge` transaction to retrieve the
payment id to refund. And return an error with a failed transaction
if the there is no such transaction, or if an error
- from razorpay occurs during the refund."""
+ from Razorpay occurs during the refund.
+ """
error = check_payment_supported(payment_information=payment_information)
if error:
diff --git a/saleor/payment/gateways/razorpay/utils.py b/saleor/payment/gateways/razorpay/utils.py
index 6ea88b0636..74501195ba 100644
--- a/saleor/payment/gateways/razorpay/utils.py
+++ b/saleor/payment/gateways/razorpay/utils.py
@@ -2,12 +2,16 @@ from decimal import Decimal
def get_error_response(amount: Decimal, **additional_kwargs) -> dict:
- """Create a place holder response for invalid/ failed requests
- for generated a failed transaction object."""
+ """Create a placeholder response for invalid or failed requests.
+
+ It is used to generate a failed transaction object.
+ """
return {"is_success": False, "amount": amount, **additional_kwargs}
def get_amount_for_razorpay(amount: Decimal) -> int:
- """Convert an amount of Indian rupees to paisa (needed by the razorpay)
- by multiplying the value by 100."""
+ """Convert an amount of Indian rupees to paisa (needed by Razorpay).
+
+ Multiplies the value by 100.
+ """
return int(amount * 100)
diff --git a/saleor/payment/gateways/stripe/__init__.py b/saleor/payment/gateways/stripe/__init__.py
index 47ced0388e..a9260d7072 100644
--- a/saleor/payment/gateways/stripe/__init__.py
+++ b/saleor/payment/gateways/stripe/__init__.py
@@ -16,8 +16,10 @@ from .utils import (
def get_client_token(**_):
- """Not implemented for stripe gateway currently. The client token can be
- generated by Stripe's checkout.js or stripe.js automatically.
+ """Not implemented for Stripe gateway currently.
+
+ The client token can be automatically generated by
+ Stripe's checkout.js or stripe.js.
"""
return
diff --git a/saleor/payment/gateways/stripe/forms.py b/saleor/payment/gateways/stripe/forms.py
index e629213f24..93f8ea0ac3 100644
--- a/saleor/payment/gateways/stripe/forms.py
+++ b/saleor/payment/gateways/stripe/forms.py
@@ -60,7 +60,8 @@ class StripeCheckoutWidget(HiddenInput):
class StripePaymentModalForm(forms.Form):
- """
+ """The modal form of the Stripe payment provider.
+
At this moment partial-payment is not supported, but there is no need to
validate amount, which may be manually adjusted in the template,
since checkout.js can do that automatically.
diff --git a/saleor/payment/gateways/stripe/utils.py b/saleor/payment/gateways/stripe/utils.py
index 03523d4f91..7732dd9313 100644
--- a/saleor/payment/gateways/stripe/utils.py
+++ b/saleor/payment/gateways/stripe/utils.py
@@ -31,6 +31,7 @@ ZERO_DECIMAL_CURRENCIES = [
def get_amount_for_stripe(amount, currency):
"""Get appropriate amount for stripe.
+
Stripe is using currency's smallest unit such as cents for USD and
stripe requires integer instead of decimal, so multiplying by 100
and converting to integer is required. But for zero-decimal currencies,
@@ -60,6 +61,7 @@ def get_amount_from_stripe(amount, currency):
def get_currency_for_stripe(currency):
"""Convert Saleor's currency format to Stripe's currency format.
+
Stripe's currency is using lowercase while Saleor is using uppercase.
"""
return currency.lower()
@@ -67,6 +69,7 @@ def get_currency_for_stripe(currency):
def get_currency_from_stripe(currency):
"""Convert Stripe's currency format to Saleor's currency format.
+
Stripe's currency is using lowercase while Saleor is using uppercase.
"""
return currency.upper()
diff --git a/saleor/payment/interface.py b/saleor/payment/interface.py
index bc910b8b52..642d0e902e 100644
--- a/saleor/payment/interface.py
+++ b/saleor/payment/interface.py
@@ -5,9 +5,11 @@ from typing import Any, Dict, Optional
@dataclass
class GatewayResponse:
- """Dataclass for storing gateway response. Used for unifying the
- representation of gateway response. It is required to communicate between
- Saleor and given payment gateway."""
+ """Dataclass for storing gateway response.
+
+ Used for unifying the representation of gateway response.
+ It is required to communicate between Saleor and given payment gateway.
+ """
is_success: bool
kind: str
@@ -36,9 +38,11 @@ class AddressData:
@dataclass
class PaymentData:
- """Dataclass for storing all payment information. Used for unifying the
- representation of data. It is required to communicate between Saleor and
- given payment gateway."""
+ """Dataclass for storing all payment information.
+
+ Used for unifying the representation of data.
+ It is required to communicate between Saleor and given payment gateway.
+ """
amount: Decimal
currency: str
@@ -54,16 +58,18 @@ class PaymentData:
@dataclass
class TokenConfig:
- """Dataclass for payment gateway token fetching customization"""
+ """Dataclass for payment gateway token fetching customization."""
customer_id: Optional[str] = None
@dataclass
class GatewayConfig:
- """Dataclass for storing gateway config data. Used for unifying the
- representation of config data. It is required to communicate between
- Saleor and given payment gateway."""
+ """Dataclass for storing gateway config data.
+
+ Used for unifying the representation of config data.
+ It is required to communicate between Saleor and given payment gateway.
+ """
gateway_name: str
auto_capture: bool
@@ -76,7 +82,7 @@ class GatewayConfig:
@dataclass
class CreditCardInfo:
- """Uniform way to represent Credit Card information"""
+ """Uniform way to represent Credit Card information."""
last_4: str
exp_year: int
@@ -86,7 +92,7 @@ class CreditCardInfo:
@dataclass
class CustomerSource:
- """Dataclass for storing information about stored payment sources in gateways"""
+ """Dataclass for storing information about stored payment sources in gateways."""
id: str
gateway: str
diff --git a/saleor/payment/migrations/0001_initial.py b/saleor/payment/migrations/0001_initial.py
index c8bc91fbf4..980d3c47a4 100644
--- a/saleor/payment/migrations/0001_initial.py
+++ b/saleor/payment/migrations/0001_initial.py
@@ -1,12 +1,12 @@
# Generated by Django 2.1.2 on 2018-10-17 18:46
-import django.contrib.postgres.fields.jsonb
-from django.db import migrations, models
-import django.db.models.deletion
-import django_prices.models
-import saleor.core
from decimal import Decimal
+
+import django.contrib.postgres.fields.jsonb
import django.core.validators
+import django.db.models.deletion
+from django.db import migrations, models
+
import saleor.payment
diff --git a/saleor/payment/migrations/0003_rename_payment_method_to_payment.py b/saleor/payment/migrations/0003_rename_payment_method_to_payment.py
index a0eeb15e60..adb459d620 100644
--- a/saleor/payment/migrations/0003_rename_payment_method_to_payment.py
+++ b/saleor/payment/migrations/0003_rename_payment_method_to_payment.py
@@ -1,9 +1,7 @@
# Generated by Django 2.1.2 on 2018-10-20 16:41
-from django.db import migrations, models
import django.db.models.deletion
-import django_prices.models
-import saleor.core
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py b/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py
index 61e9b18886..4729842144 100644
--- a/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py
+++ b/saleor/payment/migrations/0009_convert_to_partially_charged_and_partially_refunded.py
@@ -4,7 +4,6 @@ from django.db import migrations
from saleor.payment import ChargeStatus, TransactionKind
-
CHARGED = "charged"
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 7fb2582e29..1956b61169 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -69,7 +69,7 @@ def create_payment_information(
customer_id: str = None,
store_source: bool = False,
) -> PaymentData:
- """Extracts order information along with payment details.
+ """Extract order information along with payment details.
Returns information required to process payment and additional
billing/shipping addresses for optional fraud-prevention mechanisms.
@@ -214,7 +214,6 @@ def create_transaction(
error_msg=None,
) -> Transaction:
"""Create a transaction based on transaction kind and gateway response."""
-
# Default values for token, amount, currency are only used in cases where
# response from gateway was invalid or an exception occured
if not gateway_response:
@@ -243,8 +242,10 @@ def create_transaction(
def gateway_get_client_token(gateway_name: str, token_config: TokenConfig = None):
- """Gets client token, that will be used as a customer's identificator for
- client-side tokenization of the chosen payment method.
+ """Get a client token.
+
+ That will be used as a customer's identificator for client-side tokenization
+ of the chosen payment method.
"""
if not token_config:
token_config = TokenConfig()
@@ -280,7 +281,7 @@ def clean_mark_order_as_paid(order: Order):
def call_gateway(operation_type, payment, payment_token, **extra_params):
- """Helper that calls the passed gateway function and handles exceptions.
+ """Call the passed gateway function and handle exceptions.
Additionally does validation of the returned gateway response.
"""
@@ -346,8 +347,7 @@ def call_gateway(operation_type, payment, payment_token, **extra_params):
def validate_gateway_response(response: GatewayResponse):
- """Validates response to be a correct format for Saleor to process."""
-
+ """Validate response to be a correct format for Saleor to process."""
if not isinstance(response, GatewayResponse):
raise GatewayError("Gateway needs to return a GatewayResponse obj")
@@ -404,7 +404,7 @@ def _gateway_postprocess(transaction, payment):
def gateway_process_payment(
payment: Payment, payment_token: str, **extras
) -> Transaction:
- """Performs whole payment process on a gateway."""
+ """Perform the whole payment process on a gateway."""
transaction = call_gateway(
operation_type=OperationType.PROCESS_PAYMENT,
payment=payment,
@@ -419,10 +419,12 @@ def gateway_process_payment(
@require_active_payment
def gateway_authorize(payment: Payment, payment_token: str) -> Transaction:
- """Authorizes the payment and creates relevant transaction.
+ """Authorize the payment and create a relevant transaction.
Args:
- - payment_token: One-time-use reference to payment information.
+ payment: the payment to process.
+ payment_token: One-time-use reference to payment information.
+
"""
clean_authorize(payment)
@@ -433,7 +435,7 @@ def gateway_authorize(payment: Payment, payment_token: str) -> Transaction:
@require_active_payment
def gateway_capture(payment: Payment, amount: Decimal = None) -> Transaction:
- """Captures the money that was reserved during the authorization stage."""
+ """Capture the money that was reserved during the authorization stage."""
if amount is None:
amount = payment.get_charge_amount()
clean_capture(payment, amount)
@@ -478,7 +480,8 @@ def gateway_void(payment) -> Transaction:
@require_active_payment
def gateway_refund(payment, amount: Decimal = None) -> Transaction:
- """Refunds the charged funds back to the customer.
+ """Refund the charged funds back to the customer.
+
Refunds can be total or partial.
"""
if amount is None:
@@ -512,7 +515,7 @@ def gateway_refund(payment, amount: Decimal = None) -> Transaction:
def fetch_customer_id(user, gateway):
- """Retrieves users customer_id stored for desired gateway"""
+ """Retrieve users customer_id stored for desired gateway."""
key = prepare_namespace_name(gateway)
gateway_config = user.get_private_meta(
namespace=GATEWAYS_META_NAMESPACE, client=key
@@ -521,7 +524,7 @@ def fetch_customer_id(user, gateway):
def store_customer_id(user, gateway, customer_id):
- """Stores customer_id in users private meta for desired gateway"""
+ """Store customer_id in users private meta for desired gateway."""
user.store_private_meta(
namespace=GATEWAYS_META_NAMESPACE,
client=prepare_namespace_name(gateway),
@@ -535,6 +538,6 @@ def prepare_namespace_name(s):
def retrieve_customer_sources(gateway_name, customer_id):
- """ Fetches all customer payment sources stored in gateway"""
+ """Fetch all customer payment sources stored in gateway."""
gateway, config = get_payment_gateway(gateway_name)
return gateway.list_client_sources(config, customer_id)
diff --git a/saleor/product/migrations/0001_initial.py b/saleor/product/migrations/0001_initial.py
index 3ac6480a0d..a57e837e62 100644
--- a/saleor/product/migrations/0001_initial.py
+++ b/saleor/product/migrations/0001_initial.py
@@ -3,11 +3,11 @@ from __future__ import unicode_literals
from decimal import Decimal
-from django.db import models, migrations
-from django.conf import settings
-import versatileimagefield.fields
import django.core.validators
import django_prices.models
+import versatileimagefield.fields
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0002_auto_20150722_0545.py b/saleor/product/migrations/0002_auto_20150722_0545.py
index 8a4fb1a4be..fadf6ec473 100644
--- a/saleor/product/migrations/0002_auto_20150722_0545.py
+++ b/saleor/product/migrations/0002_auto_20150722_0545.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0003_auto_20150820_1955.py b/saleor/product/migrations/0003_auto_20150820_1955.py
index 0db4608026..0adefbec86 100644
--- a/saleor/product/migrations/0003_auto_20150820_1955.py
+++ b/saleor/product/migrations/0003_auto_20150820_1955.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0003_auto_20150820_2016.py b/saleor/product/migrations/0003_auto_20150820_2016.py
index b9be30ad38..0ccd5f93d2 100644
--- a/saleor/product/migrations/0003_auto_20150820_2016.py
+++ b/saleor/product/migrations/0003_auto_20150820_2016.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0004_merge.py b/saleor/product/migrations/0004_merge.py
index 31caa9570e..c2d351289d 100644
--- a/saleor/product/migrations/0004_merge.py
+++ b/saleor/product/migrations/0004_merge.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0005_auto_20150825_1433.py b/saleor/product/migrations/0005_auto_20150825_1433.py
index a4853f0932..fd6a6f53e8 100644
--- a/saleor/product/migrations/0005_auto_20150825_1433.py
+++ b/saleor/product/migrations/0005_auto_20150825_1433.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
-from django.db import models, migrations
-from django.conf import settings
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0007_auto_20160112_1025.py b/saleor/product/migrations/0007_auto_20160112_1025.py
index 9613476f7a..e83e031f42 100644
--- a/saleor/product/migrations/0007_auto_20160112_1025.py
+++ b/saleor/product/migrations/0007_auto_20160112_1025.py
@@ -2,7 +2,7 @@
# Generated by Django 1.9.1 on 2016-01-12 16:25
from __future__ import unicode_literals
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0008_auto_20160114_0733.py b/saleor/product/migrations/0008_auto_20160114_0733.py
index 4fd16c0cd2..1b54875a37 100644
--- a/saleor/product/migrations/0008_auto_20160114_0733.py
+++ b/saleor/product/migrations/0008_auto_20160114_0733.py
@@ -29,7 +29,10 @@ class Migration(migrations.Migration):
field=models.DecimalField(
decimal_places=2,
default=0,
- help_text="Value for a discount. It could be fixed amount or percentage value in range 0-100",
+ help_text=(
+ "Value for a discount. It could be fixed amount or "
+ "percentage value in range 0-100"
+ ),
max_digits=12,
),
),
diff --git a/saleor/product/migrations/0011_stock_quantity_allocated.py b/saleor/product/migrations/0011_stock_quantity_allocated.py
index b4af7b7900..f6d07059ea 100644
--- a/saleor/product/migrations/0011_stock_quantity_allocated.py
+++ b/saleor/product/migrations/0011_stock_quantity_allocated.py
@@ -3,6 +3,7 @@
from __future__ import unicode_literals
from decimal import Decimal
+
import django.core.validators
from django.db import migrations, models
diff --git a/saleor/product/migrations/0012_auto_20160218_0812.py b/saleor/product/migrations/0012_auto_20160218_0812.py
index 8a84fd7964..8d7d3bfeb0 100644
--- a/saleor/product/migrations/0012_auto_20160218_0812.py
+++ b/saleor/product/migrations/0012_auto_20160218_0812.py
@@ -2,8 +2,8 @@
# Generated by Django 1.9.1 on 2016-02-18 14:12
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0013_auto_20161130_0608.py b/saleor/product/migrations/0013_auto_20161130_0608.py
index f24878e8d5..2186e55767 100644
--- a/saleor/product/migrations/0013_auto_20161130_0608.py
+++ b/saleor/product/migrations/0013_auto_20161130_0608.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.3 on 2016-11-30 12:08
from __future__ import unicode_literals
-from django.db import migrations
from django.contrib.postgres.operations import HStoreExtension
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0013_auto_20161207_0555.py b/saleor/product/migrations/0013_auto_20161207_0555.py
index d0296e6fb0..c68077ab91 100644
--- a/saleor/product/migrations/0013_auto_20161207_0555.py
+++ b/saleor/product/migrations/0013_auto_20161207_0555.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.3 on 2016-12-07 11:55
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0019_auto_20161212_0230.py b/saleor/product/migrations/0019_auto_20161212_0230.py
index 7efe5b0601..06476ecd81 100644
--- a/saleor/product/migrations/0019_auto_20161212_0230.py
+++ b/saleor/product/migrations/0019_auto_20161212_0230.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.3 on 2016-12-12 08:30
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0020_attribute_data_to_class.py b/saleor/product/migrations/0020_attribute_data_to_class.py
index e24bcc320a..048c4bb379 100644
--- a/saleor/product/migrations/0020_attribute_data_to_class.py
+++ b/saleor/product/migrations/0020_attribute_data_to_class.py
@@ -1,6 +1,6 @@
from __future__ import unicode_literals
-from django.db import migrations, models
+from django.db import migrations
def move_data(apps, schema_editor):
diff --git a/saleor/product/migrations/0021_add_hstore_extension.py b/saleor/product/migrations/0021_add_hstore_extension.py
index 6a7f3b0f02..a96f7f0e9f 100644
--- a/saleor/product/migrations/0021_add_hstore_extension.py
+++ b/saleor/product/migrations/0021_add_hstore_extension.py
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
-from django.db import migrations
from django.contrib.postgres.operations import HStoreExtension
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0022_auto_20161212_0301.py b/saleor/product/migrations/0022_auto_20161212_0301.py
index 57732fa923..5c0fd51695 100644
--- a/saleor/product/migrations/0022_auto_20161212_0301.py
+++ b/saleor/product/migrations/0022_auto_20161212_0301.py
@@ -3,8 +3,8 @@
from __future__ import unicode_literals
import django.contrib.postgres.fields.hstore
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0023_auto_20161211_1912.py b/saleor/product/migrations/0023_auto_20161211_1912.py
index 29b6b708bd..b63f6332db 100644
--- a/saleor/product/migrations/0023_auto_20161211_1912.py
+++ b/saleor/product/migrations/0023_auto_20161211_1912.py
@@ -3,7 +3,7 @@
from __future__ import unicode_literals
import django.contrib.postgres.fields.hstore
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0025_auto_20161219_0517.py b/saleor/product/migrations/0025_auto_20161219_0517.py
index 71fdc7bb97..8655a132e3 100644
--- a/saleor/product/migrations/0025_auto_20161219_0517.py
+++ b/saleor/product/migrations/0025_auto_20161219_0517.py
@@ -2,7 +2,7 @@
# Generated by Django 1.10.3 on 2016-12-19 11:17
from __future__ import unicode_literals
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0030_auto_20170206_0407.py b/saleor/product/migrations/0030_auto_20170206_0407.py
index 1c40e97cc8..143c053b3b 100644
--- a/saleor/product/migrations/0030_auto_20170206_0407.py
+++ b/saleor/product/migrations/0030_auto_20170206_0407.py
@@ -2,9 +2,9 @@
# Generated by Django 1.10.5 on 2017-02-06 10:07
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
import versatileimagefield.fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0041_auto_20171205_0546.py b/saleor/product/migrations/0041_auto_20171205_0546.py
index 9bdaa785e7..3e352cc42d 100644
--- a/saleor/product/migrations/0041_auto_20171205_0546.py
+++ b/saleor/product/migrations/0041_auto_20171205_0546.py
@@ -2,7 +2,7 @@
# Generated by Django 1.11.5 on 2017-12-05 11:46
from __future__ import unicode_literals
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0044_auto_20180108_0814.py b/saleor/product/migrations/0044_auto_20180108_0814.py
index 538a380ced..4110e44d08 100644
--- a/saleor/product/migrations/0044_auto_20180108_0814.py
+++ b/saleor/product/migrations/0044_auto_20180108_0814.py
@@ -5,12 +5,12 @@ from __future__ import unicode_literals
from decimal import Decimal
import django.contrib.postgres.fields.hstore
-from django.conf import settings
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
import versatileimagefield.fields
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0046_product_category.py b/saleor/product/migrations/0046_product_category.py
index 2276c96c6f..de14f611a3 100644
--- a/saleor/product/migrations/0046_product_category.py
+++ b/saleor/product/migrations/0046_product_category.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.9 on 2018-01-16 11:56
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
def assign_category_to_products(apps, schema_editor):
diff --git a/saleor/product/migrations/0047_auto_20180117_0359.py b/saleor/product/migrations/0047_auto_20180117_0359.py
index c3a32527b9..df4b7541be 100644
--- a/saleor/product/migrations/0047_auto_20180117_0359.py
+++ b/saleor/product/migrations/0047_auto_20180117_0359.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.9 on 2018-01-17 09:59
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0053_auto_20180305_1002.py b/saleor/product/migrations/0053_auto_20180305_1002.py
index 4b9348cc52..a7574ee270 100644
--- a/saleor/product/migrations/0053_auto_20180305_1002.py
+++ b/saleor/product/migrations/0053_auto_20180305_1002.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.2 on 2018-03-05 16:02
-from django.db import migrations
import versatileimagefield.fields
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0053_product_seo_description.py b/saleor/product/migrations/0053_product_seo_description.py
index 2e179350d6..596388b5cd 100644
--- a/saleor/product/migrations/0053_product_seo_description.py
+++ b/saleor/product/migrations/0053_product_seo_description.py
@@ -3,6 +3,7 @@ import html
from django.core.validators import MaxLengthValidator
from django.db import migrations, models
+
from saleor.core.utils.text import strip_html_and_truncate
diff --git a/saleor/product/migrations/0058_auto_20180329_0142.py b/saleor/product/migrations/0058_auto_20180329_0142.py
index e62ffb86c0..af7560b662 100644
--- a/saleor/product/migrations/0058_auto_20180329_0142.py
+++ b/saleor/product/migrations/0058_auto_20180329_0142.py
@@ -1,10 +1,11 @@
# Generated by Django 2.0.3 on 2018-03-29 06:42
-from django.conf import settings
from decimal import Decimal
+
import django.core.validators
-from django.db import migrations, models
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0066_auto_20180803_0528.py b/saleor/product/migrations/0066_auto_20180803_0528.py
index 57ebba7e79..6050bb35e5 100644
--- a/saleor/product/migrations/0066_auto_20180803_0528.py
+++ b/saleor/product/migrations/0066_auto_20180803_0528.py
@@ -1,8 +1,8 @@
# Generated by Django 2.0.3 on 2018-08-03 10:28
import django.core.validators
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0068_auto_20180822_0720.py b/saleor/product/migrations/0068_auto_20180822_0720.py
index 07a2e48ea8..dd98258222 100644
--- a/saleor/product/migrations/0068_auto_20180822_0720.py
+++ b/saleor/product/migrations/0068_auto_20180822_0720.py
@@ -1,7 +1,8 @@
# Generated by Django 2.0.3 on 2018-08-22 12:20
-from django.db import migrations
import django_measurement.models
+from django.db import migrations
+
import saleor.core.weight
diff --git a/saleor/product/migrations/0073_auto_20181010_0729.py b/saleor/product/migrations/0073_auto_20181010_0729.py
index f9f6bebf78..810f59ed95 100644
--- a/saleor/product/migrations/0073_auto_20181010_0729.py
+++ b/saleor/product/migrations/0073_auto_20181010_0729.py
@@ -1,7 +1,7 @@
# Generated by Django 2.1.2 on 2018-10-10 12:29
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0075_auto_20181010_0842.py b/saleor/product/migrations/0075_auto_20181010_0842.py
index dd3743f364..49ed99a39c 100644
--- a/saleor/product/migrations/0075_auto_20181010_0842.py
+++ b/saleor/product/migrations/0075_auto_20181010_0842.py
@@ -1,7 +1,7 @@
# Generated by Django 2.1.2 on 2018-10-10 13:42
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0086_product_publication_date.py b/saleor/product/migrations/0086_product_publication_date.py
index 90fc63af45..ba1fb27c10 100644
--- a/saleor/product/migrations/0086_product_publication_date.py
+++ b/saleor/product/migrations/0086_product_publication_date.py
@@ -1,6 +1,6 @@
# Generated by Django 2.1.5 on 2019-02-05 11:31
-from django.db import migrations, models
+from django.db import migrations
class Migration(migrations.Migration):
diff --git a/saleor/product/migrations/0096_auto_20190719_0339.py b/saleor/product/migrations/0096_auto_20190719_0339.py
index 266aa6caae..ca26f5d2fa 100644
--- a/saleor/product/migrations/0096_auto_20190719_0339.py
+++ b/saleor/product/migrations/0096_auto_20190719_0339.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/product/migrations/0097_auto_20190719_0458.py b/saleor/product/migrations/0097_auto_20190719_0458.py
index f2cb4f0cbf..7422994fe9 100644
--- a/saleor/product/migrations/0097_auto_20190719_0458.py
+++ b/saleor/product/migrations/0097_auto_20190719_0458.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/product/migrations/0098_auto_20190719_0733.py b/saleor/product/migrations/0098_auto_20190719_0733.py
index 2219435a9d..d170d3e9b1 100644
--- a/saleor/product/migrations/0098_auto_20190719_0733.py
+++ b/saleor/product/migrations/0098_auto_20190719_0733.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/product/migrations/0099_auto_20190719_0745.py b/saleor/product/migrations/0099_auto_20190719_0745.py
index e39567cb54..94b29a26d5 100644
--- a/saleor/product/migrations/0099_auto_20190719_0745.py
+++ b/saleor/product/migrations/0099_auto_20190719_0745.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/product/migrations/0101_auto_20190719_0839.py b/saleor/product/migrations/0101_auto_20190719_0839.py
index ddb95d6f1c..4b5d40365d 100644
--- a/saleor/product/migrations/0101_auto_20190719_0839.py
+++ b/saleor/product/migrations/0101_auto_20190719_0839.py
@@ -2,6 +2,7 @@
import django.contrib.postgres.fields.jsonb
from django.db import migrations
+
import saleor.core.utils.json_serializer
diff --git a/saleor/product/models.py b/saleor/product/models.py
index a308c04957..1d61b9363a 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -291,8 +291,9 @@ class ProductVariant(ModelWithMetadata):
return self.product.is_available
def check_quantity(self, quantity):
- """Check if there is at least the given quantity in stock
- if stock handling is enabled.
+ """Check if there is at least the given quantity in stock.
+
+ If stock handling is disabled, it simply run no check.
"""
if self.track_inventory and quantity > self.quantity_available:
raise InsufficientStock(self)
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index e368261deb..df0c2143b7 100644
--- a/saleor/product/tasks.py
+++ b/saleor/product/tasks.py
@@ -5,8 +5,10 @@ from .utils.attributes import get_name_from_attributes
def _update_variants_names(instance, saved_attributes):
"""Product variant names are created from names of assigned attributes.
+
After change in attribute value name, for all product variants using this
- attributes we need to update the names."""
+ attributes we need to update the names.
+ """
initial_attributes = set(instance.variant_attributes.all())
attributes_changed = initial_attributes.intersection(saved_attributes)
if not attributes_changed:
diff --git a/saleor/product/templatetags/product_images.py b/saleor/product/templatetags/product_images.py
index 98e85e7885..24d205bca8 100644
--- a/saleor/product/templatetags/product_images.py
+++ b/saleor/product/templatetags/product_images.py
@@ -54,8 +54,9 @@ def get_available_sizes_by_method(method, rendition_key_set):
def get_thumbnail_size(size, method, rendition_key_set):
- """ Return closest larger size if not more than 2 times larger, otherwise
- return closest smaller size
+ """Return the closest larger size if not more than 2 times larger.
+
+ Otherwise, return the closest smaller size
"""
on_demand = settings.VERSATILEIMAGEFIELD_SETTINGS["create_images_on_demand"]
if isinstance(size, int):
diff --git a/saleor/product/thumbnails.py b/saleor/product/thumbnails.py
index b6a42c1cac..03519ad887 100644
--- a/saleor/product/thumbnails.py
+++ b/saleor/product/thumbnails.py
@@ -5,14 +5,13 @@ from .models import Category, Collection, ProductImage
@app.task
def create_product_thumbnails(image_id):
- """Takes a ProductImage model, and creates thumbnails for it."""
+ """Take a ProductImage model and create thumbnails for it."""
create_thumbnails(pk=image_id, model=ProductImage, size_set="products")
@app.task
def create_category_background_image_thumbnails(category_id):
- """Takes a Product model,
- and creates the background image thumbnails for it."""
+ """Take a Product model and create the background image thumbnails for it."""
create_thumbnails(
pk=category_id,
model=Category,
@@ -23,8 +22,7 @@ def create_category_background_image_thumbnails(category_id):
@app.task
def create_collection_background_image_thumbnails(collection_id):
- """Takes a Collection model,
- and creates the background image thumbnails for it."""
+ """Take a Collection model and create the background image thumbnails for it."""
create_thumbnails(
pk=collection_id,
model=Collection,
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index 7cf81a54a3..0385ac6c7c 100644
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -121,7 +121,8 @@ def increase_stock(variant, quantity, allocate=False):
def get_product_list_context(request, filter_set):
- """
+ """Build a context from the given filter set.
+
:param request: request object
:param filter_set: filter set for product list
:return: context dictionary
diff --git a/saleor/product/utils/attributes.py b/saleor/product/utils/attributes.py
index cb793db7b5..477ae396be 100644
--- a/saleor/product/utils/attributes.py
+++ b/saleor/product/utils/attributes.py
@@ -1,6 +1,7 @@
def get_product_attributes_data(product):
- """Returns attributes associated with the product,
- as dict of Attribute: AttributeValue values.
+ """Return the attributes associated with the product.
+
+ It is returned as a dict of Attribute: AttributeValue values.
"""
attributes = product.product_type.product_attributes.all()
attributes_map = {attribute.pk: attribute.translated for attribute in attributes}
@@ -12,17 +13,18 @@ def get_product_attributes_data(product):
def get_name_from_attributes(variant, attributes):
- """Generates ProductVariant's name based on its attributes."""
+ """Generate ProductVariant's name based on its attributes."""
values = get_attributes_display_map(variant, attributes)
return generate_name_from_values(values)
def get_attributes_display_map(obj, attributes):
- """Returns attributes associated with an object,
- as dict of Attribute: AttributeValue values.
+ """Return attributes associated with an object, as dict of AttrPK: AttributeValue.
Args:
+ obj: The variant or product.
attributes: Attribute Iterable
+
"""
display_map = {}
for attribute in attributes:
@@ -34,11 +36,13 @@ def get_attributes_display_map(obj, attributes):
def generate_name_from_values(attributes_dict):
- """Generates name from AttributeValues. Attributes dict is sorted,
- as attributes order should be kept within each save.
+ """Generate name from AttributeValues.
+
+ Attributes dict is sorted, as attributes order should be kept within each save.
Args:
attributes_dict: dict of attribute_pk: AttributeValue values
+
"""
return " / ".join(
str(attribute_value)
diff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.py
index e1977fa606..5a8791cbe1 100644
--- a/saleor/product/utils/availability.py
+++ b/saleor/product/utils/availability.py
@@ -85,8 +85,11 @@ def _get_total_discount(
undiscounted: Union[MoneyRange, TaxedMoneyRange, Decimal],
discounted: Union[MoneyRange, TaxedMoneyRange, Decimal],
):
- """Subtracts two prices that are whether a price range or decimal prices
- and return their total discount, if any. Otherwise, it returns None."""
+ """Calculate the discount amount between two amounts.
+
+ Subtract two prices that are whether a price range or decimal prices
+ and return their total discount, if any. Otherwise, it returns None.
+ """
if not isinstance(undiscounted, (MoneyRange, TaxedMoneyRange)):
if undiscounted > discounted:
return undiscounted - discounted
diff --git a/saleor/product/utils/digital_products.py b/saleor/product/utils/digital_products.py
index 259a1b4c62..5647ff2d84 100644
--- a/saleor/product/utils/digital_products.py
+++ b/saleor/product/utils/digital_products.py
@@ -18,8 +18,11 @@ def get_default_digital_content_settings():
def digital_content_url_is_valid(content_url: DigitalContentUrl) -> bool:
- """ Check if digital url is still valid for customer. It takes default
- settings or digital product's settings to check if url is still valid"""
+ """Check if digital url is still valid for customer.
+
+ It takes default settings or digital product's settings
+ to check if url is still valid.
+ """
if content_url.content.use_default_settings:
digital_content_settings = get_default_digital_content_settings()
url_valid_days = digital_content_settings["url_valid_days"]
diff --git a/saleor/product/views.py b/saleor/product/views.py
index 4c1fb9b8a3..9cf61a9469 100644
--- a/saleor/product/views.py
+++ b/saleor/product/views.py
@@ -116,7 +116,7 @@ def product_details(request, slug, product_id, form=None):
def digital_product(request, token: str) -> Union[FileResponse, HttpResponseNotFound]:
- """Returns direct download link to content if given token is still valid"""
+ """Return the direct download link to content if given token is still valid."""
qs = DigitalContentUrl.objects.prefetch_related("line__order__user")
content_url = get_object_or_404(qs, token=token) # type: DigitalContentUrl
diff --git a/saleor/search/backends/elasticsearch_dashboard.py b/saleor/search/backends/elasticsearch_dashboard.py
index bbd0c13941..c0e81e104e 100644
--- a/saleor/search/backends/elasticsearch_dashboard.py
+++ b/saleor/search/backends/elasticsearch_dashboard.py
@@ -32,6 +32,7 @@ def get_search_queries(phrase):
Args:
phrase (str): searched phrase
+
"""
return {
"products": _search_products(phrase),
@@ -47,5 +48,6 @@ def search(phrase):
Args:
phrase (str): searched phrase
+
"""
return {k: s.to_queryset() for k, s in get_search_queries(phrase).items()}
diff --git a/saleor/search/backends/postgresql_dashboard.py b/saleor/search/backends/postgresql_dashboard.py
index 58f4ea0102..90bdee8bb0 100644
--- a/saleor/search/backends/postgresql_dashboard.py
+++ b/saleor/search/backends/postgresql_dashboard.py
@@ -55,6 +55,7 @@ def search(phrase):
Args:
phrase (str): searched phrase
+
"""
return {
"products": search_products(phrase),
diff --git a/saleor/search/backends/test_elasticsearch_dashboard.py b/saleor/search/backends/test_elasticsearch_dashboard.py
index e95d11b8b6..45afec8096 100644
--- a/saleor/search/backends/test_elasticsearch_dashboard.py
+++ b/saleor/search/backends/test_elasticsearch_dashboard.py
@@ -35,7 +35,7 @@ USERS_QUERY = {
def test_dashboard_search_query_syntax():
- """ Check if generated ES queries have desired syntax """
+ """Check if generated ES queries have desired syntax."""
searches = elasticsearch_dashboard.get_search_queries(PHRASE)
assert PRODUCT_QUERY == searches["products"].to_dict()
assert ORDERS_QUERY == searches["orders"].to_dict()
diff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.py
index e9bbc11c67..e725a227bc 100644
--- a/saleor/seo/schema/email.py
+++ b/saleor/seo/schema/email.py
@@ -38,7 +38,7 @@ def get_product_data(line, organization):
def get_order_confirmation_markup(order):
- """Generates schema.org markup for order confirmation e-mail message."""
+ """Generate schema.org markup for order confirmation e-mail message."""
organization = get_organization()
order_url = build_absolute_uri(order.get_absolute_url())
data = {
diff --git a/saleor/shipping/migrations/0001_initial.py b/saleor/shipping/migrations/0001_initial.py
index 8669ddb0fb..83fe4f91f1 100644
--- a/saleor/shipping/migrations/0001_initial.py
+++ b/saleor/shipping/migrations/0001_initial.py
@@ -2,10 +2,10 @@
# Generated by Django 1.9.1 on 2016-01-19 10:18
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.manager
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/shipping/migrations/0004_auto_20170206_0407.py b/saleor/shipping/migrations/0004_auto_20170206_0407.py
index c79ba01ca2..febf3c799d 100644
--- a/saleor/shipping/migrations/0004_auto_20170206_0407.py
+++ b/saleor/shipping/migrations/0004_auto_20170206_0407.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.5 on 2017-02-06 10:07
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/shipping/migrations/0008_auto_20180108_0814.py b/saleor/shipping/migrations/0008_auto_20180108_0814.py
index 834f277583..c6c9e2a360 100644
--- a/saleor/shipping/migrations/0008_auto_20180108_0814.py
+++ b/saleor/shipping/migrations/0008_auto_20180108_0814.py
@@ -2,10 +2,10 @@
# Generated by Django 1.11.5 on 2018-01-08 14:14
from __future__ import unicode_literals
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/shipping/migrations/0012_remove_legacy_shipping_methods.py b/saleor/shipping/migrations/0012_remove_legacy_shipping_methods.py
index f2ccac3e73..ca0571e288 100644
--- a/saleor/shipping/migrations/0012_remove_legacy_shipping_methods.py
+++ b/saleor/shipping/migrations/0012_remove_legacy_shipping_methods.py
@@ -1,11 +1,6 @@
# Generated by Django 2.0.3 on 2018-08-22 12:20
-from django.db import migrations, models
-import django.db.models.deletion
-import django_countries.fields
-import django_measurement.models
-import django_prices.models
-import saleor.core.weight
+from django.db import migrations
def remove_legacy_shipping_methods(apps, schema_editor):
diff --git a/saleor/shipping/migrations/0013_auto_20180822_0721.py b/saleor/shipping/migrations/0013_auto_20180822_0721.py
index 1e0ebed547..2f3c8f198b 100644
--- a/saleor/shipping/migrations/0013_auto_20180822_0721.py
+++ b/saleor/shipping/migrations/0013_auto_20180822_0721.py
@@ -1,11 +1,12 @@
# Generated by Django 2.0.3 on 2018-08-22 12:20
-from django.conf import settings
-from django.db import migrations, models
import django.db.models.deletion
import django_countries.fields
import django_measurement.models
import django_prices.models
+from django.conf import settings
+from django.db import migrations, models
+
import saleor.core.weight
diff --git a/saleor/shipping/migrations/0014_auto_20180920_0956.py b/saleor/shipping/migrations/0014_auto_20180920_0956.py
index 427ead4643..8f40b656e8 100644
--- a/saleor/shipping/migrations/0014_auto_20180920_0956.py
+++ b/saleor/shipping/migrations/0014_auto_20180920_0956.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.8 on 2018-09-20 14:56
-from django.db import migrations, models
import django_countries.fields
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index b950a62c50..e557fb5581 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -25,9 +25,7 @@ from . import ShippingMethodType
def _applicable_weight_based_methods(weight, qs):
- """Returns weight based ShippingMethods that can be applied to an order
- with given total weight.
- """
+ """Return weight based shipping methods that are applicable for the total weight."""
qs = qs.weight_based()
min_weight_matched = Q(minimum_order_weight__lte=weight)
no_weight_limit = Q(maximum_order_weight__isnull=True)
@@ -36,9 +34,7 @@ def _applicable_weight_based_methods(weight, qs):
def _applicable_price_based_methods(price, qs):
- """Returns price based ShippingMethods that can be applied to an order
- with given price total.
- """
+ """Return price based shipping methods that are applicable for the given total."""
qs = qs.price_based()
min_price_matched = Q(minimum_order_price__lte=price)
no_price_limit = Q(maximum_order_price__isnull=True)
@@ -125,9 +121,10 @@ class ShippingMethodQueryset(models.QuerySet):
return self.filter(type=ShippingMethodType.WEIGHT_BASED)
def applicable_shipping_methods(self, price, weight, country_code):
- """Returns ShippingMethods that can be used on an order with
- shipment to given country(code), that are applicable to given
- price & weight total.
+ """Return the ShippingMethods that can be used on an order with shipment.
+
+ It is based on the given country code, and by shipping methods that are
+ applicable to the given price & weight total.
"""
# If dedicated shipping zone for the country exists, we should use it
# in the first place
diff --git a/saleor/site/migrations/0002_add_default_data.py b/saleor/site/migrations/0002_add_default_data.py
index e4a0423c32..2f91920bcc 100644
--- a/saleor/site/migrations/0002_add_default_data.py
+++ b/saleor/site/migrations/0002_add_default_data.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.5 on 2017-01-27 11:41
from __future__ import unicode_literals
-from django.db import migrations
from django.conf import settings
+from django.db import migrations
def create_default_site(apps, schema_editor):
diff --git a/saleor/site/migrations/0004_auto_20170221_0426.py b/saleor/site/migrations/0004_auto_20170221_0426.py
index 0b6a20dd55..36f16d27ed 100644
--- a/saleor/site/migrations/0004_auto_20170221_0426.py
+++ b/saleor/site/migrations/0004_auto_20170221_0426.py
@@ -2,8 +2,8 @@
# Generated by Django 1.10.5 on 2017-02-21 10:26
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/site/migrations/0006_auto_20171025_0454.py b/saleor/site/migrations/0006_auto_20171025_0454.py
index f6c1c4e1ad..6464e880ac 100644
--- a/saleor/site/migrations/0006_auto_20171025_0454.py
+++ b/saleor/site/migrations/0006_auto_20171025_0454.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.5 on 2017-10-25 09:54
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/site/migrations/0008_auto_20171027_0856.py b/saleor/site/migrations/0008_auto_20171027_0856.py
index 4027d25d6b..b73482ca22 100644
--- a/saleor/site/migrations/0008_auto_20171027_0856.py
+++ b/saleor/site/migrations/0008_auto_20171027_0856.py
@@ -2,8 +2,8 @@
# Generated by Django 1.11.5 on 2017-10-27 13:56
from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/site/migrations/0012_auto_20180405_0757.py b/saleor/site/migrations/0012_auto_20180405_0757.py
index ae42677859..390e6af43b 100644
--- a/saleor/site/migrations/0012_auto_20180405_0757.py
+++ b/saleor/site/migrations/0012_auto_20180405_0757.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.3 on 2018-04-05 12:57
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/site/migrations/0017_auto_20180803_0528.py b/saleor/site/migrations/0017_auto_20180803_0528.py
index dc69e69080..6c2b4d05a2 100644
--- a/saleor/site/migrations/0017_auto_20180803_0528.py
+++ b/saleor/site/migrations/0017_auto_20180803_0528.py
@@ -1,7 +1,7 @@
# Generated by Django 2.0.3 on 2018-08-03 10:28
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/saleor/site/migrations/0018_sitesettings_homepage_collection.py b/saleor/site/migrations/0018_sitesettings_homepage_collection.py
index a1426d95f9..78a316a1a6 100644
--- a/saleor/site/migrations/0018_sitesettings_homepage_collection.py
+++ b/saleor/site/migrations/0018_sitesettings_homepage_collection.py
@@ -2,10 +2,10 @@
import datetime
+import django.db.models.deletion
from django.db import migrations, models
from django.db.models import Q
from django.utils.text import slugify
-import django.db.models.deletion
def copy_featured_products_to_homepade_collection(apps, schema_editor):
diff --git a/setup.cfg b/setup.cfg
index df7e7cf5b0..9ced48ae72 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -44,10 +44,9 @@ ignore = H101,H238,H301,H306,W503
max-line-length = 88
[pydocstyle]
-ignore = D100, D101, D102, D103, D104, D105, D106, D107, D203, D213
+ignore = D100, D101, D102, D103, D104, D105, D106, D107, D203, D213, D407, D202
inherit = false
-match-dir = (?!migrations)[^\.].*
-max-line-length = 88
+match-dir = saleor
[isort]
skip =
diff --git a/tox.ini b/tox.ini
index a7cd023f65..0d27dc9d8c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,6 +30,14 @@ deps =
commands =
flake8 saleor tests
+[testenv:pydocstyle]
+basepython = python3.6
+whitelist_externals = find
+deps =
+ pydocstyle>=4.0.0
+commands =
+ pydocstyle $(find saleor -name '*.py' -type f) -v
+
[testenv:check_gql_schema]
basepython = python3.6
whitelist_externals = sh