Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove unused code
IKarbowiakb3ffb0315c08
diff --git a/saleor/account/models.py b/saleor/account/models.pyindex 584b4e6701..4be962aa1b 100644--- a/saleor/account/models.py+++ b/saleor/account/models.py@@ -181,12 +181,6 @@ class User(PermissionsMixin, ModelWithMetadata, AbstractBaseUser):def get_short_name(self):return self.email- def get_ajax_label(self):- address = self.default_billing_address- if address:- return "%s %s (%s)" % (address.first_name, address.last_name, self.email)- return self.email-class ServiceAccount(ModelWithMetadata):name = models.CharField(max_length=60)diff --git a/saleor/core/templatetags/version.py b/saleor/core/templatetags/version.pydeleted file mode 100644index 5eca41e3ea..0000000000--- a/saleor/core/templatetags/version.py+++ /dev/null@@ -1,10 +0,0 @@-from django.template import Library--from ... import __version__--register = Library()---def version():- return __version__diff --git a/saleor/core/utils/text.py b/saleor/core/utils/text.pydeleted file mode 100644index d392096932..0000000000--- a/saleor/core/utils/text.py+++ /dev/null@@ -1,62 +0,0 @@-# coding: utf-8--import bleach-from django.template.defaultfilters import truncatechars-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- :type serializer_kwargs: Dict[str, bool]-- :rtype: bleach.Cleaner- """- cleaner = bleach.Cleaner([], strip=True)- for k, v in serializer_kwargs.items():- if k not in HTMLSerializer.options:- raise ValueError(- "Parameter %s is not a valid option for HTMLSerializer" % k- )- setattr(cleaner.serializer, k, v)- return cleaner---def strip_html(text: str, **serializer_kwargs: bool):- """Remove (strip) HTML tags from text.-- Can also take additional parameters- to be passed to the serializer (see `get_cleaner`).-- :param text:- :type text: str- :param serializer_kwargs:- :type serializer_kwargs: Dict[str, bool]- :rtype: str- """- cleaner = get_cleaner(**serializer_kwargs)- text = cleaner.clean(text)- return text---def strip_html_and_truncate(html_text: str, max_length: int):- """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 textdiff --git a/saleor/core/weight.py b/saleor/core/weight.pyindex 6595ee7c52..eeb29d361d 100644--- a/saleor/core/weight.py+++ b/saleor/core/weight.py@@ -12,12 +12,7 @@ in terms of weight.In the end, it does not really matter unless you travel betweendifferent planets."""-from decimal import Decimal--from django import formsfrom django.contrib.sites.models import Site-from django.core.validators import MinValueValidator-from django.template.loader import render_to_stringfrom django.utils.translation import pgettext_lazyfrom measurement.measures import Weight@@ -51,63 +46,3 @@ def convert_weight(weight, unit):def get_default_weight_unit():site = Site.objects.get_current()return site.settings.default_weight_unit---class WeightInput(forms.TextInput):- template = "dashboard/shipping/weight_widget.html"- input_type = "number"-- def format_value(self, value):- if isinstance(value, Weight):- unit = get_default_weight_unit()- if value.unit != unit:- value = convert_weight(value, unit)- return value.value- return value-- def render(self, name, value, attrs=None, renderer=None):- widget = super().render(name, value, attrs=attrs, renderer=renderer)- unit = get_default_weight_unit()- translated_unit = dict(WeightUnits.CHOICES)[unit]- return render_to_string(- self.template, {"widget": widget, "value": value, "unit": translated_unit}- )---class WeightField(forms.FloatField):- def __init__(self, *args, widget=WeightInput, min_value=0, **kwargs):- if isinstance(widget, type):- widget = widget(attrs={"type": "number", "step": "any"})- super().__init__(*args, widget=widget, **kwargs)- if min_value is not None:- self.validators.append(MinValueValidator(min_value))-- def to_python(self, value):- value = super().to_python(value)- if value is None:- return value- unit = get_default_weight_unit()- return Weight(**{unit: value})-- def validate(self, weight):- if weight is None or weight in self.empty_values:- super().validate(weight)- else:- unit = get_default_weight_unit()- if not isinstance(weight, Weight):- raise Exception("%r is not a valid weight." % (weight,))- if weight.unit != unit:- raise forms.ValidationError(- "Invalid unit: %r (expected %r)." % (weight.unit, unit),- code="invalid",- )- super().validate(weight.value)-- def clean(self, value):- value = value_to_be_validated = self.to_python(value)- self.validate(value_to_be_validated)- if isinstance(value, Weight):- value_to_be_validated = Decimal(value.value)- # default decimal validators can be used for Weight's value only- self.run_validators(value_to_be_validated)- return valuediff --git a/saleor/menu/models.py b/saleor/menu/models.pyindex 3b1a2763bb..98c58179f7 100644--- a/saleor/menu/models.py+++ b/saleor/menu/models.py@@ -62,23 +62,6 @@ class MenuItem(MPTTModel, SortableModel):def linked_object(self):return self.category or self.collection or self.page- @property- def destination_display(self):- linked_object = self.linked_object-- if not linked_object:- prefix = pgettext_lazy("Link object type description", "URL: ")- return prefix + self.url-- if isinstance(linked_object, Category):- prefix = pgettext_lazy("Link object type description", "Category: ")- elif isinstance(linked_object, Collection):- prefix = pgettext_lazy("Link object type description", "Collection: ")- else:- prefix = pgettext_lazy("Link object type description", "Page: ")-- return prefix + str(linked_object)-def get_url(self):linked_object = self.linked_objectreturn linked_object.get_absolute_url() if linked_object else self.urldiff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex 04ba227143..867420d1ee 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -21,7 +21,7 @@ from .utils import (if TYPE_CHECKING:from .models import Order- from ..account.models import User, Address+ from ..account.models import Userfrom ..payment.models import Payment@@ -129,11 +129,6 @@ def order_shipping_updated(order: "Order"):get_extensions_manager().order_updated(order)-def order_address_updated(order: "Order", user: "User", address: "Address"):- events.order_updated_address_event(order=order, user=user, address=address)- get_extensions_manager().order_updated(order)--def order_captured(order: "Order", user: "User", amount: "Decimal", payment: "Payment"):events.payment_captured_event(order=order, user=user, amount=amount, payment=paymentdiff --git a/saleor/order/models.py b/saleor/order/models.pyindex 48f8ea69d9..5f0cd30d67 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -283,14 +283,6 @@ class Order(ModelWithMetadata):order_status_ok = self.status not in {OrderStatus.DRAFT, OrderStatus.CANCELED}return payment.can_capture() and order_status_ok- def can_charge(self, payment=None):- if not payment:- payment = self.get_last_payment()- if not payment:- return False- order_status_ok = self.status not in {OrderStatus.DRAFT, OrderStatus.CANCELED}- return payment.can_charge() and order_status_ok-def can_void(self, payment=None):if not payment:payment = self.get_last_payment()diff --git a/saleor/page/models.py b/saleor/page/models.pyindex a8e7da8ded..bac7ee2d5b 100644--- a/saleor/page/models.py+++ b/saleor/page/models.py@@ -7,7 +7,6 @@ from draftjs_sanitizer import clean_draft_jsfrom ..core.db.fields import SanitizedJSONFieldfrom ..core.models import PublishableModel, PublishedQuerySet-from ..core.utils import build_absolute_urifrom ..core.utils.draftjs import json_content_to_raw_textfrom ..core.utils.translations import TranslationProxyfrom ..seo.models import SeoModel, SeoModelTranslation@@ -49,9 +48,6 @@ class Page(SeoModel, PublishableModel):def get_absolute_url(self):return reverse("page:details", kwargs={"slug": self.slug})- def get_full_url(self):- return build_absolute_uri(self.get_absolute_url())-class PageTranslation(SeoModelTranslation):language_code = models.CharField(max_length=10)diff --git a/saleor/product/migrations/0053_product_seo_description.py b/saleor/product/migrations/0053_product_seo_description.pyindex 596388b5cd..464db840d4 100644--- a/saleor/product/migrations/0053_product_seo_description.py+++ b/saleor/product/migrations/0053_product_seo_description.py@@ -1,10 +1,68 @@# Generated by Django 2.0.2 on 2018-03-11 18:54import html+import bleachfrom django.core.validators import MaxLengthValidatorfrom django.db import migrations, models+from django.template.defaultfilters import truncatechars+from html5lib.serializer import HTMLSerializer-from saleor.core.utils.text import strip_html_and_truncate++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+ :type serializer_kwargs: Dict[str, bool]++ :rtype: bleach.Cleaner+ """+ cleaner = bleach.Cleaner([], strip=True)+ for k, v in serializer_kwargs.items():+ if k not in HTMLSerializer.options:+ raise ValueError(+ "Parameter %s is not a valid option for HTMLSerializer" % k+ )+ setattr(cleaner.serializer, k, v)+ return cleaner+++def strip_html(text: str, **serializer_kwargs: bool):+ """Remove (strip) HTML tags from text.++ Can also take additional parameters+ to be passed to the serializer (see `get_cleaner`).++ :param text:+ :type text: str+ :param serializer_kwargs:+ :type serializer_kwargs: Dict[str, bool]+ :rtype: str+ """+ cleaner = get_cleaner(**serializer_kwargs)+ text = cleaner.clean(text)+ return text+++def strip_html_and_truncate(html_text: str, max_length: int):+ """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 textdef to_seo_friendly(text):diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 747b612535..e0c786fe6a 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -15,7 +15,6 @@ from django.utils.text import slugifyfrom django.utils.translation import pgettext_lazyfrom django_measurement.models import MeasurementFieldfrom django_prices.models import MoneyField-from django_prices.templatetags import pricesfrom draftjs_sanitizer import clean_draft_jsfrom measurement.measures import Weightfrom mptt.managers import TreeManager@@ -537,10 +536,6 @@ class ProductVariant(ModelWithMetadata):images = list(self.images.all())return images[0] if images else self.product.get_first_image()- def get_ajax_label(self, discounts=None) -> str:- price = self.get_price(discounts)- return "%s, %s, %s" % (self.sku, self.display_product(), prices.amount(price))-class ProductVariantTranslation(models.Model):language_code = models.CharField(max_length=10)diff --git a/saleor/shipping/models.py b/saleor/shipping/models.pyindex 35bd56bcee..1f75b9b104 100644--- a/saleor/shipping/models.py+++ b/saleor/shipping/models.py@@ -4,7 +4,6 @@ from django.conf import settingsfrom django.contrib.postgres.fields import JSONFieldfrom django.db import modelsfrom django.db.models import Q-from django.utils.safestring import mark_safefrom django.utils.translation import pgettext_lazyfrom django_countries.fields import CountryFieldfrom django_measurement.models import MeasurementField@@ -12,7 +11,6 @@ from django_prices.models import MoneyFieldfrom measurement.measures import Weightfrom prices import Money, MoneyRange-from ..core.utils import format_moneyfrom ..core.utils.json_serializer import CustomJsonEncoderfrom ..core.utils.translations import TranslationProxyfrom ..core.weight import (@@ -219,11 +217,6 @@ class ShippingMethod(models.Model):def get_total(self):return self.price- def get_ajax_label(self):- price_html = format_money(self.price)- label = mark_safe("%s %s" % (self, price_html))- return label-class ShippingMethodTranslation(models.Model):language_code = models.CharField(max_length=10)diff --git a/tests/test_account.py b/tests/test_account.pyindex 50988a6420..bba9966e86 100644--- a/tests/test_account.py+++ b/tests/test_account.py@@ -263,16 +263,6 @@ def test_compare_addresses_different_country(address):assert address != copied_address-def test_user_ajax_label(customer_user):- address = customer_user.default_billing_address- label = "%s %s (%s)" % (address.first_name, address.last_name, customer_user.email)- assert customer_user.get_ajax_label() == label---def test_user_ajax_label_without_address(admin_user):- assert admin_user.get_ajax_label() == admin_user.email--@pytest.mark.parametrize("email, first_name, last_name, full_name",[diff --git a/tests/test_core.py b/tests/test_core.pyindex 9f8ac67acd..f1a491de4c 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -25,7 +25,6 @@ from saleor.core.utils import (get_currency_for_country,random_data,)-from saleor.core.utils.text import get_cleaner, strip_htmlfrom saleor.core.weight import WeightUnits, convert_weightfrom saleor.discount.models import Sale, Voucherfrom saleor.giftcard.models import GiftCard@@ -193,17 +192,6 @@ def test_manifest(client, site_settings):assert content["description"] == site_settings.description-def test_utils_get_cleaner_invalid_parameters():- with pytest.raises(ValueError):- get_cleaner(bad=True)---def test_utils_strip_html():- base_text = "<p>Hello</p>" "\n\n" "\t<b>World</b>"- text = strip_html(base_text, strip_whitespace=True)- assert text == "Hello World"--@override_settings(VERSATILEIMAGEFIELD_SETTINGS={"create_images_on_demand": False})def test_create_thumbnails(product_with_image, settings):sizeset = settings.VERSATILEIMAGEFIELD_RENDITION_KEY_SETS["products"]diff --git a/tests/test_shipping.py b/tests/test_shipping.pyindex 5dbbc79207..5d0074c556 100644--- a/tests/test_shipping.py+++ b/tests/test_shipping.py@@ -2,7 +2,6 @@ import pytestfrom measurement.measures import Weightfrom prices import Money-from saleor.core.utils import format_moneyfrom saleor.shipping.models import ShippingMethod, ShippingMethodType, ShippingZonefrom saleor.shipping.utils import default_shipping_zone_exists@@ -16,16 +15,6 @@ def test_shipping_get_total(monkeypatch, shipping_zone):assert method.get_total() == price-def test_shipping_get_ajax_label(shipping_zone):- shipping_method = shipping_zone.shipping_methods.get()- label = shipping_method.get_ajax_label()- proper_label = "%(shipping_method)s %(price)s" % {- "shipping_method": shipping_method,- "price": format_money(shipping_method.price),- }- assert label == proper_label--@pytest.mark.parametrize("price, min_price, max_price, shipping_included",(