From e1fa97976aae451e4d6e9a3aada299e7084226a8 Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Thu, 19 Oct 2023 23:31:22 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- cards/models.py | 2 +- cards/views.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cards/models.py b/cards/models.py index f374f18..ffbd173 100644 --- a/cards/models.py +++ b/cards/models.py @@ -23,7 +23,7 @@ class Card(models.Model): alt_image = models.ImageField(upload_to='card_images', blank=True, null=True) def __unicode__(self): - return "{} of {}s".format(self.rank.capitalize(), Card.SUITS[self.suit][1].capitalize()) + return f"{self.rank.capitalize()} of {Card.SUITS[self.suit][1].capitalize()}s" def get_ranking(self): rankings = { diff --git a/cards/views.py b/cards/views.py index 240151b..acf745e 100644 --- a/cards/views.py +++ b/cards/views.py @@ -68,9 +68,7 @@ def profile(request): war_ties = request.user.wargame_set.filter(result=WarGame.TIE).count() war_losses = request.user.wargame_set.filter(result=WarGame.LOSS).count() total_games = request.user.wargame_set.count() - percent_win = 0 - if total_games != 0: - percent_win = war_wins*100.0/total_games + percent_win = war_wins*100.0/total_games if total_games != 0 else 0 score = war_wins - war_losses total_war_wins = WarGame.objects.filter(result=WarGame.WIN).count() total_war_ties = WarGame.objects.filter(result=WarGame.TIE).count() @@ -116,8 +114,8 @@ def blackjack(request): user_cards = cards[:2] for card in user_cards: if card.rank == 'ace': - text_content = 'Congrats {} Ace of {}s at {}.'.format(request.user.first_name, card.rank, datetime.now() ) - html_content = '

Congrats {} Ace of {}s at {}.

'.format(request.user.first_name, card.get_suit_display(), datetime.now()) + text_content = f'Congrats {request.user.first_name} Ace of {card.rank}s at {datetime.now()}.' + html_content = f'

Congrats {request.user.first_name} Ace of {card.get_suit_display()}s at {datetime.now()}.

' msg = EmailMultiAlternatives("Ace!", text_content, settings.DEFAULT_FROM_EMAIL, [request.user.email]) msg.attach_alternative(html_content, "text/html") msg.send()