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 cards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 Card.__unicode__ refactored with the following changes:


def get_ranking(self):
rankings = {
Expand Down
8 changes: 3 additions & 5 deletions cards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 profile refactored with the following changes:

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()
Expand Down Expand Up @@ -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 = '<h2>Congrats {} Ace of {}s at {}.</h2>'.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'<h2>Congrats {request.user.first_name} Ace of {card.get_suit_display()}s at {datetime.now()}.</h2>'
Comment on lines -119 to +118
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 blackjack refactored with the following changes:

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