当前位置: 首页>>代码示例>>Python>>正文


Python EmailTemplate.recipient_list_for_course方法代码示例

本文整理汇总了Python中evap.evaluation.models.EmailTemplate.recipient_list_for_course方法的典型用法代码示例。如果您正苦于以下问题:Python EmailTemplate.recipient_list_for_course方法的具体用法?Python EmailTemplate.recipient_list_for_course怎么用?Python EmailTemplate.recipient_list_for_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在evap.evaluation.models.EmailTemplate的用法示例。


在下文中一共展示了EmailTemplate.recipient_list_for_course方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_recipient_list_filtering

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
    def test_recipient_list_filtering(self):
        course = mommy.make(Course)

        contributor1 = mommy.make(UserProfile)
        contributor2 = mommy.make(UserProfile, delegates=[contributor1])

        mommy.make(Contribution, course=course, contributor=contributor1)
        mommy.make(Contribution, course=course, contributor=contributor2)

        # no-one should get filtered.
        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [contributor1, contributor2])

        # contributor1 is in cc of contributor2 and gets filtered.
        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=True)
        self.assertCountEqual(recipient_list, [contributor2])

        contributor3 = mommy.make(UserProfile, delegates=[contributor2])
        mommy.make(Contribution, course=course, contributor=contributor3)

        # again, no-one should get filtered.
        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [contributor1, contributor2, contributor3])

        # contributor1 is in cc of contributor2 and gets filtered.
        # contributor2 is in cc of contributor3 but is not filtered since contributor1 wouldn't get an email at all then.
        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=True)
        self.assertCountEqual(recipient_list, [contributor2, contributor3])
开发者ID:Steditor,项目名称:EvaP,代码行数:30,代码来源:test_models.py

示例2: CourseEmailForm

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
class CourseEmailForm(forms.Form, BootstrapMixin):
    recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=EmailTemplate.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().__init__(*args, **kwargs)

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

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

        return self.cleaned_data

    # 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')
        EmailTemplate.send_to_users_in_courses(self.template, [self.instance], self.recipient_groups)
开发者ID:pitwegner,项目名称:EvaP,代码行数:29,代码来源:forms.py

示例3: CourseEmailForm

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
class CourseEmailForm(forms.Form):
    recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=EmailTemplate.EMAIL_RECIPIENTS, label=_("Send email to"))
    subject = forms.CharField(label=_("Subject"))
    body = forms.CharField(widget=forms.Textarea(), label=_("Message"))

    def __init__(self, *args, course, export=False, **kwargs):
        super().__init__(*args, **kwargs)
        self.template = EmailTemplate()
        self.course = course
        self.fields['subject'].required = not export
        self.fields['body'].required = not export

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

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

        return self.cleaned_data

    def email_addresses(self):
        recipients = self.template.recipient_list_for_course(self.course, self.recipient_groups, filter_users_in_cc=False)
        return set(user.email for user in recipients if user.email)

    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)
开发者ID:JenniferStamm,项目名称:EvaP,代码行数:30,代码来源:forms.py

示例4: CourseEmailForm

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
class CourseEmailForm(forms.Form, BootstrapMixin):
    recipients = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple(), choices=EmailTemplate.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.export = kwargs.pop("export", False)
        self.template = EmailTemplate()
        super().__init__(*args, **kwargs)
        self.fields["subject"].required = not self.export
        self.fields["body"].required = not self.export

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

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

        return self.cleaned_data

    def email_addresses(self):
        recipients = self.template.recipient_list_for_course(
            self.instance, self.recipient_groups, filter_users_in_cc=False
        )
        return set(user.email for user in recipients if user.email)

    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)
开发者ID:Steditor,项目名称:EvaP,代码行数:35,代码来源:forms.py

示例5: test_recipient_list

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
    def test_recipient_list(self):
        course = mommy.make(Course)
        responsible = mommy.make(UserProfile)
        editor = mommy.make(UserProfile)
        contributor = mommy.make(UserProfile)
        mommy.make(Contribution, course=course, contributor=responsible, responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS)
        mommy.make(Contribution, course=course, contributor=editor, can_edit=True)
        mommy.make(Contribution, course=course, contributor=contributor)

        participant1 = mommy.make(UserProfile, courses_participating_in=[course])
        participant2 = mommy.make(UserProfile, courses_participating_in=[course])
        course.voters = [participant1]

        recipient_list = EmailTemplate.recipient_list_for_course(course, [], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [])

        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.RESPONSIBLE], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [responsible])

        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.EDITORS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [responsible, editor])

        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [responsible, editor, contributor])

        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.ALL_PARTICIPANTS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [participant1, participant2])

        recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.DUE_PARTICIPANTS], filter_users_in_cc=False)
        self.assertCountEqual(recipient_list, [participant2])
开发者ID:Steditor,项目名称:EvaP,代码行数:32,代码来源:test_models.py

示例6: CourseEmailForm

# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import recipient_list_for_course [as 别名]
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)
开发者ID:Nef10,项目名称:EvaP,代码行数:43,代码来源:forms.py


注:本文中的evap.evaluation.models.EmailTemplate.recipient_list_for_course方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。