Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Jun 23, 2023
1 parent cb30806 commit 6020827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
9 changes: 5 additions & 4 deletions app/helpers/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def formatted_amount(amount):
# if number is in ones, return with one decimal
formatted_amount = round(amount, 1)
# if first decimal is zero
if int(formatted_amount) == formatted_amount:
return int(formatted_amount)
else:
return formatted_amount
return (
int(formatted_amount)
if int(formatted_amount) == formatted_amount
else formatted_amount
)
elif digits in (2, 3):
# if number is in tens or hundereds, return without decimals
return round(amount)
Expand Down
19 changes: 8 additions & 11 deletions app/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ def share_all_used_recipes(self):

@property
def relative_portion_count(self):
relative_portion_count = 0

# count portions of attendees with their portion size
for attendee in self.attendees:
relative_portion_count += getattr(attendee.portion_type, "size", 1)

relative_portion_count = sum(
getattr(attendee.portion_type, "size", 1)
for attendee in self.attendees
)
# add remaining count
relative_portion_count += self.people_count - len(self.attendees)

Expand Down Expand Up @@ -175,10 +173,9 @@ def daily_recipes_split_by_shopping(self) -> list:
split_recipes = []

shopping_indexes = [0]
for i, recipe in enumerate(daily_recipes):
if recipe.is_shopping:
shopping_indexes.append(i)

shopping_indexes.extend(
i for i, recipe in enumerate(daily_recipes) if recipe.is_shopping
)
shopping_indexes.append(len(daily_recipes))

for i in range(len(shopping_indexes) - 1):
Expand All @@ -198,7 +195,7 @@ def people_count_without_portion_type(self):

@property
def people_with_any_portion_type_count(self):
return sum([t.count for t in self.event_portion_types])
return sum(t.count for t in self.event_portion_types)

@property
def people_without_attendee_count(self):
Expand Down

0 comments on commit 6020827

Please sign in to comment.