Skip to content

Commit

Permalink
Add Superstar emails and report page
Browse files Browse the repository at this point in the history
Fixes https://magfest.atlassian.net/browse/MAGDEV-1314 and fixes https://magfest.atlassian.net/browse/MAGDEV-1138. The receipt and intro emails are separate due to the fact that people can donate multiple times.
  • Loading branch information
kitsuta committed Nov 3, 2024
1 parent 798dfeb commit 72c012d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 2 deletions.
1 change: 1 addition & 0 deletions magprime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .models import * # noqa: F401,E402,F403
from .automated_emails import * # noqa: F401,E402,F403
from .model_checks import * # noqa: F401,E402,F403
from .tasks import * # noqa: F401,E402,F403

# Silence pyflakes
from .models import PrevSeasonSupporter # noqa: E402
Expand Down
9 changes: 9 additions & 0 deletions magprime/automated_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def __init__(self, event):
when=days_before(7, c.EPOCH),
sender='MAGFest <[email protected]>')

AutomatedEmailFixture(
Attendee, 'Thank you for your Super MAGFest Superstars Donation!',
'superstar_intro.html',
filter=lambda a: a.extra_donation >= c.SUPERSTAR_MINIMUM and a.active_receipt and not a.amount_unpaid,
ident='superstar_intro',
when=before(c.SUPERSTAR_DEADLINE),
sender='MAGFest Superstar Program <[email protected]>'
)

AutomatedEmailFixture(
Attendee, 'MAGFest food for guests', 'guest_food_restrictions.txt',
lambda a: a.badge_type == c.GUEST_BADGE,
Expand Down
4 changes: 2 additions & 2 deletions magprime/site_sections/magprime_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def superstars(self, session):
count_query = count_query.filter(Attendee.extra_donation < next_amt)
counts[label] = count_query.count()

for attendee in [a for a in superstars if a.amount_unpaid]:
owe_money[attendee.id] = attendee.amount_unpaid
for attendee in [a for a in superstars if a.amount_unpaid or not a.active_receipt]:
owe_money[attendee.id] = attendee.amount_unpaid if attendee.active_receipt else attendee.default_cost

return {
'attendees': superstars,
Expand Down
40 changes: 40 additions & 0 deletions magprime/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections.abc import Mapping
from datetime import timedelta, datetime
import pytz
from time import sleep, time
import traceback

from celery.schedules import crontab
from pockets import groupify, listify
from pockets.autolog import log
from sqlalchemy.orm import joinedload

from uber import utils
from uber.amazon_ses import email_sender
from uber.automated_emails import AutomatedEmailFixture
from uber.config import c
from uber.decorators import render
from uber.models import AutomatedEmail, Email, MagModel, Attendee, Session, ReceiptItem, ModelReceipt
from uber.tasks import celery
from uber.tasks.email import send_email


@celery.schedule(crontab(minute=0, hour=0))
def superstar_receipts():
with Session() as session:
extra_donations = session.query(ReceiptItem).join(ModelReceipt).filter(
ReceiptItem.desc.contains("Extra Donation"), ReceiptItem.closed != None, ReceiptItem.amount > 0,
ModelReceipt.owner_model == "Attendee")
for donation in extra_donations:
attendee = session.query(Attendee).filter(Attendee.id == donation.receipt.owner_id).first()
if not attendee.amount_unpaid:
closed_local = donation.closed.astimezone(c.EVENT_TIMEZONE).strftime('%x_%X')
ident = f'superstar_receipt_{int(donation.amount / 100)}_{closed_local}'
already_emailed = session.query(Email.ident).filter(Email.ident == ident,
Email.fk_id == attendee.id).first()
if not already_emailed:
subject = f"MAGFest {c.EVENT_YEAR} Superstar Donation Receipt"
body = render('emails/superstar_receipt.html', {'donation': donation, 'attendee': attendee},
encoding=None)
send_email("MAGFest Superstar Program <[email protected]>", attendee.email_to_address,
subject, body, format='html', model=attendee.to_dict('id'), ident=ident)
26 changes: 26 additions & 0 deletions magprime/templates/emails/superstar_intro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head></head>
<body>
<p>
Dear {{ attendee.full_name }},
<br/>On behalf of our Board of Directors, employees, and volunteer staff, thank you for becoming a MAGFest Superstar! Your contribution helps support our mission to make the world a better place through video games.
</p>
<p>
MAGFest, Inc. has been achieving this mission through numerous events, such as Super MAGFest, MAGWest, MAGStock, and Bit Gen Gamer Fest, and by building and empowering a huge community of volunteers, partners, and participants. MAGFest supports this community by highlighting VGM musicians, indie developers, and creatives, as well as uniting those who are eager to relive nostalgia with those who mutually appreciate videogames. In recent years, we have also launched the MAGScouts initiative, which highlights family-friendly content throughout the event, and have increased our educational offerings in Makerspace, Jam Clinic, Panels and more.
</p>
<p>
With your donation, you are helping us to grow these events, create new content, educate more people about video game music, art, and history, and you are also supporting the continued preservation of video game culture and history. If you are interested in learning more about how you can continue supporting our mission, please reach out to us at {{ '[email protected]'|email_to_link }}, and look out for another email in the coming weeks about fulfilling your Superstars perks for MAGFest {{ c.EVENT_YEAR }}!
</p>
<p>
You should receive an email as an official receipt for tax purposes, titled "MAGFest {{ c.EVENT_YEAR }} Superstar Donation Receipt."
If you donated multiple times (e.g., you upgraded an existing donation), you'll receive one email for each time you donated.
</p>
<p>Thank you again for your thoughtful and generous contribution.</p>
<p>
Sincerely,
<br/><br/>Christina Ralls
<br/>Director of Business and Development
<br/>MAGFest, Inc.
</p>
</body>
</html>
22 changes: 22 additions & 0 deletions magprime/templates/emails/superstar_receipt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head></head>
<body>
<p>
Dear {{ attendee.full_name }},
<br/>Thank you for donating to {{ c.EVENT_NAME_AND_YEAR }}!
</p>
<p>
Please accept this email as an official receipt for tax purposes:
<br/>Amount: {{ (donation.amount / 100)|format_currency }}
<br/>Date: {{ donation.closed|full_datetime_local }}
<br/>Total Donated: {{ attendee.extra_donation|format_currency }}<em class="text-muted">*</em>
<br/><span class="text-muted form-text">*The total donations associated with your {{ c.EVENT_NAME_AND_YEAR }} registration. Does not include donations to {{ c.ORGANIZATION_NAME }} from other sources or at other events.</span>
</p>
<p>
Sincerely,
<br/><br/>Christina Ralls
<br/>Director of Business and Development
<br/>MAGFest, Inc.
</p>
</body>
</html>

0 comments on commit 72c012d

Please sign in to comment.