本文整理汇总了Python中synnefo_branding.utils.render_to_string函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_string函数的具体用法?Python render_to_string怎么用?Python render_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _send_admin_notification
def _send_admin_notification(template_name,
context=None,
user=None,
msg="",
subject='alpha2 testing notification',):
"""
Send notification email to settings.HELPDESK + settings.MANAGERS +
settings.ADMINS.
"""
if context is None:
context = {}
if not 'user' in context:
context['user'] = user
message = render_to_string(template_name, context)
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK +
settings.MANAGERS + settings.ADMINS]
send_mail(subject, message, sender, recipient_list,
connection=get_connection())
if user:
msg = 'Sent admin notification (%s) for user %s' % (msg,
user.log_display)
else:
msg = 'Sent admin notification (%s)' % msg
logger.log(settings.LOGGING_LEVEL, msg)
示例2: api_access_config
def api_access_config(request, template_name='im/api_access_config.html',
content_type='text/plain', extra_context=None,
filename='.kamakirc'):
if settings.KAMAKI_CONFIG_CLOUD_NAME:
cloud_name = settings.KAMAKI_CONFIG_CLOUD_NAME
else:
cloud_name = branding_settings.SERVICE_NAME.replace(' ', '_').lower()
url = get_public_endpoint(settings.astakos_services, 'identity')
context = {
'user': request.user,
'services': Component.catalog(),
'token_url': url,
'cloud_name': cloud_name
}
extra_context = extra_context or {}
context.update(extra_context)
content = branding.render_to_string(template_name, context,
RequestContext(request))
response = HttpResponse(content_type=content_type)
response.status_code = 200
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
response.content = content
return response
示例3: send_plain
def send_plain(user, sender=settings.SERVER_EMAIL,
subject=_(astakos_messages.PLAIN_EMAIL_SUBJECT),
template_name='im/plain_email.txt', text=None):
"""Send mail to user with fully customizable sender, subject and body.
If the function is provided with a `template name`, then it will be used
for rendering the mail. Any additional text should be provided in the
`text` parameter and it will be included in the main body of the mail.
If the function is not provided with a `template name`, then it will use
the string provided in the `text` parameter as the mail body.
"""
if not template_name:
message = text
else:
message = render_to_string(template_name, {
'user': user,
'text': text,
'baseurl': settings.BASE_URL,
'site_name': settings.SITENAME,
'support': settings.CONTACT_EMAIL})
send_mail(subject, message, sender, [user.email],
connection=get_connection())
logger.info("Sent plain email to user: %s", user.log_display)
示例4: save
def save(self, domain_override=None,
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
request=None, **kwargs):
"""
Generates a one-use only link for resetting password
and sends to the user.
"""
for user in self.users_cache:
url = user.astakosuser.get_password_reset_url(token_generator)
url = join_urls(settings.BASE_HOST, url)
c = {
'email': user.email,
'url': url,
'site_name': settings.SITENAME,
'user': user,
'baseurl': settings.BASE_URL,
'support': settings.CONTACT_EMAIL
}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(astakos_messages.PASSWORD_RESET_EMAIL_SUBJECT),
message,
from_email,
[user.email],
connection=get_connection())
示例5: send_change_email_to_old
def send_change_email_to_old(email_change,
email_template_name='registration/email_change_email_old_email.txt'):
message = render_to_string(email_template_name, {'ec': email_change})
from_email = settings.SERVER_EMAIL
send_mail(_(astakos_messages.EMAIL_CHANGE_OLD_EMAIL_SUBJECT), message,
from_email, [email_change.user.email], connection=get_connection())
示例6: __init__
def __init__(self, sender, recipients, subject,
message=None, template=None, dictionary=None):
if not message and not template:
raise IOError('message and template cannot be both None.')
dictionary = dictionary or {}
self.sender = sender
self.recipients = recipients
self.subject = subject
self.message = message or render_to_string(template, dictionary)
示例7: render
def render(self, *args, **kwargs):
conf = settings.RECAPTCHA_OPTIONS
recaptcha_conf = ('<script type="text/javascript">' "var RecaptchaOptions = %s" "</script>") % json.dumps(conf)
custom_widget_html = render_to_string("im/captcha.html", {"conf": "Bob"})
return mark_safe(
recaptcha_conf
+ custom_widget_html
+ captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY, use_ssl=settings.RECAPTCHA_USE_SSL)
)
示例8: send_feedback
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
subject = _(astakos_messages.FEEDBACK_EMAIL_SUBJECT)
from_email = settings.SERVER_EMAIL
recipient_list = [e[1] for e in settings.HELPDESK]
content = render_to_string(email_template_name, {
'message': msg,
'data': data,
'user': user})
send_mail(subject, content, from_email, recipient_list,
connection=get_connection())
msg = 'Sent feedback from %s'
logger.log(settings.LOGGING_LEVEL, msg, user.log_display)
示例9: send_change_email
def send_change_email(
ec, request, email_template_name='registration/email_change_email.txt'):
url = ec.get_url()
url = request.build_absolute_uri(url)
c = {'url': url, 'site_name': settings.SITENAME, 'support': settings.CONTACT_EMAIL,
'ec': ec}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(astakos_messages.EMAIL_CHANGE_EMAIL_SUBJECT), message,
from_email,
[ec.new_email_address], connection=get_connection())
msg = 'Sent change email for %s' % ec.user.log_display
logger.log(settings.LOGGING_LEVEL, msg)
示例10: confirm_link
def confirm_link(context, title, prompt='', url=None, urlarg=None,
extracontent='',
confirm_prompt=None,
inline=True,
cls='',
template="im/table_rich_link_column.html"):
urlargs = None
if urlarg:
if isinstance(urlarg, basestring) and "," in urlarg:
args = urlarg.split(",")
for index, arg in enumerate(args):
property = None
if "." in arg:
arg, property = arg.split(".")
if context.get(arg, None) is not None:
val = context.get(arg)
if property:
val = getattr(val, property)
args[index] = val
urlargs = args
else:
urlargs = (urlarg,)
if CONFIRM_LINK_PROMPT_MAP.get(prompt, None):
prompt = mark_safe(CONFIRM_LINK_PROMPT_MAP.get(prompt))
if url:
url = reverse(url, args=urlargs)
else:
url = None
title = _(title)
tpl_context = RequestContext(context.get('request'))
tpl_context.update({
'col': {
'method': 'POST',
'cancel_prompt': 'CANCEL',
'confirm_prompt': confirm_prompt or title
},
'inline': inline,
'url': url,
'action': title,
'cls': cls,
'prompt': prompt,
'extra_form_content': EXTRA_CONTENT_MAP.get(extracontent, ''),
'confirm': True
})
content = render_to_string(template, tpl_context)
return content
示例11: send_change_email_to_new
def send_change_email_to_new(ec, email_template_name=(
'registration/email_change_email_new_email.txt')):
url = ec.get_url()
url = urlparse.urljoin(settings.BASE_URL, url)
c = {'url': url,
'support': settings.CONTACT_EMAIL,
'ec': ec}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(astakos_messages.EMAIL_CHANGE_NEW_EMAIL_SUBJECT), message,
from_email,
[ec.new_email_address], connection=get_connection())
msg = 'Sent change email for %s'
logger.log(settings.LOGGING_LEVEL, msg, ec.user.log_display)
示例12: confirm_link
def confirm_link(
context,
title,
prompt="",
url=None,
urlarg=None,
extracontent="",
confirm_prompt=None,
inline=True,
cls="",
template="im/table_rich_link_column.html",
):
urlargs = None
if urlarg:
if isinstance(urlarg, basestring) and "," in urlarg:
args = urlarg.split(",")
for index, arg in enumerate(args):
if context.get(arg, None) is not None:
args[index] = context.get(arg)
urlargs = args
else:
urlargs = (urlarg,)
if CONFIRM_LINK_PROMPT_MAP.get(prompt, None):
prompt = mark_safe(CONFIRM_LINK_PROMPT_MAP.get(prompt))
if url:
url = reverse(url, args=urlargs)
else:
url = None
title = _(title)
tpl_context = RequestContext(context.get("request"))
tpl_context.update(
{
"col": {"method": "POST", "cancel_prompt": "CANCEL", "confirm_prompt": confirm_prompt or title},
"inline": inline,
"url": url,
"action": title,
"cls": cls,
"prompt": prompt,
"extra_form_content": EXTRA_CONTENT_MAP.get(extracontent, ""),
"confirm": True,
}
)
content = render_to_string(template, tpl_context)
return content
示例13: test_send_plain_email
def test_send_plain_email(self):
"""Test if send_plain_email function works as intended."""
def verify_sent_email(email_dict, mail):
"""Helper function to verify that an email was sent properly."""
sender = email_dict.get('sender', astakos_settings.SERVER_EMAIL)
subject = email_dict.get('subject',
_(astakos_messages.PLAIN_EMAIL_SUBJECT))
self.assertEqual(sender, mail.from_email)
self.assertEqual(subject, mail.subject)
self.assertEqual(email_dict['text'], mail.body)
# Common variables
template_name = 'im/plain_email.txt'
text = u"Δεσποινίς, που είναι η μπάλα; Ümlaut.)?"
expected_text = render_to_string(template_name, {
'user': self.user1,
'text': text,
'baseurl': astakos_settings.BASE_URL,
'site_name': astakos_settings.SITENAME,
'support': astakos_settings.CONTACT_EMAIL})
# Test 1 - Check if a simple test mail is sent properly.
send_plain(self.user1, text=text)
self.assertEqual(len(mail.outbox), 1)
body = mail.outbox[0].body
self.assertEqual(expected_text, body)
# Test 2 - Check if the email template can get overriden.
email_dict = {
'template_name': None,
'text': expected_text,
}
send_plain(self.user1, **email_dict)
self.assertEqual(len(mail.outbox), 2)
verify_sent_email(email_dict, mail.outbox[1])
# Test 3 - Check if the email subject can get overriden.
email_dict.update({'subject': u"Το θέμα μας είναι: Ümlaut."})
send_plain(self.user1, **email_dict)
self.assertEqual(len(mail.outbox), 3)
verify_sent_email(email_dict, mail.outbox[2])
# Test 4 - Check if the email sender can get overriden.
email_dict.update({'sender': "[email protected]"})
send_plain(self.user1, **email_dict)
self.assertEqual(len(mail.outbox), 4)
verify_sent_email(email_dict, mail.outbox[3])
示例14: send_account_pending_moderation_notification
def send_account_pending_moderation_notification(
user,
template_name='im/account_pending_moderation_notification.txt'):
"""
Notify 'ACCOUNT_PENDING_MODERATION_RECIPIENTS' that a new user has verified
his email address and moderation step is required to activate his account.
"""
subject = (_(astakos_messages.ACCOUNT_CREATION_SUBJECT) %
{'user': user.email})
message = render_to_string(template_name, {'user': user})
sender = settings.SERVER_EMAIL
recipient_list = [e[1] for e in
settings.ACCOUNT_PENDING_MODERATION_RECIPIENTS]
send_mail(subject, message, sender, recipient_list,
connection=get_connection())
msg = 'Sent admin notification (account creation) for user %s'
logger.log(settings.LOGGING_LEVEL, msg, user.log_display)
示例15: send_verification
def send_verification(user, template_name='im/activation_email.txt'):
"""
Send email to user to verify his/her email and activate his/her account.
"""
index_url = reverse('index', urlconf="synnefo.webproject.urls")
url = join_urls(settings.BASE_HOST,
user.get_activation_url(nxt=index_url))
message = render_to_string(template_name, {
'user': user,
'url': url,
'baseurl': settings.BASE_URL,
'support': settings.CONTACT_EMAIL})
sender = settings.SERVER_EMAIL
send_mail(_(astakos_messages.VERIFICATION_EMAIL_SUBJECT), message, sender,
[user.email],
connection=get_connection())
logger.info("Sent user verification email: %s", user.log_display)