Exemplo n.º 1
0
def session_confirm_guardian(request, session_obj, order, student):
    merge_global_data = {
        'first_name': request.user.first_name,
        'last_name': request.user.last_name,
        'student_first_name': student.first_name,
        'student_last_name': student.last_name,
        'order_id': order.id,
        'class_code': session_obj.course.code,
        'class_title': session_obj.course.title,
        'class_description': session_obj.course.description,
        'class_start_date': arrow.get(session_obj.start_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_start_time': arrow.get(session_obj.start_date).to('local').format('h:mma'),
        'class_end_date': arrow.get(session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_end_time': arrow.get(session_obj.end_date).to('local').format('h:mma'),
        'class_location_name': session_obj.location.name,
        'class_location_address': session_obj.location.address,
        'class_location_address2': session_obj.location.address2,
        'class_location_city': session_obj.location.city,
        'class_location_state': session_obj.location.state,
        'class_location_zip': session_obj.location.zip,
        'class_additional_info': session_obj.additional_info,
        'class_url': session_obj.get_absolute_url(),
        'class_calendar_url': session_obj.get_calendar_url(),
        'microdata_start_date': arrow.get(session_obj.start_date).to('local').isoformat(),
        'microdata_end_date': arrow.get(session_obj.end_date).to('local').isoformat(),
    }

    email(
        subject=f'Upcoming class confirmation for {student.first_name} {student.last_name}',
        template_name='class-confirm-guardian',
        merge_global_data=merge_global_data,
        recipients=[request.user.email],
        preheader='Magical wizards have generated this confirmation. All thanks to the mystical power of coding.',
    )
Exemplo n.º 2
0
def session_confirm_mentor(request, session_obj, order):
    merge_global_data = {
        'first_name': request.user.first_name,
        'last_name': request.user.last_name,
        'order_id': order.id,
        'class_code': session_obj.course.code,
        'class_title': session_obj.course.title,
        'class_description': session_obj.course.description,
        'class_start_date': arrow.get(session_obj.mentor_start_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_start_time': arrow.get(session_obj.mentor_start_date).to('local').format('h:mma'),
        'class_end_date': arrow.get(session_obj.mentor_end_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_end_time': arrow.get(session_obj.mentor_end_date).to('local').format('h:mma'),
        'class_location_name': session_obj.location.name,
        'class_location_address': session_obj.location.address,
        'class_location_address2': session_obj.location.address2,
        'class_location_city': session_obj.location.city,
        'class_location_state': session_obj.location.state,
        'class_location_zip': session_obj.location.zip,
        'class_additional_info': session_obj.additional_info,
        'class_url': f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
        'class_calendar_url': f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        'microdata_start_date': arrow.get(session_obj.mentor_start_date).to('local').isoformat(),
        'microdata_end_date': arrow.get(session_obj.mentor_end_date).to('local').isoformat(),
    }

    email(
        subject='Mentoring confirmation for {} class'.format(
            arrow.get(session_obj.mentor_start_date).to('local').format('MMMM D'),
        ),
        template_name='class-confirm-mentor',
        merge_global_data=merge_global_data,
        recipients=[request.user.email],
        preheader="It's time to use your powers for good.",
    )
Exemplo n.º 3
0
def avatar_updated_handler(sender, instance, **kwargs):

    try:
        original_mentor = Mentor.objects.get(id=instance.id)
    except ObjectDoesNotExist:
        return

    if not instance.avatar:
        return

    if original_mentor.avatar != instance.avatar:
        instance.avatar_approved = False

        img = MIMEImage(instance.avatar.read())
        img.add_header('Content-Id', 'avatar')
        img.add_header("Content-Disposition", "inline", filename="avatar")

        email(
            subject=f"{instance.user.first_name} {instance.user.last_name} | Mentor Avatar Changed",
            template_name='avatar-changed-mentor',
            merge_global_data={
                'first_name': instance.user.first_name,
                'last_name': instance.user.last_name,
                'image': 'avatar',
                'approve_url': f"{settings.SITE_URL}{instance.get_approve_avatar_url()}",
                'reject_url': f"{settings.SITE_URL}{instance.get_reject_avatar_url()}",
            },
            recipients=[settings.CONTACT_EMAIL],
            preheader='Mentor Avatar Changed',
            attachments=[img],
            mixed_subtype='related',
        )
Exemplo n.º 4
0
    def post(self, request, **kwargs):
        if request.POST['human']:
            return messages.error(request, "Bad robot.")

        form = ContactForm(request.POST)

        if form.is_valid():
            email(
                subject=f"{request.POST['name']} | We All Code Contact Form",
                recipients=[settings.CONTACT_EMAIL],
                reply_to=[f"{request.POST['name']}<{request.POST['email']}>"],
                template_name='contact-email',
                merge_global_data={
                    'interest': request.POST['interest'],
                    'message': request.POST['message']
                },
            )

            messages.success(
                request,
                "Thank you for contacting us! We will respond as soon as possible."
            )

            form = ContactForm()
        else:
            messages.error(request, "There was an error. Please try again.")

        context = self.get_context_data(**kwargs)
        context['form'] = form

        return render(request, self.template_name, context)
Exemplo n.º 5
0
def donate_callback(sender, **kwargs):
    ipn_obj = sender

    if ipn_obj.payment_status == ST_PP_COMPLETED:
        donation = get_object_or_404(Donation, id=ipn_obj.invoice)
        donation.is_verified = True

        if not donation.receipt_sent:
            email(
                subject='Donations Receipt from CoderDojoChi',
                template_name='donation-receipt',
                context={
                    'first_name':
                    donation.first_name,
                    'last_name':
                    donation.last_name,
                    'email':
                    donation.email,
                    'amount':
                    '${:0,.2f}'.format(donation.amount),
                    'transaction_date':
                    arrow.get(donation.created_at).to('local').format(
                        'MMMM D, YYYY h:ss a'),
                    'transaction_id':
                    donation.id
                },
                recipients=[donation.email],
                bcc=[settings.CONTACT_EMAIL],
                preheader='Your generous donation is what'
                ' makes CoderDojoChi possible.',
            )

            donation.receipt_sent = True

        donation.save()
Exemplo n.º 6
0
def donate_callback(sender, **kwargs):
    ipn_obj = sender

    if ipn_obj.payment_status == ST_PP_COMPLETED:
        donation = get_object_or_404(Donation, id=ipn_obj.invoice)
        donation.is_verified = True

        if not donation.receipt_sent:
            merge_global_data = {
                'first_name': donation.first_name,
                'last_name': donation.last_name,
                'email': donation.email,
                'amount': f"${donation.amount:0,.2f}",
                'transaction_date': arrow.get(donation.created_at).to('local').format('MMMM D, YYYY h:ss a'),
                'transaction_id': donation.id,
            }

            email(
                subject='Donations Receipt from We All Code',
                template_name='donation-receipt',
                merge_global_data=merge_global_data,
                recipients=[donation.email],
                bcc=[settings.CONTACT_EMAIL],
                preheader="Your generous donation is what makes We All Code possible.",
            )

            donation.receipt_sent = True

        donation.save()
Exemplo n.º 7
0
    def post(self, request, **kwargs):
        if request.POST['human']:
            return messages.error(request, "Bad robot.")

        form = ContactForm(request.POST)

        if form.is_valid():
            email(
                subject=f"{request.POST['name']} | We All Code Contact Form",
                recipients=[settings.CONTACT_EMAIL],
                reply_to=[f"{request.POST['name']}<{request.POST['email']}>"],
                template_name='contact-email',
                merge_global_data={
                    'interest': request.POST['interest'],
                    'message': request.POST['message']
                },
            )

            messages.success(
                request,
                "Thank you for contacting us! We will respond as soon as possible."
            )

            form = ContactForm()
        else:
            messages.error(request, "There was an error. Please try again.")

        context = self.get_context_data(**kwargs)
        context['form'] = form

        return render(request, self.template_name, context)
Exemplo n.º 8
0
def mentor_reject_avatar(request, pk=None):
    mentor = get_object_or_404(Mentor, id=pk)

    if not request.user.is_staff:
        messages.error(request,
                       'You do not have permissions to moderate content.')

        return redirect(
            f"{reverse('account_login')}?next={mentor.get_reject_avatar_url()}"
        )

    mentor.avatar_approved = False
    mentor.save()

    email(
        subject='Your We All Code avatar...',
        template_name='class-announcement-mentor',
        merge_global_data={
            'site_url': settings.SITE_URL,
        },
        recipients=[mentor.user.email],
    )

    messages.warning(request, (
        f"{mentor.user.first_name} {mentor.user.last_name}'s avatar rejected and their account "
        f"is no longer public. An email notice has been sent to the mentor."))

    return redirect('mentors')
Exemplo n.º 9
0
def mentor_reject_avatar(request, pk=None):
    mentor = get_object_or_404(Mentor, id=pk)

    if not request.user.is_staff:
        messages.error(
            request,
            'You do not have permissions to moderate content.'
        )

        return redirect(
            f"{reverse('account_login')}?next={mentor.get_reject_avatar_url()}"
        )

    mentor.avatar_approved = False
    mentor.save()

    email(
        subject='Your We All Code avatar...',
        template_name='class-announcement-mentor',
        merge_global_data={
            'site_url': settings.SITE_URL,
        },
        recipients=[mentor.user.email],
    )

    messages.warning(
        request,
        (
            f"{mentor.user.first_name} {mentor.user.last_name}'s avatar rejected and their account "
            f"is no longer public. An email notice has been sent to the mentor."
        )
    )

    return redirect('mentors')
Exemplo n.º 10
0
def session_confirm_guardian(request, session_obj, order, student):
    merge_global_data = {
        'first_name': request.user.first_name,
        'last_name': request.user.last_name,
        'student_first_name': student.first_name,
        'student_last_name': student.last_name,
        'order_id': order.id,
        'class_code': session_obj.course.code,
        'class_title': session_obj.course.title,
        'class_description': session_obj.course.description,
        'class_start_date': arrow.get(session_obj.start_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_start_time': arrow.get(session_obj.start_date).to('local').format('h:mma'),
        'class_end_date': arrow.get(session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_end_time': arrow.get(session_obj.end_date).to('local').format('h:mma'),
        'class_location_name': session_obj.location.name,
        'class_location_address': session_obj.location.address,
        'class_location_city': session_obj.location.city,
        'class_location_state': session_obj.location.state,
        'class_location_zip': session_obj.location.zip,
        'class_additional_info': session_obj.additional_info,
        'class_url': session_obj.get_absolute_url(),
        'class_calendar_url': session_obj.get_calendar_url(),
        'microdata_start_date': arrow.get(session_obj.start_date).to('local').isoformat(),
        'microdata_end_date': arrow.get(session_obj.end_date).to('local').isoformat(),
    }

    email(
        subject=f'Upcoming class confirmation for {student.first_name} {student.last_name}',
        template_name='class-confirm-guardian',
        merge_global_data=merge_global_data,
        recipients=[request.user.email],
        preheader='Magical wizards have generated this confirmation. All thanks to the mystical power of coding.',
    )
Exemplo n.º 11
0
def session_confirm_mentor(request, session_obj, order):
    merge_global_data = {
        'first_name': request.user.first_name,
        'last_name': request.user.last_name,
        'order_id': order.id,
        'class_code': session_obj.course.code,
        'class_title': session_obj.course.title,
        'class_description': session_obj.course.description,
        'class_start_date': arrow.get(session_obj.mentor_start_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_start_time': arrow.get(session_obj.mentor_start_date).to('local').format('h:mma'),
        'class_end_date': arrow.get(session_obj.mentor_end_date).to('local').format('dddd, MMMM D, YYYY'),
        'class_end_time': arrow.get(session_obj.mentor_end_date).to('local').format('h:mma'),
        'class_location_name': session_obj.location.name,
        'class_location_address': session_obj.location.address,
        'class_location_city': session_obj.location.city,
        'class_location_state': session_obj.location.state,
        'class_location_zip': session_obj.location.zip,
        'class_additional_info': session_obj.additional_info,
        'class_url': f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
        'class_calendar_url': f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        'microdata_start_date': arrow.get(session_obj.mentor_start_date).to('local').isoformat(),
        'microdata_end_date': arrow.get(session_obj.mentor_end_date).to('local').isoformat(),
    }

    email(
        subject='Mentoring confirmation for {} class'.format(
            arrow.get(session_obj.mentor_start_date).to('local').format('MMMM D'),
        ),
        template_name='class-confirm-mentor',
        merge_global_data=merge_global_data,
        recipients=[request.user.email],
        preheader="It's time to use your powers for good.",
    )
Exemplo n.º 12
0
def donate_callback(sender, **kwargs):
    ipn_obj = sender

    if ipn_obj.payment_status == ST_PP_COMPLETED:
        donation = get_object_or_404(Donation, id=ipn_obj.invoice)
        donation.verified = True

        if not donation.receipt_sent:
            email(
                subject='Donations Receipt from CoderDojoChi',
                template_name='donation-receipt',
                context={
                    'first_name': donation.first_name,
                    'last_name': donation.last_name,
                    'email': donation.email,
                    'amount': '${:0,.2f}'.format(donation.amount),
                    'transaction_date': arrow.get(
                        donation.created_at
                    ).to('local').format(
                        'MMMM D, YYYY h:ss a'
                    ),
                    'transaction_id': donation.id
                },
                recipients=[donation.email],
                bcc=[settings.CONTACT_EMAIL],
                preheader='Your generous donation is what'
                          ' makes CoderDojoChi possible.',
            )

            donation.receipt_sent = True

        donation.save()
Exemplo n.º 13
0
    def create_new_user(self, request, user, next_url):
        if request.POST.get('role') == 'mentor':
            role = 'mentor'
            account, created = Mentor.objects.get_or_create(user=user)
        else:
            role = 'guardian'
            account, created = Guardian.objects.get_or_create(user=user)

        account.user.first_name = user.first_name
        account.user.last_name = user.last_name
        account.save()

        user.role = role
        user.save()

        merge_global_data = {
            'user': user.username,
            'first_name': user.first_name,
            'last_name': user.last_name
        }

        next_url = f"?next={next_url}" if next_url else None

        if role == 'mentor':
            # check for next upcoming meeting
            next_meeting = Meeting.objects.filter(
                is_active=True,
                is_public=True
            ).order_by('start_date').first()

            if next_meeting:
                merge_global_data['next_intro_meeting_url'] = f"{settings.SITE_URL}{next_meeting.get_absolute_url()}"
                merge_global_data['next_intro_meeting_calendar_url'] = (
                    f"{settings.SITE_URL}{next_meeting.get_calendar_url()}"
                )
            if not next_url:
                next_url = reverse('account_home')
        else:
            # check for next upcoming class
            next_class = Session.objects.filter(
                is_active=True
            ).order_by('start_date').first()

            if next_class:
                merge_global_data['next_class_url'] = f"{settings.SITE_URL}{next_class.get_absolute_url()}"
                merge_global_data['next_class_calendar_url'] = f"{settings.SITE_URL}{next_class.get_calendar_url()}"

            if not next_url:
                next_url = reverse('welcome')

        email(
            subject='Welcome!',
            template_name=f"welcome-{role}",
            merge_global_data=merge_global_data,
            recipients=[user.email],
            preheader='Your adventure awaits!',
        )

        return redirect(next_url)
Exemplo n.º 14
0
    def create_new_user(self, request, user, next_url):
        if request.POST.get('role') == 'mentor':
            role = 'mentor'
            account, created = Mentor.objects.get_or_create(user=user)
        else:
            role = 'guardian'
            account, created = Guardian.objects.get_or_create(user=user)

        account.user.first_name = user.first_name
        account.user.last_name = user.last_name
        account.save()

        user.role = role
        user.save()

        merge_global_data = {
            'user': user.username,
            'first_name': user.first_name,
            'last_name': user.last_name
        }

        next_url = f"?next={next_url}" if next_url else None

        if role == 'mentor':
            # check for next upcoming meeting
            next_meeting = Meeting.objects.filter(
                is_active=True, is_public=True).order_by('start_date').first()

            if next_meeting:
                merge_global_data[
                    'next_intro_meeting_url'] = f"{settings.SITE_URL}{next_meeting.get_absolute_url()}"
                merge_global_data['next_intro_meeting_calendar_url'] = (
                    f"{settings.SITE_URL}{next_meeting.get_calendar_url()}")
            if not next_url:
                next_url = reverse('account_home')
        else:
            # check for next upcoming class
            next_class = Session.objects.filter(
                is_active=True).order_by('start_date').first()

            if next_class:
                merge_global_data[
                    'next_class_url'] = f"{settings.SITE_URL}{next_class.get_absolute_url()}"
                merge_global_data[
                    'next_class_calendar_url'] = f"{settings.SITE_URL}{next_class.get_calendar_url()}"

            if not next_url:
                next_url = reverse('welcome')

        email(
            subject='Welcome!',
            template_name=f"welcome-{role}",
            merge_global_data=merge_global_data,
            recipients=[user.email],
            preheader='Your adventure awaits!',
        )

        return redirect(next_url)
Exemplo n.º 15
0
 def send_email(self):
     # send email using the self.cleaned_data dictionary
     data = self.cleaned_data
     email(
         subject=f"{data['name']} | We All Code Contact Form",
         recipients=[settings.CONTACT_EMAIL],
         reply_to=[f"{data['name']}<{data['email']}>"],
         template_name='contact-email',
         merge_global_data={
             'interest': data['interest'],
             'message': data['message']
         },
     )
Exemplo n.º 16
0
def contact(request, template_name="contact.html"):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        human = True

        if form.is_valid():
            if request.POST['human']:
                messages.error(request, 'Bad robot.')
                human = False

            if human:
                email(
                    subject=f"{request.POST['name']} | We All Code Contact Form",
                    recipients=[settings.CONTACT_EMAIL],
                    reply_to=[f"{request.POST['name']}<{request.POST['email']}>"],
                    template_name='contact-email',
                    merge_global_data={
                        'message': request.POST['message'],
                    },
                )

                messages.success(
                    request,
                    "Thank you for contacting us! We will respond as soon as possible."
                )

            form = ContactForm()
        else:
            messages.error(
                request,
                "There was an error. Please try again."
            )
    else:
        form = ContactForm()

    return render(
        request,
        template_name,
        {
            'form': form
        }
    )
Exemplo n.º 17
0
def contact(request, template_name="contact.html"):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        human = True

        if form.is_valid():
            if request.POST['human']:
                messages.error(request, 'Bad robot.')
                human = False

            if human:
                email(
                    subject=f"{request.POST['name']} | We All Code Contact Form",
                    recipients=[settings.CONTACT_EMAIL],
                    reply_to=[f"{request.POST['name']}<{request.POST['email']}>"],
                    template_name='contact-email',
                    merge_global_data={
                        'message': request.POST['message'],
                    },
                )

                messages.success(
                    request,
                    "Thank you for contacting us! We will respond as soon as possible."
                )

            form = ContactForm()
        else:
            messages.error(
                request,
                "There was an error. Please try again."
            )
    else:
        form = ContactForm()

    return render(
        request,
        template_name,
        {
            'form': form
        }
    )
Exemplo n.º 18
0
def avatar_updated_handler(sender, instance, **kwargs):

    try:
        original_mentor = Mentor.objects.get(id=instance.id)
    except ObjectDoesNotExist:
        return

    if not instance.avatar:
        return

    if original_mentor.avatar != instance.avatar:
        instance.avatar_approved = False

        img = MIMEImage(instance.avatar.read())
        img.add_header('Content-Id', 'avatar')
        img.add_header("Content-Disposition", "inline", filename="avatar")

        email(
            subject=
            f"{instance.user.first_name} {instance.user.last_name} | Mentor Avatar Changed",
            template_name='avatar-changed-mentor',
            merge_global_data={
                'first_name':
                instance.user.first_name,
                'last_name':
                instance.user.last_name,
                'image':
                'avatar',
                'approve_url':
                f"{settings.SITE_URL}{instance.get_approve_avatar_url()}",
                'reject_url':
                f"{settings.SITE_URL}{instance.get_reject_avatar_url()}",
            },
            recipients=[settings.CONTACT_EMAIL],
            preheader='Mentor Avatar Changed',
            attachments=[img],
            mixed_subtype='related',
        )
Exemplo n.º 19
0
def donate_callback(sender, **kwargs):
    ipn_obj = sender

    if ipn_obj.payment_status == ST_PP_COMPLETED:
        donation = get_object_or_404(Donation, id=ipn_obj.invoice)
        donation.is_verified = True

        if not donation.receipt_sent:
            merge_global_data = {
                'first_name':
                donation.first_name,
                'last_name':
                donation.last_name,
                'email':
                donation.email,
                'amount':
                f"${donation.amount:0,.2f}",
                'transaction_date':
                arrow.get(donation.created_at).to('local').format(
                    'MMMM D, YYYY h:ss a'),
                'transaction_id':
                donation.id,
            }

            email(
                subject='Donations Receipt from We All Code',
                template_name='donation-receipt',
                merge_global_data=merge_global_data,
                recipients=[donation.email],
                bcc=[settings.CONTACT_EMAIL],
                preheader=
                "Your generous donation is what makes We All Code possible.",
            )

            donation.receipt_sent = True

        donation.save()
Exemplo n.º 20
0
def avatar_updated_handler(sender, instance, **kwargs):

    try:
        original_mentor = Mentor.objects.get(id=instance.id)
    except ObjectDoesNotExist:
        return

    if not instance.avatar:
        return

    if original_mentor.avatar != instance.avatar:

        instance.avatar_approved = False

        msg = email(
            subject='{} {} | Mentor Avatar Changed'.format(
                instance.user.first_name,
                instance.user.last_name
            ),
            template_name='avatar-changed-mentor',
            context={
                'first_name': instance.user.first_name,
                'last_name': instance.user.last_name,
                'image': 'avatar',
                'approve_url': instance.get_approve_avatar_url(),
                'reject_url': instance.get_reject_avatar_url(),
            },
            recipients=[settings.CONTACT_EMAIL],
            preheader='Mentor Avatar Changed',
            send=False
        )

        msg.mixed_subtype = 'related'

        img = MIMEImage(instance.avatar.read())
        img.add_header('Content-Id', 'avatar')
        img.add_header("Content-Disposition", "inline", filename="avatar")

        msg.attach(img)

        msg.send()
Exemplo n.º 21
0
def avatar_updated_handler(sender, instance, **kwargs):

    try:
        original_mentor = Mentor.objects.get(id=instance.id)
    except ObjectDoesNotExist:
        return

    if not instance.avatar:
        return

    if original_mentor.avatar != instance.avatar:

        instance.avatar_approved = False

        msg = email(subject='{} {} | Mentor Avatar Changed'.format(
            instance.user.first_name, instance.user.last_name),
                    template_name='avatar-changed-mentor',
                    context={
                        'first_name': instance.user.first_name,
                        'last_name': instance.user.last_name,
                        'image': 'avatar',
                        'approve_url': instance.get_approve_avatar_url(),
                        'reject_url': instance.get_reject_avatar_url(),
                    },
                    recipients=[settings.CONTACT_EMAIL],
                    preheader='Mentor Avatar Changed',
                    send=False)

        msg.mixed_subtype = 'related'

        img = MIMEImage(instance.avatar.read())
        img.add_header('Content-Id', 'avatar')
        img.add_header("Content-Disposition", "inline", filename="avatar")

        msg.attach(img)

        msg.send()
Exemplo n.º 22
0
def meeting_sign_up(request, pk, template_name="meeting-sign-up.html"):
    meeting_obj = get_object_or_404(Meeting, pk=pk)

    mentor = get_object_or_404(
        Mentor,
        user=request.user
    )

    meeting_orders = MeetingOrder.objects.filter(
        meeting=meeting_obj,
        is_active=True
    )

    user_meeting_order = meeting_orders.filter(mentor=mentor)
    user_signed_up = True if user_meeting_order.count() else False

    if request.method == 'POST':

        if user_signed_up:
            meeting_order = get_object_or_404(
                MeetingOrder,
                meeting=meeting_obj,
                mentor=mentor
            )
            meeting_order.is_active = False
            meeting_order.save()

            messages.success(
                request,
                'Thanks for letting us know!'
            )

        else:
            if not settings.DEBUG:
                ip = (
                    request.META['HTTP_X_FORWARDED_FOR'] or
                    request.META['REMOTE_ADDR']
                )
            else:
                ip = request.META['REMOTE_ADDR']

            meeting_order, created = MeetingOrder.objects.get_or_create(
                mentor=mentor,
                meeting=meeting_obj
            )

            meeting_order.ip = ip
            meeting_order.is_active = True
            meeting_order.save()

            messages.success(
                request,
                'Success! See you there!'
            )

            merge_global_data = {
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'order_id': meeting_order.id,
                'meeting_title': meeting_obj.meeting_type.title,
                'meeting_description': meeting_obj.meeting_type.description,
                'meeting_start_date': arrow.get(meeting_obj.start_date).to('local').format('dddd, MMMM D, YYYY'),
                'meeting_start_time': arrow.get(meeting_obj.start_date).to('local').format('h:mma'),
                'meeting_end_date': arrow.get(meeting_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
                'meeting_end_time': arrow.get(meeting_obj.end_date).to('local').format('h:mma'),
                'meeting_location_name': meeting_obj.location.name,
                'meeting_location_address': meeting_obj.location.address,
                'meeting_location_city': meeting_obj.location.city,
                'meeting_location_state': meeting_obj.location.state,
                'meeting_location_zip': meeting_obj.location.zip,
                'meeting_additional_info': meeting_obj.additional_info,
                'meeting_url': f"{settings.SITE_URL}{meeting_obj.get_absolute_url()}",
                'meeting_calendar_url': f"{settings.SITE_URL}{meeting_obj.get_calendar_url()}",
                'microdata_start_date': arrow.get(meeting_obj.start_date).to('local').isoformat(),
                'microdata_end_date': arrow.get(meeting_obj.end_date).to('local').isoformat(),
            }

            email(
                subject='Upcoming mentor meeting confirmation',
                template_name='meeting-confirm-mentor',
                merge_global_data=merge_global_data,
                recipients=[request.user.email],
                preheader=(
                    f"Thanks for signing up for our next meeting, {request.user.first_name}. "
                    f"We look forward to seeing there."
                ),
            )

        return redirect('meeting-detail', meeting_obj.id)

    return render(request, template_name, {
        'meeting': meeting_obj,
        'user_signed_up': user_signed_up
    })
Exemplo n.º 23
0
def session_announce_guardians(request, pk):
    if not request.user.is_staff:
        messages.error(
            request,
            'You do not have permission to access this page.'
        )
        return redirect('home')

    session_obj = get_object_or_404(Session, pk=pk)

    if not session_obj.announced_date_guardians:
        merge_data = {}
        merge_global_data = {
            'class_code': session_obj.course.code,
            'class_title': session_obj.course.title,
            'class_description': session_obj.course.description,
            'class_start_date': arrow.get(session_obj.start_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_start_time': arrow.get(session_obj.start_date).to('local').format('h:mma'),
            'class_end_date': arrow.get(session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_end_time': arrow.get(session_obj.end_date).to('local').format('h:mma'),
            'min_age_limitation': session_obj.min_age_limitation,
            'max_age_limitation': session_obj.max_age_limitation,
            'class_location_name': session_obj.location.name,
            'class_location_address': session_obj.location.address,
            'class_location_city': session_obj.location.city,
            'class_location_state': session_obj.location.state,
            'class_location_zip': session_obj.location.zip,
            'class_additional_info': session_obj.additional_info,
            'class_url': f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
            'class_calendar_url': f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        }
        recipients = []

        guardians = Guardian.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        for guardian in guardians:
            recipients.append(guardian.user.email)
            merge_data[guardian.user.email] = {
                'first_name': guardian.user.first_name,
                'last_name': guardian.user.last_name,
            }

        email(
            subject='New We All Code class date announced!',
            template_name='class-announcement-guardian',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader="We're super excited to bring you another class date. Sign up to reserve your spot",
        )

        session_obj.announced_date_guardians = timezone.now()
        session_obj.save()

        messages.success(
            request,
            f'Session announced to {guardians.count()} guardians!'
        )

    else:
        messages.warning(
            request,
            'Session already announced.'
        )

    return redirect('cdc-admin')
Exemplo n.º 24
0
def session_announce_mentors(request, pk):
    if not request.user.is_staff:
        messages.error(
            request,
            'You do not have permission to access this page.'
        )
        return redirect('home')

    session_obj = get_object_or_404(Session, pk=pk)

    if not session_obj.announced_date_mentors:
        merge_data = {}
        merge_global_data = {
            'class_code': session_obj.course.code,
            'class_title': session_obj.course.title,
            'class_description': session_obj.course.description,
            'class_start_date': arrow.get(session_obj.mentor_start_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_start_time': arrow.get(session_obj.mentor_start_date).to('local').format('h:mma'),
            'class_end_date': arrow.get(session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_end_time': arrow.get(session_obj.end_date).to('local').format('h:mma'),
            'min_age_limitation': session_obj.min_age_limitation,
            'max_age_limitation': session_obj.max_age_limitation,
            'class_location_name': session_obj.location.name,
            'class_location_address': session_obj.location.address,
            'class_location_city': session_obj.location.city,
            'class_location_state': session_obj.location.state,
            'class_location_zip': session_obj.location.zip,
            'class_additional_info': session_obj.additional_info,
            'class_url': f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
            'class_calendar_url': f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        }
        recipients = []

        # send mentor announcements
        mentors = Mentor.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        for mentor in mentors:
            recipients.append(mentor.user.email)
            merge_data[mentor.user.email] = {
                'first_name': mentor.user.first_name,
                'last_name': mentor.user.last_name,
            }

        email(
            subject='New We All Code class date announced! Come mentor!',
            template_name='class-announcement-mentor',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader='Help us make a huge difference! A brand new class was just announced.',
        )

        session_obj.announced_date_mentors = timezone.now()
        session_obj.save()

        messages.success(
            request,
            f'Session announced to {mentors.count()} mentors.'
        )

    else:
        messages.warning(
            request,
            f'Session already announced.'
        )

    return redirect('cdc-admin')
Exemplo n.º 25
0
def session_announce_guardians(request, pk):
    if not request.user.is_staff:
        messages.error(request,
                       'You do not have permission to access this page.')
        return redirect('home')

    session_obj = get_object_or_404(Session, pk=pk)

    if not session_obj.announced_date_guardians:
        merge_data = {}
        merge_global_data = {
            'class_code':
            session_obj.course.code,
            'class_title':
            session_obj.course.title,
            'class_description':
            session_obj.course.description,
            'class_start_date':
            arrow.get(session_obj.start_date).to('local').format(
                'dddd, MMMM D, YYYY'),
            'class_start_time':
            arrow.get(session_obj.start_date).to('local').format('h:mma'),
            'class_end_date':
            arrow.get(
                session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_end_time':
            arrow.get(session_obj.end_date).to('local').format('h:mma'),
            'minimum_age':
            session_obj.minimum_age,
            'maximum_age':
            session_obj.maximum_age,
            'class_location_name':
            session_obj.location.name,
            'class_location_address':
            session_obj.location.address,
            'class_location_city':
            session_obj.location.city,
            'class_location_state':
            session_obj.location.state,
            'class_location_zip':
            session_obj.location.zip,
            'class_additional_info':
            session_obj.additional_info,
            'class_url':
            f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
            'class_calendar_url':
            f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        }
        recipients = []

        guardians = Guardian.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        for guardian in guardians:
            recipients.append(guardian.user.email)
            merge_data[guardian.user.email] = {
                'first_name': guardian.user.first_name,
                'last_name': guardian.user.last_name,
            }

        email(
            subject='New We All Code class date announced!',
            template_name='class-announcement-guardian',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader=
            "We're super excited to bring you another class date. Sign up to reserve your spot",
            unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
        )

        session_obj.announced_date_guardians = timezone.now()
        session_obj.save()

        messages.success(
            request, f'Session announced to {guardians.count()} guardians!')

    else:
        messages.warning(request, 'Session already announced.')

    return redirect('cdc-admin')
Exemplo n.º 26
0
def session_announce_mentors(request, pk):
    if not request.user.is_staff:
        messages.error(request,
                       'You do not have permission to access this page.')
        return redirect('home')

    session_obj = get_object_or_404(Session, pk=pk)

    if not session_obj.announced_date_mentors:
        merge_data = {}
        merge_global_data = {
            'class_code':
            session_obj.course.code,
            'class_title':
            session_obj.course.title,
            'class_description':
            session_obj.course.description,
            'class_start_date':
            arrow.get(session_obj.mentor_start_date).to('local').format(
                'dddd, MMMM D, YYYY'),
            'class_start_time':
            arrow.get(
                session_obj.mentor_start_date).to('local').format('h:mma'),
            'class_end_date':
            arrow.get(
                session_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'class_end_time':
            arrow.get(session_obj.end_date).to('local').format('h:mma'),
            'minimum_age':
            session_obj.minimum_age,
            'maximum_age':
            session_obj.maximum_age,
            'class_location_name':
            session_obj.location.name,
            'class_location_address':
            session_obj.location.address,
            'class_location_city':
            session_obj.location.city,
            'class_location_state':
            session_obj.location.state,
            'class_location_zip':
            session_obj.location.zip,
            'class_additional_info':
            session_obj.additional_info,
            'class_url':
            f"{settings.SITE_URL}{session_obj.get_absolute_url()}",
            'class_calendar_url':
            f"{settings.SITE_URL}{session_obj.get_calendar_url()}",
        }
        recipients = []

        # send mentor announcements
        mentors = Mentor.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        for mentor in mentors:
            recipients.append(mentor.user.email)
            merge_data[mentor.user.email] = {
                'first_name': mentor.user.first_name,
                'last_name': mentor.user.last_name,
            }

        email(
            subject='New We All Code class date announced! Come mentor!',
            template_name='class-announcement-mentor',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader=
            'Help us make a huge difference! A brand new class was just announced.',
            unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
        )

        session_obj.announced_date_mentors = timezone.now()
        session_obj.save()

        messages.success(request,
                         f'Session announced to {mentors.count()} mentors.')

    else:
        messages.warning(request, f'Session already announced.')

    return redirect('cdc-admin')
Exemplo n.º 27
0
def meeting_announce(request, pk):
    if not request.user.is_staff:
        messages.error(
            request,
            'You do not have permission to access this page.'
        )
        return redirect('home')

    meeting_obj = get_object_or_404(Meeting, pk=pk)

    if not meeting_obj.announced_date:
        merge_data = {}
        merge_global_data = {
            'meeting_title': meeting_obj.meeting_type.title,
            'meeting_description': meeting_obj.meeting_type.description,
            'meeting_start_date': arrow.get(meeting_obj.start_date).to('local').format('dddd, MMMM D, YYYY'),
            'meeting_start_time': arrow.get(meeting_obj.start_date).to('local').format('h:mma'),
            'meeting_end_date': arrow.get(meeting_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'meeting_end_time': arrow.get(meeting_obj.end_date).to('local').format('h:mma'),
            'meeting_location_name': meeting_obj.location.name,
            'meeting_location_address': meeting_obj.location.address,
            'meeting_location_city': meeting_obj.location.city,
            'meeting_location_state': meeting_obj.location.state,
            'meeting_location_zip': meeting_obj.location.zip,
            'meeting_additional_info': meeting_obj.additional_info,
            'meeting_url': f"{settings.SITE_URL}{meeting_obj.get_absolute_url()}",
            'meeting_calendar_url': f"{settings.SITE_URL}{meeting_obj.get_calendar_url()}",
        }

        mentors = Mentor.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        recipients = []
        for mentor in mentors:
            recipients.append(mentor.user.email)
            merge_data[mentor.user.email] = {
                'first_name': mentor.user.first_name,
                'last_name': mentor.user.last_name,
            }

        email(
            subject='New meeting announced!',
            template_name='meeting-announcement-mentor',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader='A new meeting has been announced. Come join us for some amazing fun!',
        )

        meeting_obj.announced_date = timezone.now()
        meeting_obj.save()

        messages.success(
            request,
            f"Meeting announced to {mentors.count()} mentors."
        )
    else:
        messages.warning(
            request,
            'Meeting already announced.'
        )

    return redirect('cdc-admin')
Exemplo n.º 28
0
    def do(self):
        orders_within_a_week = Order.objects.filter(
            is_active=True,
            week_reminder_sent=False,
            session__start_date__lte=(timezone.now() + datetime.timedelta(days=7)),
            session__start_date__gte=(timezone.now() + datetime.timedelta(days=1)),
        )
        orders_within_a_day = Order.objects.filter(
            is_active=True,
            day_reminder_sent=False,
            session__start_date__lte=(timezone.now() + datetime.timedelta(days=1)),
            session__start_date__gte=(timezone.now() - datetime.timedelta(days=2)),
        )
        sessions_within_a_week = Session.objects.filter(
            is_active=True,
            mentors_week_reminder_sent=False,
            start_date__lte=(timezone.now() + datetime.timedelta(days=7)),
            start_date__gte=(timezone.now() + datetime.timedelta(days=1)),
        )
        sessions_within_a_day = Session.objects.filter(
            is_active=True,
            mentors_day_reminder_sent=False,
            start_date__lte=(timezone.now() + datetime.timedelta(days=1)),
            start_date__gte=(timezone.now() - datetime.timedelta(days=2)),
        )

        # Clear email send data
        merge_data = {}
        recipients = []

        for order in orders_within_a_week:
            recipients.append(order.guardian.user.email)
            merge_data[order.guardian.user.email] = {
                'first_name': order.guardian.user.first_name,
                'last_name': order.guardian.user.last_name,
                'student_first_name': order.student.first_name,
                'student_last_name': order.student.last_name,
                'class_code': order.session.course.code,
                'class_title': order.session.course.title,
                'class_description': order.session.course.description,
                'class_start_date': arrow.get(order.session.start_date).to('local').format('dddd, MMMM D, YYYY'),
                'class_start_time': arrow.get(order.session.start_date).to('local').format('h:mma'),
                'class_end_date': arrow.get(order.session.end_date).to('local').format('dddd, MMMM D, YYYY'),
                'class_end_time': arrow.get(order.session.end_date).to('local').format('h:mma'),
                'class_location_name': order.session.location.name,
                'class_location_address': order.session.location.address,
                'class_location_city': order.session.location.city,
                'class_location_state': order.session.location.state,
                'class_location_zip': order.session.location.zip,
                'class_additional_info': order.session.additional_info,
                'class_url': f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                'class_calendar_url': f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                'microdata_start_date': arrow.get(order.session.start_date).to('local').isoformat(),
                'microdata_end_date': arrow.get(order.session.end_date).to('local').isoformat(),
                'order_id': order.id,
            }

        email(
            subject='Upcoming class reminder',
            template_name='class-reminder-guardian-one-week',
            merge_data=merge_data,
            recipients=recipients,
            preheader='Your class is just a few days away!',
        )

        for order in orders_within_a_week:
            order.week_reminder_sent = True
            order.save()

        # Clear email send data
        merge_data = {}
        recipients = []

        for order in orders_within_a_day:
            recipients.append(order.guardian.user.email)
            merge_data[order.guardian.user.email] = {
                'first_name': order.guardian.user.first_name,
                'last_name': order.guardian.user.last_name,
                'student_first_name': order.student.first_name,
                'student_last_name': order.student.last_name,
                'class_code': order.session.course.code,
                'class_title': order.session.course.title,
                'class_description': order.session.course.description,
                'class_start_date': arrow.get(order.session.start_date).to('local').format('dddd, MMMM D, YYYY'),
                'class_start_time': arrow.get(order.session.start_date).to('local').format('h:mma'),
                'class_end_date': arrow.get(order.session.end_date).to('local').format('dddd, MMMM D, YYYY'),
                'class_end_time': arrow.get(order.session.end_date).to('local').format('h:mma'),
                'class_location_name': order.session.location.name,
                'class_location_address': order.session.location.address,
                'class_location_city': order.session.location.city,
                'class_location_state': order.session.location.state,
                'class_location_zip': order.session.location.zip,
                'class_additional_info': order.session.additional_info,
                'class_url': f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                'class_calendar_url': f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                'microdata_start_date': arrow.get(order.session.start_date).to('local').isoformat(),
                'microdata_end_date': arrow.get(order.session.end_date).to('local').isoformat(),
                'order_id': order.id,
            }

        email(
            subject='Your class is coming up!',
            template_name='class-reminder-guardian-24-hour',
            merge_data=merge_data,
            recipients=recipients,
            preheader='Your class is just hours away!',
        )

        for order in orders_within_a_day:
            order.day_reminder_sent = True
            order.save()

        for session in sessions_within_a_week:
            orders = MentorOrder.objects.filter(session=session)

            # Clear email send data
            merge_data = {}
            recipients = []

            for order in orders:
                recipients.append(order.mentor.user.email)
                merge_data[order.mentor.user.email] = {
                    'first_name': order.mentor.user.first_name,
                    'last_name': order.mentor.user.last_name,
                    'class_code': order.session.course.code,
                    'class_title': order.session.course.title,
                    'class_description': order.session.course.description,
                    'class_start_date': arrow.get(
                        order.session.mentor_start_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_start_time': arrow.get(order.session.mentor_start_date).to('local').format('h:mma'),
                    'class_end_date': arrow.get(order.session.mentor_end_date).to('local').format('dddd, MMMM D, YYYY'),
                    'class_end_time': arrow.get(order.session.mentor_end_date).to('local').format('h:mma'),
                    'class_location_name': order.session.location.name,
                    'class_location_address': order.session.location.address,
                    'class_location_city': order.session.location.city,
                    'class_location_state': order.session.location.state,
                    'class_location_zip': order.session.location.zip,
                    'class_additional_info': order.session.additional_info,
                    'class_url': f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                    'class_calendar_url': f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                    'microdata_start_date': arrow.get(order.session.start_date).to('local').isoformat(),
                    'microdata_end_date': arrow.get(order.session.end_date).to('local').isoformat(),
                    'order_id': order.id,
                }

            email(
                subject='Your We All Code class is in less than a week!',
                template_name='class-reminder-mentor-one-week',
                merge_data=merge_data,
                recipients=recipients,
                preheader='The class is just a few days away!',
            )

            session.mentors_week_reminder_sent = True
            session.save()

        for session in sessions_within_a_day:
            orders = MentorOrder.objects.filter(session=session)

            for order in orders:
                recipients.append(order.mentor.user.email)
                merge_data[order.mentor.user.email] = {
                    'first_name': order.mentor.user.first_name,
                    'last_name': order.mentor.user.last_name,
                    'class_code': order.session.course.code,
                    'class_title': order.session.course.title,
                    'class_description': order.session.course.description,
                    'class_start_date': arrow.get(
                        order.session.mentor_start_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_start_time': arrow.get(order.session.mentor_start_date).to('local').format('h:mma'),
                    'class_end_date': arrow.get(order.session.mentor_end_date).to('local').format('dddd, MMMM D, YYYY'),
                    'class_end_time': arrow.get(order.session.mentor_end_date).to('local').format('h:mma'),
                    'class_location_name': order.session.location.name,
                    'class_location_address': order.session.location.address,
                    'class_location_city': order.session.location.city,
                    'class_location_state': order.session.location.state,
                    'class_location_zip': order.session.location.zip,
                    'class_additional_info': order.session.additional_info,
                    'class_url': f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                    'class_calendar_url': f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                    'microdata_start_date': arrow.get(order.session.start_date).to('local').isoformat(),
                    'microdata_end_date': arrow.get(order.session.end_date).to('local').isoformat(),
                    'order_id': order.id,
                }

            email(
                subject='Your We All Code class is tomorrow!',
                template_name='class-reminder-mentor-24-hour',
                merge_data=merge_data,
                recipients=recipients,
                preheader='The class is just a few hours away!',
            )

            session.mentors_day_reminder_sent = True
            session.save()
Exemplo n.º 29
0
    def do(self):
        orders_within_a_week = Order.objects.filter(
            is_active=True,
            week_reminder_sent=False,
            session__start_date__lte=(timezone.now() +
                                      datetime.timedelta(days=7)),
            session__start_date__gte=(timezone.now() +
                                      datetime.timedelta(days=1)),
        )
        orders_within_a_day = Order.objects.filter(
            is_active=True,
            day_reminder_sent=False,
            session__start_date__lte=(timezone.now() +
                                      datetime.timedelta(days=1)),
            session__start_date__gte=(timezone.now() -
                                      datetime.timedelta(days=2)),
        )
        sessions_within_a_week = Session.objects.filter(
            is_active=True,
            mentors_week_reminder_sent=False,
            start_date__lte=(timezone.now() + datetime.timedelta(days=7)),
            start_date__gte=(timezone.now() + datetime.timedelta(days=1)),
        )
        sessions_within_a_day = Session.objects.filter(
            is_active=True,
            mentors_day_reminder_sent=False,
            start_date__lte=(timezone.now() + datetime.timedelta(days=1)),
            start_date__gte=(timezone.now() - datetime.timedelta(days=2)),
        )

        # Clear email send data
        merge_data = {}
        recipients = []

        for order in orders_within_a_week:
            recipients.append(order.guardian.user.email)
            merge_data[order.guardian.user.email] = {
                'first_name':
                order.guardian.user.first_name,
                'last_name':
                order.guardian.user.last_name,
                'student_first_name':
                order.student.first_name,
                'student_last_name':
                order.student.last_name,
                'class_code':
                order.session.course.code,
                'class_title':
                order.session.course.title,
                'class_description':
                order.session.course.description,
                'class_start_date':
                arrow.get(order.session.start_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'class_start_time':
                arrow.get(
                    order.session.start_date).to('local').format('h:mma'),
                'class_end_date':
                arrow.get(order.session.end_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'class_end_time':
                arrow.get(order.session.end_date).to('local').format('h:mma'),
                'class_location_name':
                order.session.location.name,
                'class_location_address':
                order.session.location.address,
                'class_location_city':
                order.session.location.city,
                'class_location_state':
                order.session.location.state,
                'class_location_zip':
                order.session.location.zip,
                'class_additional_info':
                order.session.additional_info,
                'class_url':
                f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                'class_calendar_url':
                f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                'microdata_start_date':
                arrow.get(order.session.start_date).to('local').isoformat(),
                'microdata_end_date':
                arrow.get(order.session.end_date).to('local').isoformat(),
                'order_id':
                order.id,
            }

        email(
            subject='Upcoming class reminder',
            template_name='class-reminder-guardian-one-week',
            merge_data=merge_data,
            recipients=recipients,
            preheader='Your class is just a few days away!',
            unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
        )

        for order in orders_within_a_week:
            order.week_reminder_sent = True
            order.save()

        # Clear email send data
        merge_data = {}
        recipients = []

        for order in orders_within_a_day:
            recipients.append(order.guardian.user.email)
            merge_data[order.guardian.user.email] = {
                'first_name':
                order.guardian.user.first_name,
                'last_name':
                order.guardian.user.last_name,
                'student_first_name':
                order.student.first_name,
                'student_last_name':
                order.student.last_name,
                'class_code':
                order.session.course.code,
                'class_title':
                order.session.course.title,
                'class_description':
                order.session.course.description,
                'class_start_date':
                arrow.get(order.session.start_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'class_start_time':
                arrow.get(
                    order.session.start_date).to('local').format('h:mma'),
                'class_end_date':
                arrow.get(order.session.end_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'class_end_time':
                arrow.get(order.session.end_date).to('local').format('h:mma'),
                'class_location_name':
                order.session.location.name,
                'class_location_address':
                order.session.location.address,
                'class_location_city':
                order.session.location.city,
                'class_location_state':
                order.session.location.state,
                'class_location_zip':
                order.session.location.zip,
                'class_additional_info':
                order.session.additional_info,
                'class_url':
                f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                'class_calendar_url':
                f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                'microdata_start_date':
                arrow.get(order.session.start_date).to('local').isoformat(),
                'microdata_end_date':
                arrow.get(order.session.end_date).to('local').isoformat(),
                'order_id':
                order.id,
            }

        email(
            subject='Your class is coming up!',
            template_name='class-reminder-guardian-24-hour',
            merge_data=merge_data,
            recipients=recipients,
            preheader='Your class is just hours away!',
            unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
        )

        for order in orders_within_a_day:
            order.day_reminder_sent = True
            order.save()

        for session in sessions_within_a_week:
            orders = MentorOrder.objects.filter(session=session)

            # Clear email send data
            merge_data = {}
            recipients = []

            for order in orders:
                recipients.append(order.mentor.user.email)
                merge_data[order.mentor.user.email] = {
                    'first_name':
                    order.mentor.user.first_name,
                    'last_name':
                    order.mentor.user.last_name,
                    'class_code':
                    order.session.course.code,
                    'class_title':
                    order.session.course.title,
                    'class_description':
                    order.session.course.description,
                    'class_start_date':
                    arrow.get(order.session.mentor_start_date).to(
                        'local').format('dddd, MMMM D, YYYY'),
                    'class_start_time':
                    arrow.get(order.session.mentor_start_date).to(
                        'local').format('h:mma'),
                    'class_end_date':
                    arrow.get(order.session.mentor_end_date).to(
                        'local').format('dddd, MMMM D, YYYY'),
                    'class_end_time':
                    arrow.get(order.session.mentor_end_date).to(
                        'local').format('h:mma'),
                    'class_location_name':
                    order.session.location.name,
                    'class_location_address':
                    order.session.location.address,
                    'class_location_city':
                    order.session.location.city,
                    'class_location_state':
                    order.session.location.state,
                    'class_location_zip':
                    order.session.location.zip,
                    'class_additional_info':
                    order.session.additional_info,
                    'class_url':
                    f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                    'class_calendar_url':
                    f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                    'microdata_start_date':
                    arrow.get(
                        order.session.start_date).to('local').isoformat(),
                    'microdata_end_date':
                    arrow.get(order.session.end_date).to('local').isoformat(),
                    'order_id':
                    order.id,
                }

            email(
                subject='Your We All Code class is in less than a week!',
                template_name='class-reminder-mentor-one-week',
                merge_data=merge_data,
                recipients=recipients,
                preheader='The class is just a few days away!',
                unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
            )

            session.mentors_week_reminder_sent = True
            session.save()

        for session in sessions_within_a_day:
            orders = MentorOrder.objects.filter(session=session)

            for order in orders:
                recipients.append(order.mentor.user.email)
                merge_data[order.mentor.user.email] = {
                    'first_name':
                    order.mentor.user.first_name,
                    'last_name':
                    order.mentor.user.last_name,
                    'class_code':
                    order.session.course.code,
                    'class_title':
                    order.session.course.title,
                    'class_description':
                    order.session.course.description,
                    'class_start_date':
                    arrow.get(order.session.mentor_start_date).to(
                        'local').format('dddd, MMMM D, YYYY'),
                    'class_start_time':
                    arrow.get(order.session.mentor_start_date).to(
                        'local').format('h:mma'),
                    'class_end_date':
                    arrow.get(order.session.mentor_end_date).to(
                        'local').format('dddd, MMMM D, YYYY'),
                    'class_end_time':
                    arrow.get(order.session.mentor_end_date).to(
                        'local').format('h:mma'),
                    'class_location_name':
                    order.session.location.name,
                    'class_location_address':
                    order.session.location.address,
                    'class_location_city':
                    order.session.location.city,
                    'class_location_state':
                    order.session.location.state,
                    'class_location_zip':
                    order.session.location.zip,
                    'class_additional_info':
                    order.session.additional_info,
                    'class_url':
                    f"{settings.SITE_URL}{order.session.get_absolute_url()}",
                    'class_calendar_url':
                    f"{settings.SITE_URL}{order.session.get_calendar_url()}",
                    'microdata_start_date':
                    arrow.get(
                        order.session.start_date).to('local').isoformat(),
                    'microdata_end_date':
                    arrow.get(order.session.end_date).to('local').isoformat(),
                    'order_id':
                    order.id,
                }

            email(
                subject='Your We All Code class is tomorrow!',
                template_name='class-reminder-mentor-24-hour',
                merge_data=merge_data,
                recipients=recipients,
                preheader='The class is just a few hours away!',
                unsub_group_id=settings.SENDGRID_UNSUB_CLASSANNOUNCE,
            )

            session.mentors_day_reminder_sent = True
            session.save()
Exemplo n.º 30
0
def meeting_sign_up(request, pk, template_name="meeting-sign-up.html"):
    meeting_obj = get_object_or_404(Meeting, pk=pk)

    mentor = get_object_or_404(Mentor, user=request.user)

    meeting_orders = MeetingOrder.objects.filter(meeting=meeting_obj,
                                                 is_active=True)

    user_meeting_order = meeting_orders.filter(mentor=mentor)
    user_signed_up = True if user_meeting_order.count() else False

    if request.method == 'POST':

        if user_signed_up:
            meeting_order = get_object_or_404(MeetingOrder,
                                              meeting=meeting_obj,
                                              mentor=mentor)
            meeting_order.is_active = False
            meeting_order.save()

            messages.success(request, 'Thanks for letting us know!')

        else:
            if not settings.DEBUG:
                ip = (request.META['HTTP_X_FORWARDED_FOR']
                      or request.META['REMOTE_ADDR'])
            else:
                ip = request.META['REMOTE_ADDR']

            meeting_order, created = MeetingOrder.objects.get_or_create(
                mentor=mentor, meeting=meeting_obj)

            meeting_order.ip = ip
            meeting_order.is_active = True
            meeting_order.save()

            messages.success(request, 'Success! See you there!')

            merge_global_data = {
                'first_name':
                request.user.first_name,
                'last_name':
                request.user.last_name,
                'order_id':
                meeting_order.id,
                'meeting_title':
                meeting_obj.meeting_type.title,
                'meeting_description':
                meeting_obj.meeting_type.description,
                'meeting_start_date':
                arrow.get(meeting_obj.start_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'meeting_start_time':
                arrow.get(meeting_obj.start_date).to('local').format('h:mma'),
                'meeting_end_date':
                arrow.get(meeting_obj.end_date).to('local').format(
                    'dddd, MMMM D, YYYY'),
                'meeting_end_time':
                arrow.get(meeting_obj.end_date).to('local').format('h:mma'),
                'meeting_location_name':
                meeting_obj.location.name,
                'meeting_location_address':
                meeting_obj.location.address,
                'meeting_location_city':
                meeting_obj.location.city,
                'meeting_location_state':
                meeting_obj.location.state,
                'meeting_location_zip':
                meeting_obj.location.zip,
                'meeting_additional_info':
                meeting_obj.additional_info,
                'meeting_url':
                f"{settings.SITE_URL}{meeting_obj.get_absolute_url()}",
                'meeting_calendar_url':
                f"{settings.SITE_URL}{meeting_obj.get_calendar_url()}",
                'microdata_start_date':
                arrow.get(meeting_obj.start_date).to('local').isoformat(),
                'microdata_end_date':
                arrow.get(meeting_obj.end_date).to('local').isoformat(),
            }

            email(
                subject='Upcoming mentor meeting confirmation',
                template_name='meeting-confirm-mentor',
                merge_global_data=merge_global_data,
                recipients=[request.user.email],
                preheader=
                (f"Thanks for signing up for our next meeting, {request.user.first_name}. "
                 f"We look forward to seeing there."),
            )

        return redirect('meeting-detail', meeting_obj.id)

    return render(request, template_name, {
        'meeting': meeting_obj,
        'user_signed_up': user_signed_up
    })
Exemplo n.º 31
0
def meeting_announce(request, pk):
    if not request.user.is_staff:
        messages.error(request,
                       'You do not have permission to access this page.')
        return redirect('home')

    meeting_obj = get_object_or_404(Meeting, pk=pk)

    if not meeting_obj.announced_date:
        merge_data = {}
        merge_global_data = {
            'meeting_title':
            meeting_obj.meeting_type.title,
            'meeting_description':
            meeting_obj.meeting_type.description,
            'meeting_start_date':
            arrow.get(meeting_obj.start_date).to('local').format(
                'dddd, MMMM D, YYYY'),
            'meeting_start_time':
            arrow.get(meeting_obj.start_date).to('local').format('h:mma'),
            'meeting_end_date':
            arrow.get(
                meeting_obj.end_date).to('local').format('dddd, MMMM D, YYYY'),
            'meeting_end_time':
            arrow.get(meeting_obj.end_date).to('local').format('h:mma'),
            'meeting_location_name':
            meeting_obj.location.name,
            'meeting_location_address':
            meeting_obj.location.address,
            'meeting_location_city':
            meeting_obj.location.city,
            'meeting_location_state':
            meeting_obj.location.state,
            'meeting_location_zip':
            meeting_obj.location.zip,
            'meeting_additional_info':
            meeting_obj.additional_info,
            'meeting_url':
            f"{settings.SITE_URL}{meeting_obj.get_absolute_url()}",
            'meeting_calendar_url':
            f"{settings.SITE_URL}{meeting_obj.get_calendar_url()}",
        }

        mentors = Mentor.objects.filter(
            is_active=True,
            user__is_active=True,
        )

        recipients = []
        for mentor in mentors:
            recipients.append(mentor.user.email)
            merge_data[mentor.user.email] = {
                'first_name': mentor.user.first_name,
                'last_name': mentor.user.last_name,
            }

        email(
            subject='New meeting announced!',
            template_name='meeting-announcement-mentor',
            merge_data=merge_data,
            merge_global_data=merge_global_data,
            recipients=recipients,
            preheader=
            'A new meeting has been announced. Come join us for some amazing fun!',
        )

        meeting_obj.announced_date = timezone.now()
        meeting_obj.save()

        messages.success(request,
                         f"Meeting announced to {mentors.count()} mentors.")
    else:
        messages.warning(request, 'Meeting already announced.')

    return redirect('cdc-admin')
Exemplo n.º 32
0
    def do(self):
        orders_within_a_week = Order.objects.filter(
            is_active=True,
            week_reminder_sent=False,
            session__start_date__lte=(
                timezone.now() + datetime.timedelta(days=7)
            ),
            session__start_date__gte=(
                timezone.now() + datetime.timedelta(days=1)
            ),
        )
        orders_within_a_day = Order.objects.filter(
            is_active=True,
            day_reminder_sent=False,
            session__start_date__lte=(
                timezone.now() + datetime.timedelta(days=1)
            ),
            session__start_date__gte=(
                timezone.now() - datetime.timedelta(days=2)
            ),
        )
        sessions_within_a_week = Session.objects.filter(
            is_active=True,
            mentors_week_reminder_sent=False,
            start_date__lte=timezone.now() + datetime.timedelta(days=7),
            start_date__gte=timezone.now() + datetime.timedelta(days=1)
        )
        sessions_within_a_day = Session.objects.filter(
            is_active=True,
            mentors_day_reminder_sent=False,
            start_date__lte=timezone.now() + datetime.timedelta(days=1),
            start_date__gte=timezone.now() - datetime.timedelta(days=2)
        )

        # uses SMTP server specified in settings.py
        connection = get_connection()

        # If you don't open the connection manually,
        # Django will automatically open, then tear down the connection
        # in msg.send()
        connection.open()

        for order in orders_within_a_week:
            email(
                subject='Upcoming class reminder',
                template_name='class-reminder-guardian-one-week',
                context={
                    'first_name': order.guardian.user.first_name,
                    'last_name': order.guardian.user.last_name,
                    'student_first_name': order.student.first_name,
                    'student_last_name': order.student.last_name,
                    'class_code': order.session.course.code,
                    'class_title': order.session.course.title,
                    'class_description': order.session.course.description,
                    'class_start_date': arrow.get(
                        order.session.start_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_start_time': arrow.get(
                        order.session.start_date
                    ).to('local').format('h:mma'),
                    'class_end_date': arrow.get(
                        order.session.end_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_end_time': arrow.get(
                        order.session.end_date
                    ).to('local').format('h:mma'),
                    'class_location_name': order.session.location.name,
                    'class_location_address': order.session.location.address,
                    'class_location_address2': order.session.location.address2,
                    'class_location_city': order.session.location.city,
                    'class_location_state': order.session.location.state,
                    'class_location_zip': order.session.location.zip,
                    'class_additional_info': order.session.additional_info,
                    'class_url': order.session.get_absolute_url(),
                    'class_ics_url': order.session.get_ics_url(),
                    'microdata_start_date': arrow.get(
                        order.session.start_date
                    ).to('local').isoformat(),
                    'microdata_end_date': arrow.get(
                        order.session.end_date
                    ).to('local').isoformat(),
                    'order': order,
                },
                recipients=[order.guardian.user.email],
                preheader='Your class is just a few days away!',
            )

            order.week_reminder_sent = True
            order.save()

        for order in orders_within_a_day:
            email(
                subject='Your CoderDojoChi is coming up!',
                template_name='class-reminder-guardian-24-hour',
                context={
                    'first_name': order.guardian.user.first_name,
                    'last_name': order.guardian.user.last_name,
                    'student_first_name': order.student.first_name,
                    'student_last_name': order.student.last_name,
                    'class_code': order.session.course.code,
                    'class_title': order.session.course.title,
                    'class_description': order.session.course.description,
                    'class_start_date': arrow.get(
                        order.session.start_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_start_time': arrow.get(
                        order.session.start_date
                    ).to('local').format('h:mma'),
                    'class_end_date': arrow.get(
                        order.session.end_date
                    ).to('local').format('dddd, MMMM D, YYYY'),
                    'class_end_time': arrow.get(
                        order.session.end_date
                    ).to('local').format('h:mma'),
                    'class_location_name': order.session.location.name,
                    'class_location_address': order.session.location.address,
                    'class_location_address2': order.session.location.address2,
                    'class_location_city': order.session.location.city,
                    'class_location_state': order.session.location.state,
                    'class_location_zip': order.session.location.zip,
                    'class_additional_info': order.session.additional_info,
                    'class_url': order.session.get_absolute_url(),
                    'class_ics_url': order.session.get_ics_url(),
                    'microdata_start_date': arrow.get(
                        order.session.start_date
                    ).to('local').isoformat(),
                    'microdata_end_date': arrow.get(
                        order.session.end_date
                    ).to('local').isoformat(),
                    'order': order,
                },
                recipients=[order.guardian.user.email],
                preheader='Your class is just hours away!',
            )

            order.day_reminder_sent = True
            order.save()

        for session in sessions_within_a_week:
            orders = MentorOrder.objects.filter(session=session)

            for order in orders:
                email(
                    subject='Your CoderDojoChi class is in less than a week!',
                    template_name='class-reminder-mentor-one-week',
                    context={
                        'first_name': order.mentor.user.first_name,
                        'last_name': order.mentor.user.last_name,
                        'class_code': order.session.course.code,
                        'class_title': order.session.course.title,
                        'class_description': order.session.course.description,
                        'class_start_date': arrow.get(
                            order.session.mentor_start_date
                        ).to('local').format('dddd, MMMM D, YYYY'),
                        'class_start_time': arrow.get(
                            order.session.mentor_start_date
                        ).to('local').format('h:mma'),
                        'class_end_date': arrow.get(
                            order.session.mentor_end_date
                        ).to('local').format('dddd, MMMM D, YYYY'),
                        'class_end_time': arrow.get(
                            order.session.mentor_end_date
                        ).to('local').format('h:mma'),
                        'class_location_name': order.session.location.name,
                        'class_location_address':
                            order.session.location.address,
                        'class_location_address2':
                            order.session.location.address2,
                        'class_location_city': order.session.location.city,
                        'class_location_state': order.session.location.state,
                        'class_location_zip': order.session.location.zip,
                        'class_additional_info': order.session.additional_info,
                        'class_url': order.session.get_absolute_url(),
                        'class_ics_url': order.session.get_ics_url(),
                        'microdata_start_date': arrow.get(
                            order.session.start_date
                        ).to('local').isoformat(),
                        'microdata_end_date': arrow.get(
                            order.session.end_date
                        ).to('local').isoformat(),
                        'order': order,
                    },
                    recipients=[order.mentor.user.email],
                    preheader='The class is just a few days away!',
                )

            session.mentors_week_reminder_sent = True
            session.save()

        for session in sessions_within_a_day:
            orders = MentorOrder.objects.filter(session=session)

            for order in orders:
                email(
                    subject='Your CoderDojoChi class is tomorrow!',
                    template_name='class-reminder-mentor-24-hour',
                    context={
                        'first_name': order.mentor.user.first_name,
                        'last_name': order.mentor.user.last_name,
                        'class_code': order.session.course.code,
                        'class_title': order.session.course.title,
                        'class_description': order.session.course.description,
                        'class_start_date': arrow.get(
                            order.session.mentor_start_date
                        ).to('local').format('dddd, MMMM D, YYYY'),
                        'class_start_time': arrow.get(
                            order.session.mentor_start_date
                        ).to('local').format('h:mma'),
                        'class_end_date': arrow.get(
                            order.session.mentor_end_date
                        ).to('local').format('dddd, MMMM D, YYYY'),
                        'class_end_time': arrow.get(
                            order.session.mentor_end_date
                        ).to('local').format('h:mma'),
                        'class_location_name': order.session.location.name,
                        'class_location_address':
                            order.session.location.address,
                        'class_location_address2':
                            order.session.location.address2,
                        'class_location_city': order.session.location.city,
                        'class_location_state': order.session.location.state,
                        'class_location_zip': order.session.location.zip,
                        'class_additional_info': order.session.additional_info,
                        'class_url': order.session.get_absolute_url(),
                        'class_ics_url': order.session.get_ics_url(),
                        'microdata_start_date': arrow.get(
                            order.session.start_date
                        ).to('local').isoformat(),
                        'microdata_end_date': arrow.get(
                            order.session.end_date
                        ).to('local').isoformat(),
                        'order': order,
                    },
                    recipients=[order.mentor.user.email],
                    preheader='The class is just a few hours away!',
                )

            session.mentors_day_reminder_sent = True
            session.save()

        # Cleanup
        connection.close()