Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def clean_email(self):
User.objects.exclude(pk=self.instance.pk).get(email=email)
except User.DoesNotExist:
return email
raise forms.ValidationError("Email '%s' already in use." % email)
raise forms.ValidationError(f"Email '{email}' already in use.")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AccountUpdateForm.clean_email refactored with the following changes:



class UserAdminCreationForm(forms.ModelForm):
Expand Down
2 changes: 1 addition & 1 deletion account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CustomUserManager(UserManager):
def get_by_natural_key(self, username):
case_insensitive_username_field = '{}__iexact'.format(self.model.USERNAME_FIELD)
case_insensitive_username_field = f'{self.model.USERNAME_FIELD}__iexact'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CustomUserManager.get_by_natural_key refactored with the following changes:

return self.get(**{case_insensitive_username_field: username})

def create_user(self, first_name, last_name, email, password=None):
Expand Down
15 changes: 7 additions & 8 deletions commerce/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ def list_products(
@check_pk
def list_addresses(request):

addresses = Address.objects.select_related('city', 'user').filter(user=User.objects.get(id=request.auth['pk']))
if addresses:
if addresses := Address.objects.select_related('city', 'user').filter(
user=User.objects.get(id=request.auth['pk'])
):
Comment on lines -112 to +114

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function list_addresses refactored with the following changes:

return addresses
return 404, {'detail': 'No addresses found'}

Expand All @@ -125,9 +126,7 @@ def list_addresses(request):
404: MessageOut
})
def list_cities(request):
cities_qs = City.objects.all()

if cities_qs:
if cities_qs := City.objects.all():
Comment on lines -128 to +129

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function list_cities refactored with the following changes:

return cities_qs

return 404, {'detail': 'No cities found'}
Expand Down Expand Up @@ -188,9 +187,9 @@ def delete_city(request, id: UUID4):
@check_pk
def view_cart(request):

cart_items = Item.objects.filter(user=User.objects.get(id=request.auth['pk']), ordered=False)

if cart_items:
if cart_items := Item.objects.filter(
user=User.objects.get(id=request.auth['pk']), ordered=False
):
Comment on lines -191 to +192

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function view_cart refactored with the following changes:

return cart_items

return 404, {'detail': 'Your cart is empty, go shop like crazy!'}
Expand Down
4 changes: 1 addition & 3 deletions commerce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ class Category(Entity):


def __str__(self):
if self.parent:
return f'- {self.name}'
return f'{self.name}'
return f'- {self.name}' if self.parent else f'{self.name}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Category.__str__ refactored with the following changes:


class Meta:
verbose_name = 'category'
Expand Down