Example #1
0
def admin_student_registered(request, email_address, **kwargs):
    student = StudentProfile.objects.get(user=email_address.user)
    send_templated_mail(
        subject=_("New student %s has registered") % student,
        html_template="email/admin/student_registered.html",
        context={'new_profile': student, 'user': student},
    )
    action.send(student, verb='has registered')
Example #2
0
def student_missing_information_mail(sender, instance, name, source, target, **kwargs):
    if target == StudentProfileState.MISSING_INFORMATION and not is_duplicate_transition(name, instance):
        with translation.override(instance.get_preferred_language()):
            send_templated_mail(
                subject=_("Your profile at Motius is incomplete"),
                html_template='email/student/student_missing_information.html',
                recipient_list=[instance.user.email],
                context={'profile': instance, 'user': instance.user}
            )
Example #3
0
def student_rejected_mail(sender, instance, name, source, target, **kwargs):
    if target == StudentProfileState.REJECTED and not is_duplicate_transition(name, instance):
        with translation.override(instance.get_preferred_language()):
            send_templated_mail(
                subject=_("About your registration at Motius"),
                html_template='email/student/student_rejected.html',
                recipient_list=[instance.user.email],
                context={'profile': instance, 'user': instance.user}
            )
            action.send(instance, verb='was rejected')
Example #4
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST)
     if form.is_valid():
         send_templated_mail(
             subject=_("Contact from %(name)s: %(topic)s")
             % {
                 "name": form.cleaned_data["name"],
                 "topic": dict(form.fields["topic"].choices)[form.cleaned_data["topic"]],
             },
             html_template="email/admin/contact.html",
             context=form.cleaned_data,
             reply_to=form.cleaned_data["email"],
         )
         messages.add_message(
             request, messages.SUCCESS, _("Thank you for your message, we will be in touch shortly.")
         )
     else:
         messages.add_message(request, messages.WARNING, _("There was an error while sending your message."))
     return HttpResponseRedirect(form.cleaned_data["next"])
Example #5
0
def send_invoice(sender, instance, name, source, target, **kwargs):
    if name == "state_sent" and not is_duplicate_transition(name, instance):
        if isinstance(instance.recipient, StudentProfile) and instance.pdf:
            with translation.override(instance.recipient.get_preferred_language()):
                mail = send_templated_mail(
                    subject=_("New invoice %(id)s") % {'id': instance.public_id},
                    html_template='email/student/new_invoice_notification.html',
                    recipient_list=[instance.recipient.user.email],
                    context={'invoice': instance, 'user': instance.recipient.user},
                    skip_sending=True
                )
                mail.attach("%s.pdf" % instance.public_id, instance.pdf.read())
                mail.send()
Example #6
0
def refer_friends(request, project_slug):
    profile = StudentProfile.objects.get(user=request.user)
    if ProjectInvitation.objects.filter(student=profile, project__slug=project_slug).exists():
        invitation = ProjectInvitation.objects.get(student=profile, project__slug=project_slug)
        project = invitation.project
    else:
        project = get_object_or_404(Project, slug=project_slug, visibility=ProjectVisibility.STUDENTS)

    if request.method == 'POST':
        form = ReferFriendsForm(request.POST)
        if form.is_valid():
            valid_invitations = 0
            # send invitation mails
            for email_address in form.cleaned_data['emails']:
                # remove blanks from email addresses
                email_address = email_address.strip()
                if StudentProfile.objects.filter(user__email=email_address):
                    messages.add_message(
                        request, messages.WARNING,
                        _("The email address %(email)s is already registered. No invitation was sent.") % {'email': email_address}
                    )
                    continue
                send_templated_mail(
                    subject=_("Your friend %s invites you to join a Motius project") % profile.user.first_name,
                    html_template="email/student/new_project_referral.html",
                    recipient_list=[email_address],
                    context={'project': project, 'profile': profile, 'message': form.cleaned_data['message'],
                             'referral_hash': hashlib.md5(profile.user.email.encode('utf-8')).hexdigest()},
                )
                valid_invitations += 1
            if valid_invitations > 0:
                messages.add_message(request, messages.SUCCESS, _("%(count)s referrals have been sent.") % {'count': valid_invitations})
            return HttpResponseRedirect(reverse('invitation_index'))
    else:
        form = ReferFriendsForm()

    return render(request, 'motius_project/refer_friends.html', {'form': form, 'project': project})
Example #7
0
def student_accepted_mail(sender, instance, name, source, target, **kwargs):
    if target == StudentProfileState.ACCEPTED and not is_duplicate_transition(name, instance):
        with translation.override(instance.get_preferred_language()):
            mail = send_templated_mail(
                subject=_("We've accepted you for Motius"),
                html_template='email/student/student_accepted.html',
                recipient_list=[instance.user.email],
                context={'profile': instance, 'user': instance.user},
                skip_sending=True,
            )

            # Attach student guide to email
            student_guide = finders.find('pdf/student_guide_%s.pdf' % instance.get_preferred_language())
            with open(student_guide, 'rb') as f:
                mail.attach(_('motius_student_guide.pdf'), f.read())
            mail.send()
            action.send(instance, verb='was accepted into the pool')