def handle(self, **kwargs): # Contributors only contributors = Ticket.objects.filter( owner__isnull=False, owner__is_contributor=True).all().values_list('owner', flat=True) all_emailees = set(list(contributors)) users_to_email = User.objects.filter(pk__in=all_emailees).all() template = get_template('accounts/emails/slack.txt') for user in users_to_email: context = { 'user': user, 'slack_link': settings.SLACK_SIGNUP_LINK, } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'PyCon UK Slack Workspace information ({user.user_id})', body, user.email_addr, )
def send_order_confirmation_mail(order): assert not order.payment_required() template = get_template('orders/emails/order-confirmation.txt') context = { 'purchaser_name': order.purchaser.name, 'num_tickets': order.num_tickets(), 'num_items': order.num_items(), 'order_rows_summary': order.order_rows_summary(), 'tickets_for_others': order.tickets_for_others(), 'ticket_for_self': order.ticket_for_self(), 'receipt_url': settings.DOMAIN + reverse('orders:order_receipt', args=[order.order_id]), } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'PyCon UK 2018 order confirmation ({order.order_id})', body, order.purchaser.email_addr, )
def handle(self, template, subject, **kwargs): successful_applicants_who_came = Application.objects.filter( application_declined=False, amount_awarded__gt=0, applicant__ticket__badge__collected__isnull=False ).all().values_list('applicant', flat=True) all_emailees = set(list(successful_applicants_who_came)) users_to_email = User.objects.filter(pk__in=all_emailees).all() template = get_template(f'emails/{template[0]}.txt') for user in users_to_email: context = { 'user': user } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'{subject[0]} ({user.user_id})', body, user.email_addr, )
def handle(self, *args, **kwargs): accepted_applications = Application.objects.filter( application_declined=False, ).filter( Q(ticket_awarded=True) | Q(amount_awarded__isnull=False)).all() for application in accepted_applications: if application.ticket_awarded: create_free_ticket(email_addr=application.applicant.email_addr, free_reason='Financial Assistance', days=application.days()) if application.amount_awarded: template = get_template('grants/emails/how-to-get-grant.txt') context = { 'application': application, } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'Your PyCon UK 2018 Financial Assistance ({application.application_id})', body, application.applicant.email_addr, )
def send_order_refund_mail(order): body = ORDER_REFUND_TEMPLATE.format(purchaser_name=order.purchaser.name) send_mail( f'PyCon UK 2017 order refund ({order.order_id})', body, order.purchaser.email_addr, )
def send_booking_confirmation_mail(booking): body = INVITATION_TEMPLATE.format( room_description=booking.room_description()) send_mail( f'PyCon UK 2017 accommodation confirmation', body, booking.guest.email_addr, )
def handle(self, *args, template, subject, recipients, dry_run, **kwargs): settings.EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' template = get_template(f'emails/{template}.txt') with open(recipients) as f: recipients = list(csv.DictReader(f)) num_recipients = len(recipients) if dry_run: self.stdout.write('This is a dry run') self.stdout.write( f'Running this would send the email to {num_recipients} recipient(s)' ) else: self.stdout.write( f'About to send the email to {num_recipients} recipient(s)') for recipient in recipients: # Here, we are making sure that template.render() raises no errors, # *before* we start to send any emails. body = render(template, recipient) assert 'THIS SHOULD NEVER HAPPEN' not in body, f'Could not render template for {recipient["email_addr"]}' if dry_run: self.stdout.write(body) if dry_run: return self.stdout.write('Are you sure? [yN]') while True: rsp = input() if rsp in ['', 'n', 'N']: self.stdout.write('Aborting') return elif rsp in ['y', 'Y']: break self.stdout.write(f'Sending {num_recipients} email(s)') for recipient in recipients: body = render(template, recipient) qualified_subject = subject send_mail( qualified_subject, body, recipient['email_addr'], )
def handle(self, *args, **kwargs): accepted_proposals = Proposal.objects.filter( state='accept', replied_to__isnull=True).all() for proposal in accepted_proposals: template = get_template('cfp/emails/proposal_accept.txt') context = { 'proposal': proposal, 'proposal_url': settings.DOMAIN + reverse('cfp:proposal', args=[proposal.proposal_id]), 'user_proposal_count': Proposal.objects.filter(proposer=proposal.proposer).count() } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'Your PyCon UK 2018 Proposal ({proposal.title})', body, proposal.proposer.email_addr, ) proposal.replied_to = datetime.now() proposal.save() rejected_proposals = Proposal.objects.filter( state='reject', replied_to__isnull=True).all() for proposal in rejected_proposals: template = get_template('cfp/emails/proposal_reject.txt') context = { 'proposal': proposal, 'user_proposal_count': Proposal.objects.filter(proposer=proposal.proposer).count() } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'Your PyCon UK 2018 Proposal ({proposal.title})', body, proposal.proposer.email_addr, ) proposal.replied_to = datetime.now() proposal.save()
def send_invitation_mail(ticket): invitation = ticket.invitation() url = settings.DOMAIN + invitation.get_absolute_url() if ticket.order is None: body = FREE_TICKET_INVITATION_TEMPLATE.format(url=url) else: purchaser_name = ticket.order.purchaser.name body = INVITATION_TEMPLATE.format(purchaser_name=purchaser_name, url=url) send_mail( f'PyCon UK 2017 ticket invitation ({ticket.ticket_id})', body, invitation.email_addr, )
def send_booking_confirmation_mail(booking): user = booking.guest subject = f'PyCon UK 2017 dinner confirmation | {user.user_id}' template = get_template('dinners/emails/order-confirmation.txt') context = { 'booking': booking, 'receipt_url': settings.DOMAIN + reverse('dinners:conference_dinner_receipt'), } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( subject, body, booking.guest.email_addr, )
def handle(self, *args, template, subject, dry_run, **kwargs): template = get_template(f'emails/{template}.txt') invitations = TicketInvitation.objects.filter(status='unclaimed') num_recipients = len(invitations) for invitation in invitations: # Here, we are making sure that template.render() raises no errors, # *before* we start to send any emails. context = {'invitation': invitation} body = render(template, context) assert 'THIS SHOULD NEVER HAPPEN' not in body, f'Could not render template' if dry_run: self.stdout.write('This is a dry run') self.stdout.write(f'Running this would send the email to {num_recipients} recipient(s)') self.stdout.write(body) return self.stdout.write('Are you sure? [yN]') while True: rsp = input() if rsp in ['', 'n', 'N']: self.stdout.write('Aborting') return elif rsp in ['y', 'Y']: break self.stdout.write(f'Sending {num_recipients} email(s)') logger.info('sending ticket reminder', template=template.template.name, num_recipients=num_recipients) for invitation in invitations: context = {'invitation': invitation} body = render(template, context) qualified_subject = f'{subject} | {invitation.ticket.ticket_id}' logger.info('sending email', email_addr=invitation.email_addr) send_mail( qualified_subject, body, invitation.email_addr, )
def send_order_confirmation_mail(order): assert not order.payment_required() template = get_template('children/emails/order-confirmation.txt') context = { 'purchaser_name': order.purchaser.name, 'num_tickets': order.num_tickets(), 'order_url': settings.DOMAIN + reverse('children:order', args=[order.order_id]), } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f"PyCon UK 2017 children's day order confirmation ({order.order_id})", body, order.purchaser.email_addr, )
def handle(self, *args, **kwargs): unclaimed_invites = TicketInvitation.objects.filter( status='unclaimed' ).all() for invite in unclaimed_invites: template = get_template('tickets/emails/unclaimed.txt') context = { 'invite': invite, 'url': settings.DOMAIN + invite.get_absolute_url() } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'PyCon UK - urgent, action required to claim ticket ({invite.ticket.ticket_id})', body, invite.email_addr, )
def handle(self, *args, **kwargs): accepted_proposals = Proposal.objects.filter( state__in=['accept', 'confirm']).all() for proposal in accepted_proposals: if proposal.proposer.get_ticket() is None: template = get_template('cfp/emails/not_got_ticket.txt') context = { 'proposal': proposal, } body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'Your PyCon UK 2018 Proposal ({proposal.title})', body, proposal.proposer.email_addr, ) proposal.replied_to = datetime.now() proposal.save()
def handle(self, template, subject, **kwargs): # All ticket holders ticket_holders = Ticket.objects.filter( owner__isnull=False).all().values_list('owner', flat=True) # # All ticket orderers # ticket_orderers = Order.objects.filter( # status='successful' # ).all().values_list('purchaser', flat=True) # # All accepted speakers # accepted_speakers = Proposal.objects.filter( # state__in=['accept', 'confirm'] # ).all().values_list('proposer', flat=True) # # All accepted Financial Assistance # accepted_finaid = Application.objects.filter( # Q(ticket_awarded=True) | Q(amount_awarded__gt=0) # ).all().values_list('applicant', flat=True) all_emailees = set(list(ticket_holders)) # + list(ticket_orderers) + #list(accepted_speakers) + list(accepted_finaid)) users_to_email = User.objects.filter(pk__in=all_emailees).all() template = get_template(f'emails/{template[0]}.txt') for user in users_to_email: context = {'user': user} body_raw = template.render(context) body = re.sub('\n\n\n+', '\n\n', body_raw) send_mail( f'{subject[0]} ({user.user_id})', body, user.email_addr, )
def handle(self, *args, template, subject, recipients, list_recipients, dry_run, **kwargs): template = get_template(f'emails/{template}.txt') recipients = self.recipients[recipients] num_recipients = recipients.count() if dry_run: self.stdout.write('This is a dry run') self.stdout.write( f'Running this would send the email to {num_recipients} recipient(s)' ) else: self.stdout.write( f'About to send the email to {num_recipients} recipient(s)') for recipient in recipients.order_by('email_addr'): if list_recipients: if dry_run: self.stdout.write('~' * 80) self.stdout.write( f' * {recipient.name} ({recipient.email_addr})') # Here, we are making sure that template.render() raises no errors, # *before* we start to send any emails. context = {'recipient': recipient} body = render(template, context) assert 'THIS SHOULD NEVER HAPPEN' not in body, f'Could not render template for {recipient.email_addr}' if dry_run: self.stdout.write(body) if dry_run: return self.stdout.write('Are you sure? [yN]') while True: rsp = input() if rsp in ['', 'n', 'N']: self.stdout.write('Aborting') return elif rsp in ['y', 'Y']: break self.stdout.write(f'Sending {num_recipients} email(s)') logger.info('sending bulk email', template=template.template.name, num_recipients=num_recipients) for recipient in recipients.order_by('id'): context = {'recipient': recipient} body = render(template, context) qualified_subject = f'{subject} | {recipient.user_id}' logger.info('sending email', recipient=recipient.id, email_addr=recipient.email_addr) send_mail( qualified_subject, body, recipient.email_addr, )