Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 2 additions & 9 deletions accounts/auth_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@

class UserEmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None):
if '@' in username:
kwargs = {'email': username}
else:
kwargs = {'username': username}

kwargs = {'email': username} if '@' in username else {'username': username}
try:
user = User.objects.get(**kwargs)
if user.check_password(password):
return user
else:
return None
return user if user.check_password(password) else None
Comment on lines -7 to +10
Copy link
Author

Choose a reason for hiding this comment

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

Function UserEmailBackend.authenticate refactored with the following changes:

except User.DoesNotExist:
return None

Expand Down
4 changes: 2 additions & 2 deletions orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Meta:
verbose_name_plural = 'Заказы(ов)'

def __str__(self):
return 'Order {}'.format(self.id)
return f'Order {self.id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function Order.__str__ refactored with the following changes:


def get_total_cost(self):
return sum(item.get_cost() for item in self.items.all())
Expand All @@ -41,7 +41,7 @@ class Meta:
verbose_name_plural = 'Заказанные товары'

def __str__(self):
return '{}'.format(self.id)
return f'{self.id}'
Copy link
Author

Choose a reason for hiding this comment

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

Function OrderItem.__str__ refactored with the following changes:


def get_cost(self):
return self.price * self.quantity
3 changes: 1 addition & 2 deletions orders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

def order_create(request):
cart = Cart(request)
user = request.user
if request.method == 'POST':
user = request.user
Comment on lines +9 to -10
Copy link
Author

Choose a reason for hiding this comment

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

Function order_create refactored with the following changes:

if user.is_authenticated:
data = {"last_name": user.last_name, "first_name": user.first_name, "email": user.email}
form = OrderCreateForm(request.POST, initial=data)
Expand All @@ -26,7 +26,6 @@ def order_create(request):
cart.clear()
return render(request, 'orders/created.html', {'order': order})
else:
user = request.user
data = {}
if user.is_authenticated:
data["last_name"] = user.last_name
Expand Down