-
Notifications
You must be signed in to change notification settings - Fork 0
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 main branch #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,24 +39,18 @@ def __str__(self): | |
|
||
@property | ||
def shipping(self): | ||
shipping = False | ||
orderitems = self.orderitem_set.all() | ||
for i in orderitems: | ||
if i.product.digital == False: | ||
shipping = True | ||
return shipping | ||
return any(i.product.digital == False for i in orderitems) | ||
|
||
@property | ||
def get_cart_total(self): | ||
orderitems = self.orderitem_set.all() | ||
total = sum([item.get_total for item in orderitems]) | ||
return total | ||
return sum(item.get_total for item in orderitems) | ||
Comment on lines
-52
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@property | ||
def get_cart_items(self): | ||
orderitems = self.orderitem_set.all() | ||
total = sum([item.quantity for item in orderitems]) | ||
return total | ||
return sum(item.quantity for item in orderitems) | ||
Comment on lines
-58
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
class OrderItem(models.Model): | ||
product = models.ForeignKey(Product,on_delete=models.SET_NULL, blank=True, null=True) | ||
|
@@ -66,8 +60,7 @@ class OrderItem(models.Model): | |
|
||
@property | ||
def get_total(self): | ||
total = self.product.price * self.quantity | ||
return total | ||
return self.product.price * self.quantity | ||
Comment on lines
-69
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,15 @@ def cookieCart(request): | |
order = {'get_cart_total': 0, 'get_cart_items': 0, 'shipping': False} | ||
cartItems = order['get_cart_items'] | ||
|
||
for i in cart: | ||
for i, value in cart.items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
try: | ||
cartItems += cart[i]['quantity'] | ||
|
||
product = Product.objects.get(id=i) | ||
total = (product.price * cart[i]['quantity']) | ||
|
||
order['get_cart_total'] += total | ||
order['get_cart_items'] += cart[i]['quantity'] | ||
order['get_cart_items'] += value['quantity'] | ||
|
||
item = { | ||
'product': { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Order.shipping
refactored with the following changes:use-any
)inline-immediately-returned-variable
)