本文整理汇总了Python中tendenci.apps.emails.models.Email.sender_display方法的典型用法代码示例。如果您正苦于以下问题:Python Email.sender_display方法的具体用法?Python Email.sender_display怎么用?Python Email.sender_display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tendenci.apps.emails.models.Email
的用法示例。
在下文中一共展示了Email.sender_display方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: message
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [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})
示例2: email_script_errors
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [as 别名]
def email_script_errors(err_msg):
"""Send error message to us in case of an error.
"""
email = Email()
email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
email.sender_display = get_setting('site', 'global', 'sitedisplayname')
site_url = get_setting('site', 'global', 'siteurl')
now = datetime.now()
nowstr = time.strftime("%d-%b-%y %I:%M %p", now.timetuple())
email.recipient = get_script_support_emails()
if email.recipient:
email.body = '%s \n\nTime Submitted: %s\n' % (err_msg, nowstr)
email.content_type = "text"
email.subject = 'Error Setting Up Campaign Monitor Account on New Site %s' % site_url
email.send()
示例3: email_invoice
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [as 别名]
def email_invoice(request, invoice_id, form_class=EmailInvoiceForm,
template_name='invoices/email_invoice.html'):
if not request.user.profile.is_superuser:
raise Http403
invoice = get_object_or_404(Invoice, pk=invoice_id)
if request.method == "POST":
email = Email()
form = form_class(request.POST, instance=email)
if form.is_valid():
email = form.save(commit=False)
email.sender_display = request.user.get_full_name()
email.reply_to = request.user.email
email.recipient = form.cleaned_data['recipient']
email.content_type = "html"
email.recipient_cc = form.cleaned_data['cc']
attachment = form.cleaned_data['attachment']
kwargs = {}
if attachment:
result = invoice_pdf(request, invoice)
kwargs['attachments'] = [("invoice_{}.pdf".format(invoice.id),
result.getvalue(),
'application/pdf')]
email.send(**kwargs)
EventLog.objects.log(instance=email)
msg_string = 'Successfully sent email invoice to {}.'.format(email.recipient)
messages.add_message(request, messages.SUCCESS, msg_string)
return HttpResponseRedirect(reverse('invoice.view', args=([invoice_id])))
else:
template = get_template("invoices/email_invoice_template.html")
body_initial = template.render(RequestContext(request, {
'invoice': invoice,}))
form = form_class(initial={'subject': 'Invoice for {}'.format(invoice.title),
'recipient': invoice.bill_to_email,
'body': body_initial})
return render_to_response(template_name, {
'invoice': invoice,
'form': form
},context_instance=RequestContext(request))
示例4: save
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [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
示例5: message
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [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})
示例6: handle
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import sender_display [as 别名]
def handle(self, *args, **options):
from tendenci.apps.events.models import Event, Registrant, Organizer
from tendenci.apps.emails.models import Email
from tendenci.apps.site_settings.utils import get_setting
from tendenci.apps.base.utils import convert_absolute_urls
from tendenci.apps.events.utils import (render_event_email,
get_default_reminder_template)
verbosity = options['verbosity']
site_url = get_setting('site', 'global', 'siteurl')
now = datetime.now()
today_tuple = (datetime(now.year, now.month, now.day, 0, 0, 0),
datetime(now.year, now.month, now.day, 23, 59, 59))
# get a list of upcoming events that are specified to send reminders.
events = Event.objects.filter(start_dt__gt=now,
registration_configuration__enabled=True,
registration_configuration__send_reminder=True,
status=True,
status_detail='active')
events_list = []
if events:
for event in events:
reg_conf = event.registration_configuration
reminder_days = reg_conf.reminder_days
if not reminder_days:
reminder_days = '1'
days_list = reminder_days.split(',')
for day in days_list:
try:
day = int(day)
except:
continue
start_dt = event.start_dt - timedelta(days=day)
if today_tuple[0] <= start_dt and start_dt <= today_tuple[1]:
events_list.append(event)
for event in events_list:
registrants = Registrant.objects.filter(
reminder=True,
registration__event=event,
cancel_dt=None
)
reg_conf = event.registration_configuration
[organizer] = Organizer.objects.filter(event=event)[:1] or [None]
event.organizer = organizer
email = reg_conf.email
if not email:
email = Email()
if not email.sender_display:
if organizer.name:
email.sender_display = organizer.name
if not email.reply_to:
if organizer.user and organizer.user.email:
email.reply_to = organizer.user.email
if not email.subject:
email.subject = 'Reminder: %s' % event.title
else:
email.subject = 'Reminder: %s' % email.subject
if not email.body:
email.body = get_default_reminder_template(event)
email = render_event_email(event, email)
# replace the relative links with absolute urls
# in the email body and subject
email.body = convert_absolute_urls(email.body, site_url)
event.email = email
self.send_reminders(event, registrants, verbosity=verbosity)