Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
IKarbowiak committed Nov 27, 2019
1 parent 622de65 commit 9d05d80
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 224 deletions.
6 changes: 0 additions & 6 deletions saleor/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ def get_full_name(self):
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)
Expand Down
10 changes: 0 additions & 10 deletions saleor/core/templatetags/version.py

This file was deleted.

62 changes: 0 additions & 62 deletions saleor/core/utils/text.py

This file was deleted.

65 changes: 0 additions & 65 deletions saleor/core/weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
In the end, it does not really matter unless you travel between
different planets.
"""
from decimal import Decimal

from django import forms
from django.contrib.sites.models import Site
from django.core.validators import MinValueValidator
from django.template.loader import render_to_string
from django.utils.translation import pgettext_lazy
from measurement.measures import Weight

Expand Down Expand Up @@ -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 value
17 changes: 0 additions & 17 deletions saleor/menu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,6 @@ def get_ordering_queryset(self):
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_object
return linked_object.get_absolute_url() if linked_object else self.url
Expand Down
7 changes: 1 addition & 6 deletions saleor/order/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

if TYPE_CHECKING:
from .models import Order
from ..account.models import User, Address
from ..account.models import User
from ..payment.models import Payment


Expand Down Expand Up @@ -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=payment
Expand Down
8 changes: 0 additions & 8 deletions saleor/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,6 @@ def can_capture(self, payment=None):
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()
Expand Down
4 changes: 0 additions & 4 deletions saleor/page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from ..core.db.fields import SanitizedJSONField
from ..core.models import PublishableModel, PublishedQuerySet
from ..core.utils import build_absolute_uri
from ..core.utils.draftjs import json_content_to_raw_text
from ..core.utils.translations import TranslationProxy
from ..seo.models import SeoModel, SeoModelTranslation
Expand Down Expand Up @@ -49,9 +48,6 @@ def plain_text_content(self):
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)
Expand Down
60 changes: 59 additions & 1 deletion saleor/product/migrations/0053_product_seo_description.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
# Generated by Django 2.0.2 on 2018-03-11 18:54
import html

import bleach
from django.core.validators import MaxLengthValidator
from 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 text


def to_seo_friendly(text):
Expand Down
5 changes: 0 additions & 5 deletions saleor/product/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from django.utils.translation import pgettext_lazy
from django_measurement.models import MeasurementField
from django_prices.models import MoneyField
from django_prices.templatetags import prices
from draftjs_sanitizer import clean_draft_js
from measurement.measures import Weight
from mptt.managers import TreeManager
Expand Down Expand Up @@ -532,10 +531,6 @@ def get_first_image(self):
images = list(self.images.all())
return images[0] if images else self.product.get_first_image()

def get_ajax_label(self, discounts=None):
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)
Expand Down
7 changes: 0 additions & 7 deletions saleor/shipping/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models import Q
from django.utils.safestring import mark_safe
from django.utils.translation import pgettext_lazy
from django_countries.fields import CountryField
from django_measurement.models import MeasurementField
from django_prices.models import MoneyField
from measurement.measures import Weight
from prices import Money, MoneyRange

from ..core.utils import format_money
from ..core.utils.json_serializer import CustomJsonEncoder
from ..core.utils.translations import TranslationProxy
from ..core.weight import (
Expand Down Expand Up @@ -219,11 +217,6 @@ def __repr__(self):
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)
Expand Down
10 changes: 0 additions & 10 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
Loading

0 comments on commit 9d05d80

Please sign in to comment.