diff --git a/magprime/__init__.py b/magprime/__init__.py index 5cd0313..55e6b12 100644 --- a/magprime/__init__.py +++ b/magprime/__init__.py @@ -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 diff --git a/magprime/automated_emails.py b/magprime/automated_emails.py index d985c50..30aa6a8 100644 --- a/magprime/automated_emails.py +++ b/magprime/automated_emails.py @@ -41,6 +41,15 @@ def __init__(self, event): when=days_before(7, c.EPOCH), sender='MAGFest ') +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 ' +) + AutomatedEmailFixture( Attendee, 'MAGFest food for guests', 'guest_food_restrictions.txt', lambda a: a.badge_type == c.GUEST_BADGE, diff --git a/magprime/site_sections/magprime_reports.py b/magprime/site_sections/magprime_reports.py index 097bfc8..e43e016 100644 --- a/magprime/site_sections/magprime_reports.py +++ b/magprime/site_sections/magprime_reports.py @@ -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, diff --git a/magprime/tasks.py b/magprime/tasks.py new file mode 100644 index 0000000..0fd4e4f --- /dev/null +++ b/magprime/tasks.py @@ -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 ", attendee.email_to_address, + subject, body, format='html', model=attendee.to_dict('id'), ident=ident) \ No newline at end of file diff --git a/magprime/templates/emails/superstar_intro.html b/magprime/templates/emails/superstar_intro.html new file mode 100644 index 0000000..8293b52 --- /dev/null +++ b/magprime/templates/emails/superstar_intro.html @@ -0,0 +1,26 @@ + + + +

+ Dear {{ attendee.full_name }}, +
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. +

+

+ 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. +

+

+ 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 {{ 'superstars@magfest.org'|email_to_link }}, and look out for another email in the coming weeks about fulfilling your Superstars perks for MAGFest {{ c.EVENT_YEAR }}! +

+

+ 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. +

+

Thank you again for your thoughtful and generous contribution.

+

+ Sincerely, +

Christina Ralls +
Director of Business and Development +
MAGFest, Inc. +

+ + \ No newline at end of file diff --git a/magprime/templates/emails/superstar_receipt.html b/magprime/templates/emails/superstar_receipt.html new file mode 100644 index 0000000..66d1ad4 --- /dev/null +++ b/magprime/templates/emails/superstar_receipt.html @@ -0,0 +1,22 @@ + + + +

+ Dear {{ attendee.full_name }}, +
Thank you for donating to {{ c.EVENT_NAME_AND_YEAR }}! +

+

+ Please accept this email as an official receipt for tax purposes: +
Amount: {{ (donation.amount / 100)|format_currency }} +
Date: {{ donation.closed|full_datetime_local }} +
Total Donated: {{ attendee.extra_donation|format_currency }}* +
*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. +

+

+ Sincerely, +

Christina Ralls +
Director of Business and Development +
MAGFest, Inc. +

+ + \ No newline at end of file