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


Python Email.save方法代码示例

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


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

示例1: message

# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import save [as 别名]
def message(request, group_slug, template_name="user_groups/message.html"):
    """
    Send a message to the group
    """
    from tendenci.apps.emails.models import Email

    group = get_object_or_404(Group, slug=group_slug)
    EventLog.objects.log(instance=group)

    members = GroupMembership.objects.filter(group=group, status=True, status_detail="active")

    num_members = members.count()

    form = MessageForm(request.POST or None, request=request, num_members=num_members)

    if request.method == "POST" and form.is_valid():

        email = Email()
        email.sender_display = request.user.get_full_name()
        email.sender = get_setting("site", "global", "siteemailnoreplyaddress")
        email.reply_to = email.sender
        email.content_type = email.CONTENT_TYPE_HTML
        email.subject = form.cleaned_data["subject"]
        email.body = form.cleaned_data["body"]
        email.save(request.user)

        # send email to myself (testing email)
        if form.cleaned_data["is_test"]:
            email.recipient = request.user.email
            email.send()

            messages.add_message(request, messages.SUCCESS, _("Successfully sent test email to yourself"))

            EventLog.objects.log(instance=email)

        else:
            # send email to members
            for member in members:
                email.recipient = member.member.email
                email.send()

            messages.add_message(
                request,
                messages.SUCCESS,
                _("Successfully sent email to all %(num)s members in this group" % {"num": num_members}),
            )

            EventLog.objects.log(instance=email)

        return redirect("group.detail", group_slug=group_slug)

    else:
        print "form errors", form.errors.items()

    return render(request, template_name, {"group": group, "num_members": num_members, "form": form})
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:57,代码来源:views.py

示例2: save

# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import save [as 别名]
    def save(self, *args, **kwargs):
        data = self.cleaned_data
        subject = ''
        subj = data.get('subject', '')
        inc_last_name = data.get('personalize_subject_last_name')
        inc_first_name = data.get('personalize_subject_first_name')

        if inc_first_name and not inc_last_name:
            subject = '[firstname] ' + subj
        elif inc_last_name and not inc_first_name:
            subject = '[lastname] ' + subj
        elif inc_first_name and inc_last_name:
            subject = '[firstname] [lastname] ' + subj
        else:
            subject = subj
        nl = super(OldGenerateForm, self).save(*args, **kwargs)
        nl.subject = subject
        nl.actionname = subject
        nl.date_created = datetime.datetime.now()
        nl.send_status = 'draft'
        if nl.default_template:
            template = render_to_string(nl.default_template, context_instance=RequestContext(self.request))
            email_content = nl.generate_newsletter(self.request, template)

            email = Email()
            email.subject = subject
            email.body = email_content
            email.sender = self.request.user.email
            email.sender_display = self.request.user.profile.get_name()
            email.reply_to = self.request.user.email
            email.creator = self.request.user
            email.creator_username = self.request.user.username
            email.owner = self.request.user
            email.owner_username = self.request.user.username
            email.save()
            nl.email = email

        nl.save()

        return nl
开发者ID:BIGGANI,项目名称:tendenci,代码行数:42,代码来源:forms.py

示例3: message

# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import save [as 别名]
def message(request, group_slug, template_name='user_groups/message.html'):
    """
    Send a message to the group
    """
    from tendenci.apps.emails.models import Email

    group = get_object_or_404(Group, slug=group_slug)
    EventLog.objects.log(instance=group)

    members = GroupMembership.objects.filter(
        group=group,
        status=True,
        status_detail='active')

    num_members = members.count()

    form = MessageForm(request.POST or None,
        request=request,
        num_members=num_members)


    if request.method == 'POST' and form.is_valid():

        email = Email()
        email.sender_display = request.user.get_full_name()
        email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
        email.reply_to = email.sender
        email.content_type = 'text/html'
        email.subject = form.cleaned_data['subject']
        email.body = form.cleaned_data['body']
        email.save(request.user)

        # send email to myself (testing email)
        if form.cleaned_data['is_test']:
            email.recipient = request.user.email
            email.send()

            messages.add_message(
                request,
                messages.SUCCESS,
                _('Successfully sent test email to yourself'))

            EventLog.objects.log(instance=email)

        else:
            # send email to members
            for member in members:
                email.recipient = member.member.email
                email.send()

            messages.add_message(
                request,
                messages.SUCCESS,
                _('Successfully sent email to all %(num)s members in this group' % {'num': num_members}))

            EventLog.objects.log(instance=email)

        return redirect('group.detail', group_slug=group_slug)

    else:
        print 'form errors', form.errors.items()


    return render(request, template_name, {
        'group': group,
        'num_members': num_members,
        'form': form})
开发者ID:jiwonlee777,项目名称:tendenci,代码行数:69,代码来源:views.py


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