Ejemplo n.º 1
0
 def thank_faculty(self, course: Course) -> None:
     user = self.request.user
     send_template_email(
         'Locus Tempus Course Connected',
         'main/lti_course_connect.txt',
         {'course': course},
         user.email if user.email else user.username + '@columbia.edu')
Ejemplo n.º 2
0
    def handle_unis(self, course: Course, unis: List[str]) -> None:
        """
        Add a list of UNI users to a course
        """
        site = get_current_site(self.request)
        for uni in unis:
            user = self.get_or_create_user(uni)
            display_name = user_display_name(user)
            if course.is_true_member(user):
                msg = '{} ({}) is already a course member'.format(
                    display_name, uni)
                messages.add_message(self.request, messages.WARNING, msg)
            else:
                email = '{}@columbia.edu'.format(uni)
                course.group.user_set.add(user)
                subj = 'Locus Tempus Invitation: {}'.format(course.title)
                send_template_email(
                    subj,
                    self.email_template,
                    {'course_title': course.title, 'site': site},
                    email
                )
                msg = (
                    '{} is now a workspace member. An email notification '
                    'was sent to {}.').format(display_name, email)

                messages.add_message(self.request, messages.SUCCESS, msg)
Ejemplo n.º 3
0
    def post(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
        site = get_current_site(request)
        addr = request.POST.get('user_email', None)
        course = get_object_or_404(Course, id=kwargs.get('pk', None))
        affil = get_object_or_404(
            GuestUserAffil, guest_email=addr, course=course, accepted_at=None)

        # Set the modified_at time
        affil.save()

        # Resend email to invited user
        subj = 'Locus Tempus Invitation: {}'.format(course.title)
        send_template_email(
            subj,
            self.guest_email_template,
            {'course_title': course.title,
             'guest_email': affil.guest_email,
             'site': site},
            affil.guest_email
        )

        msg = ('{} has been resent an invitation '
               'to join the workspace.'.format(addr))
        messages.add_message(request, messages.INFO, msg)
        return HttpResponseRedirect(
            reverse('course-roster-view', args=[course.pk]))
Ejemplo n.º 4
0
    def handle_emails(self, course: Course, email_addrs: List[str]) -> None:
        """
        Add a list of guest users to a course from a list of email addresses.
        """
        site = get_current_site(self.request)
        for addr in email_addrs:
            try:
                user = User.objects.get(email=addr)
                if course.is_true_member(user):
                    msg = '{} is already a course member'.format(
                        user.username)
                    messages.add_message(self.request, messages.WARNING, msg)
                else:
                    course.group.user_set.add(user)
                    subj = 'Locus Tempus Invitation: {}'.format(course.title)
                    send_template_email(
                        subj,
                        self.email_template,
                        {'course_title': course.title, 'site': site},
                        addr
                    )
                    msg = (
                        '{} is now a workspace member. An email notification '
                        'was sent to {}.').format(
                            user.username, addr)

                    messages.add_message(self.request, messages.SUCCESS, msg)
            except User.DoesNotExist:
                # Create an affiliation
                # You need to check if an affiliation exist
                if GuestUserAffil.objects.filter(
                        course=course, guest_email=addr).exists():
                    msg = ('{} has already been invited to join the workspace.'
                           ' Please use the resend button below to '
                           'resend the invitation'.format(addr))
                    messages.add_message(self.request, messages.INFO, msg)
                else:
                    affil = GuestUserAffil(
                        course=course,
                        guest_email=addr,
                        invited_by=self.request.user
                    )
                    affil.save()
                    # Send email to invite user to sign up
                    subj = 'Locus Tempus Invitation: {}'.format(course.title)
                    send_template_email(
                        subj,
                        self.guest_email_template,
                        {
                            'course_title': course.title,
                            'guest_email': addr,
                            'site': site
                        },
                        addr
                    )
                    # Show message to faculty
                    msg = ('{} has been sent an invitation '
                           'to join the workspace.'.format(addr))
                    messages.add_message(self.request, messages.SUCCESS, msg)
Ejemplo n.º 5
0
 def notify_staff(self, course: Course) -> None:
     data = {
         'course': course,
         'user': self.request.user
     }
     send_template_email(
         'Locus Tempus Course Connected',
         'main/notify_lti_course_connect.txt',
         data, settings.SERVER_EMAIL)
Ejemplo n.º 6
0
 def test_send_template_email(self):
     user = UserFactory()
     with self.settings(SERVER_EMAIL='*****@*****.**'):
         send_template_email('foo', 'main/notify_lti_course_connect.txt',
                             {'user': user}, '*****@*****.**')
         self.assertEqual(len(mail.outbox), 1)
         self.assertEqual(mail.outbox[0].subject, 'foo')
         self.assertEquals(mail.outbox[0].from_email,
                           '*****@*****.**')
         self.assertTrue(mail.outbox[0].to, ['*****@*****.**'])