Exemplo n.º 1
0
class CourseEmailForm(forms.Form, BootstrapMixin):
    recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=EMAIL_RECIPIENTS, label=_("Send email to"))
    subject = forms.CharField(label=_("Subject"))
    body = forms.CharField(widget=forms.Textarea(), label=_("Message"))

    def __init__(self, *args, **kwargs):
        self.instance = kwargs.pop('instance')
        self.template = EmailTemplate()
        super(CourseEmailForm, self).__init__(*args, **kwargs)

    def clean(self):
        self.recipient_groups = self.cleaned_data.get('recipients')

        if not self.recipient_groups:
            raise forms.ValidationError(_(u"No recipient selected. Choose at least one group of recipients."))

        return self.cleaned_data

    # returns whether all recepients have an email address
    def all_recepients_reachable(self):
        return self.missing_email_addresses() == 0

    # returns the number of recepients without an email address
    def missing_email_addresses(self):
        recipients = self.template.recipient_list_for_course(self.instance, self.recipient_groups)
        return len([user for user in recipients if not user.email])

    def send(self):
        self.template.subject = self.cleaned_data.get('subject')
        self.template.body = self.cleaned_data.get('body')
        self.template.send_to_users_in_courses([self.instance], self.recipient_groups)
Exemplo n.º 2
0
 def send(self, request):
     self.template.subject = self.cleaned_data.get('subject')
     self.template.body = self.cleaned_data.get('body')
     EmailTemplate.send_to_users_in_courses(self.template, [self.instance],
                                            self.recipient_groups,
                                            use_cc=True,
                                            request=request)
Exemplo n.º 3
0
 def test_no_login_url_when_cc_users_in_cc(self):
     self.user.cc_users.add(self.other_user)
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=True)
     self.assertEqual(len(mail.outbox), 2)
     self.assertFalse("loginkey" in mail.outbox[0].body)  # message does not contain the login url
     self.assertTrue("loginkey" in mail.outbox[1].body)  # separate email with login url was sent
     self.assertEqual(len(mail.outbox[1].cc), 0)
     self.assertEqual(mail.outbox[1].to, [self.user.email])
Exemplo n.º 4
0
 def test_no_login_url_when_cc_users_in_cc(self):
     self.user.cc_users.add(self.other_user)
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=True, request=None)
     self.assertEqual(len(mail.outbox), 2)
     self.assertFalse("loginkey" in mail.outbox[0].body)  # message does not contain the login url
     self.assertTrue("loginkey" in mail.outbox[1].body)  # separate email with login url was sent
     self.assertEqual(len(mail.outbox[1].cc), 0)
     self.assertEqual(mail.outbox[1].to, [self.user.email])
Exemplo n.º 5
0
 def test_login_url_when_nobody_in_cc(self):
     # message is not sent to others in cc
     EmailTemplate.send_to_users_in_courses(self.template, [self.course],
                                            [EmailTemplate.CONTRIBUTORS],
                                            use_cc=True,
                                            request=None)
     self.assertEqual(len(mail.outbox), 1)
     self.assertTrue(
         "loginkey"
         in mail.outbox[0].body)  # message does contain the login url
Exemplo n.º 6
0
Arquivo: forms.py Projeto: Nef10/EvaP
class CourseEmailForm(forms.Form, BootstrapMixin):
    sendToDueParticipants = forms.BooleanField(label=_("Send to participants who didn't vote yet"), required=False, initial=True)
    sendToAllParticipants = forms.BooleanField(label=_("Send to all participants"), required=False)
    sendToResponsible = forms.BooleanField(label=_("Send to the responsible person"), required=False)
    sendToEditors = forms.BooleanField(label=_("Send to editors"), required=False)
    sendToContributors = forms.BooleanField(label=_("Send to all contributors (includes editors)"), required=False)
    subject = forms.CharField(label=_("Subject"))
    body = forms.CharField(widget=forms.Textarea(), label=_("Body"))

    def __init__(self, *args, **kwargs):
        self.instance = kwargs.pop('instance')
        self.template = EmailTemplate()
        super(CourseEmailForm, self).__init__(*args, **kwargs)

    def clean(self):
        self.recipient_groups = []

        if self.cleaned_data.get('sendToAllParticipants'): self.recipient_groups += ['all_participants']
        if self.cleaned_data.get('sendToDueParticipants'): self.recipient_groups += ['due_participants']
        if self.cleaned_data.get('sendToResponsible'): self.recipient_groups += ['responsible']
        if self.cleaned_data.get('sendToEditors'): self.recipient_groups += ['editors']
        if self.cleaned_data.get('sendToContributors'): self.recipient_groups += ['contributors']

        if len(self.recipient_groups) == 0:
            raise forms.ValidationError(_(u"No recipient selected. Choose at least one group of recipients."))

        return self.cleaned_data

    # returns whether all recepients have an email address
    def all_recepients_reachable(self):
        return self.missing_email_addresses() == 0

    # returns the number of recepients without an email address
    def missing_email_addresses(self):
        recipients = self.template.recipient_list_for_course(self.instance, self.recipient_groups)
        return len([user for user in recipients if not user.email])

    def send(self):
        self.template.subject = self.cleaned_data.get('subject')
        self.template.body = self.cleaned_data.get('body')
        self.template.send_to_users_in_courses([self.instance], self.recipient_groups)
Exemplo n.º 7
0
 def send(self):
     self.template.subject = self.cleaned_data.get('subject')
     self.template.body = self.cleaned_data.get('body')
     EmailTemplate.send_to_users_in_courses(self.template, [self.instance], self.recipient_groups)
Exemplo n.º 8
0
 def test_login_url_when_use_cc_is_false(self):
     # message is not sent to others in cc
     self.user.delegates.add(self.other_user)
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=False)
     self.assertEqual(len(mail.outbox), 1)
     self.assertTrue("loginkey" in mail.outbox[0].body)  # message does contain the login url
Exemplo n.º 9
0
 def test_login_url_when_nobody_in_cc(self):
     # message is not sent to others in cc
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=True)
     self.assertEqual(len(mail.outbox), 1)
     self.assertTrue("loginkey" in mail.outbox[0].body)  # message does contain the login url
Exemplo n.º 10
0
 def send(self, request):
     self.template.subject = self.cleaned_data.get('subject')
     self.template.body = self.cleaned_data.get('body')
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], self.recipient_groups, use_cc=True, request=request)
Exemplo n.º 11
0
 def test_login_url_when_use_cc_is_false(self):
     # message is not sent to others in cc
     self.user.delegates.add(self.other_user)
     EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=False, request=None)
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].body, self.user.login_url)  # message does contain the login url
Exemplo n.º 12
0
 def send(self):
     self.template.subject = self.cleaned_data.get("subject")
     self.template.body = self.cleaned_data.get("body")
     EmailTemplate.send_to_users_in_courses(self.template, [self.instance], self.recipient_groups, use_cc=True)