def send_registration_invite_email(invite_ids=[]): for invite_id in invite_ids: try: invite = RegistrationInvite.objects.get(pk=invite_id) except RegistrationInvite.DoesNotExist: continue # Don't send invites if they have completed registration # or the sent date is set (already sent invite). # To resend an invite, we need to set sent_date to null # before calling this task. if invite.completed_date or invite.sent_date: continue send_email( league=invite.event.league, to_email=invite.email, template="registration_invite", context={ 'invite': invite, }, ) invite.sent_date = timezone.now() invite.save()
def test_email(league, to_email): send_email( league=league, to_email=to_email, template="test_email", context={}, )
def notify_admin_of_user_changes(league_id, initial, updated): league = League.objects.get(pk=league_id) if league.email_from_address: send_email( league=League.objects.get(pk=league_id), to_email=league.email_from_address, template="users_profile_updated_alert", context={ 'initial': initial, 'updated': updated, }, )
def email_invoice(invoice_id): invoice = Invoice.objects.get(pk=invoice_id) subject = "{} - {} Invoice".format(invoice.league.name, invoice.description) send_email( league=invoice.league, to_email=invoice.user.email, template="new_invoice", context={ 'user': invoice.user, 'invoice': invoice, 'subject': subject, }, )
def post(self, request, organization_slug): form = CreateRinkUserForm(request.POST) if form.is_valid(): cleaned_data = form.cleaned_data # Yeah I guess... this could be something more custom. organization = Organization.objects.get( pk=request.session['view_organization']) league = League.objects.get(pk=request.session['view_league']) password = get_random_string(12) user = User.objects.create_user( email=cleaned_data['email'], password=password, ) user.first_name = cleaned_data['first_name'] user.last_name = cleaned_data['last_name'] user.derby_name = cleaned_data['derby_name'] # These two might make more sense elsewhere as an item on the # form or validating that they are allowed to access it. user.organization = organization user.league = league user.save() send_email(league=league, to_email=cleaned_data['email'], template="admin_user_creation_invite", context={ 'user': user, 'password': password, 'league': league, 'organization': organization, }) return HttpResponseRedirect( reverse("league:organization_permissions_update", kwargs={ 'organization_slug': organization.slug, 'user_id': user.pk, })) else: return render(request, self.template, {'form': form})
def send_voting_invite(invite_ids=[], reminder=False): if reminder: template = 'voting_reminder' else: template = 'voting_invite' for invite in invite_ids: invite = VotingInvite.objects.get(pk=invite) send_email( league=invite.election.league, to_email=invite.user.email, template=template, context={ 'invite': invite, 'election': invite.election, 'user': invite.user, }, )
def send_registration_confirmation(registration_data_id, payment_data_id=None): #try: registration_data = RegistrationData.objects.get(pk=registration_data_id) payment_data = None if payment_data_id: payment_data = Payment.objects.get(pk=payment_data_id) #except RegistrationData.DoesNotExist: # raise RegistrationData.DoesNotExist send_email( league=registration_data.event.league, to_email=registration_data.user.email, template="registration_confirmation", context={ 'user': registration_data.user, 'event': registration_data.event, 'registration': registration_data, 'payment': payment_data, }, ) return True
def email_payment_receipt(payment_id): payment = Payment.objects.get(pk=payment_id) invoices = Invoice.objects.filter(payment=payment) if invoices.count() == 1: subject = "{} {} Payment Receipt #{}".format( payment.league.name, invoices[0].description, payment.id) else: subject = "{} Payment Receipt #{}".format( payment.league.name, payment.id) send_email( league=payment.league, to_email=payment.user.email, template="payment_receipt", context={ 'user': payment.user, 'invoices': invoices, 'payment': payment, 'subject': subject, }, )
def send_registration_invite_reminder(event_id, invite_ids=[], custom_message=''): for invite_id in invite_ids: try: invite = RegistrationInvite.objects.get(pk=invite_id, event__pk=event_id) except RegistrationInvite.DoesNotExist: continue reminder_subject = "*REMINDER* " custom_message_html = markdownify(custom_message) send_email( league=invite.event.league, to_email=invite.email, template="registration_invite", context={ 'invite': invite, 'reminder_subject': reminder_subject, 'custom_message': custom_message_html, }, )
def post(self, request, league_slug, event_slug): league = get_object_or_404(League, slug=league_slug) event = get_object_or_404(TicketEvent, slug=event_slug) form = TicketForm(request.POST) if form.is_valid(): # charge token five bucks stripe.api_key = league.get_stripe_private_key() stripe.api_version = settings.STRIPE_API_VERSION try: customer = stripe.Customer.create( description=form.cleaned_data.get('derby_name'), name=form.cleaned_data.get('real_name'), email=form.cleaned_data.get('email'), source=form.cleaned_data.get('stripe_token'), ) charge = stripe.Charge.create( amount=500, currency='usd', description=event.name, customer=customer, ) except stripe.error.CardError as e: body = e.json_body error = body.get('error', {}) except: error = "A generic error happened when trying to charge your card. Weird." else: ticket = TicketPurchase.objects.create( event=event, real_name=form.cleaned_data.get('real_name'), derby_name=form.cleaned_data.get('derby_name'), email=form.cleaned_data.get('email'), transaction_id=charge.id, amount=5.00, ) send_email( league=league, to_email=form.cleaned_data.get('email'), template="ticket", context={ 'ticket': ticket, 'event': event, }, ) return redirect('tickets:ticket_purchase_done', league_slug=league_slug, event_slug=event_slug) else: error = form.errors return render( request, 'tickets/tickets.html', { 'league_template': league, 'league': league, 'event': event, 'error': error, })