Skip to content

Commit

Permalink
Handle changes from amount -> amount_won
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Apr 26, 2024
1 parent bb2f120 commit b6affed
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/vb/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def show_is_winner(self, obj: ContestEntry) -> bool:
@admin.display(description="Winnings")
def show_winnings(self, obj: ContestEntry) -> str:
"""Return the contest entry's winnings, if any, if any."""
return f"${obj.amount}" if obj.is_winner else ""
return f"${obj.amount_won}" if obj.is_winner else ""

@admin.display(description="Issued?")
def show_winnings_issued(self, obj: ContestEntry) -> str:
Expand Down
2 changes: 1 addition & 1 deletion server/vb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def has_issued(self) -> bool:
@property
def is_winner(self) -> bool:
"""Return whether the student won a prize."""
return self.amount > 0
return self.amount_won > 0

@property
def needs_to_issue(self) -> bool:
Expand Down
11 changes: 6 additions & 5 deletions server/vb/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _create_contest_entry(student: Student, contest: Contest) -> ContestEntry:
return ContestEntry.objects.create(
student=student,
contest=contest,
amount=contest.amount if minted else 0,
amount_won=contest.amount if minted else 0,
)


Expand Down Expand Up @@ -107,9 +107,10 @@ def get_or_issue_prize(

def _create_gift_card(contest_entry: ContestEntry) -> tuple[ContestEntry, str]:
"""Create a new gift card for a student in the amount of `amount`."""
assert contest_entry.is_winner
client = AGCODClient.from_settings()
try:
response = client.create_gift_card(contest_entry.amount)
response = client.create_gift_card(contest_entry.amount_won)
except Exception as e:
logger.exception(
f"AGCOD failed for contest entry {contest_entry.pk} {contest_entry.student.email}" # noqa
Expand All @@ -128,11 +129,11 @@ def _get_claim_code(contest_entry: ContestEntry) -> str:
Raise an exception if unable to obtain the claim code.
"""
# Otherwise, they do!
assert contest_entry.is_winner
client = AGCODClient.from_settings()
try:
response = client.check_gift_card(
contest_entry.amount, contest_entry.creation_request_id
contest_entry.amount_won, contest_entry.creation_request_id
)
except Exception as e:
logger.exception(
Expand Down Expand Up @@ -181,7 +182,7 @@ def send_validation_link_email(
token=make_token(12),
)
if contest_entry and contest_entry.is_winner:
button_text = f"Get my ${contest_entry.amount} gift card"
button_text = f"Get my ${contest_entry.amount_won} gift card"
else:
button_text = "Validate my email"
success = send_template_email(
Expand Down
2 changes: 1 addition & 1 deletion server/vb/templates/email/code/body.dhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Hi {{ student.first_name }},
{% include "email/base/p_close.html" %}
{% include "email/base/p.html" %}
Your ${{ contest_entry.amount }} Amazon gift code is: <strong>{{ claim_code }}</strong>
Your ${{ contest_entry.amount_won }} Amazon gift code is: <strong>{{ claim_code }}</strong>
{% include "email/base/p_close.html" %}
{% include "email/base/p.html" %}
Copy and paste it into Amazon's gift card redemption page to claim your gift.
Expand Down
2 changes: 1 addition & 1 deletion server/vb/templates/email/code/body.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "email/base/body.txt" %}

{% block message %}Hi {{ student.first_name }},
Your ${{ contest_entry.amount }} Amazon gift code is: {{ claim_code }}
Your ${{ contest_entry.amount_won }} Amazon gift code is: {{ claim_code }}

Copy and paste it into Amazon's gift card redemption page to claim your gift.

Expand Down
2 changes: 1 addition & 1 deletion server/vb/templates/email/code/subject.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Your ${{ contest_entry.amount }} Amazon gift card
Your ${{ contest_entry.amount_won }} Amazon gift card
4 changes: 2 additions & 2 deletions server/vb/templates/finish_check.dhtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
{% if contest_entry %}
{% if contest_entry.is_winner %}
{% if contest_entry.contest.is_giveaway %}
We've sent you a link to claim your ${{ contest_entry.amount }} gift card.
We've sent you a link to claim your ${{ contest_entry.amount_won }} gift card.
{% else %}
You won a ${{ contest_entry.amount }} gift card! We've sent you a link to claim it.
You won a ${{ contest_entry.amount_won }} gift card! We've sent you a link to claim it.
{% endif %}
{% else %}
Alas, you didn't win a gift card this time. Your friends still have a chance to win, though! Share the link with them: <a href="{% url 'vb:school' slug=school.slug %}">{{ BASE_URL }}{% url 'vb:school' slug=school.slug %}</a>
Expand Down
2 changes: 1 addition & 1 deletion server/vb/templates/verify_email.dhtml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<img src="{{ school.logo.url }}"
alt="{{ school.short_name }} {{ school.mascot }} logo" />
{% if contest_entry and claim_code %}
<p>Congrats! You won a ${{ contest_entry.amount }} gift card!</p>
<p>Congrats! You won a ${{ contest_entry.amount_won }} gift card!</p>
<h2>
<span class="code">{{ claim_code }}</span>
<span class="clipboard" title="Copy to clipboard">{% include "clipboard.svg" %}</span>
Expand Down

0 comments on commit b6affed

Please sign in to comment.