本文整理汇总了Python中userena.utils.get_protocol函数的典型用法代码示例。如果您正苦于以下问题:Python get_protocol函数的具体用法?Python get_protocol怎么用?Python get_protocol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_protocol函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_protocol
def test_get_protocol(self):
""" Test if the correct protocol is returned """
self.failUnlessEqual(get_protocol(), 'http')
userena_settings.USERENA_USE_HTTPS = True
self.failUnlessEqual(get_protocol(), 'https')
userena_settings.USERENA_USE_HTTPS = False
示例2: send_confirmation_email
def send_confirmation_email(self):
# TODO !!!!!!!!!
context = {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'new_email': self.email_unconfirmed,
'protocol': get_protocol(),
'confirmation_key': self.email_confirmation_key,
'site': Site.objects.get_current()}
# Email to the old address, if present
subject_old = render_to_string('userena/emails/confirmation_email_subject_old.txt',
context)
subject_old = ''.join(subject_old.splitlines())
message_old = render_to_string('userena/emails/confirmation_email_message_old.txt',
context)
if self.user.email:
send_mail(subject_old,
message_old,
settings.DEFAULT_FROM_EMAIL,
[self.user.email])
# Email to the new address
subject_new = render_to_string('userena/emails/confirmation_email_subject_new.txt',
context)
subject_new = ''.join(subject_new.splitlines())
message_new = render_to_string('userena/emails/confirmation_email_message_new.txt',
context)
send_mail(subject_new,
message_new,
settings.DEFAULT_FROM_EMAIL,
[self.email_unconfirmed, ])
示例3: send_confirmation_email
def send_confirmation_email(self):
"""
Sends an email to confirm the new email address.
This method sends out two emails. One to the new email address that
contains the ``email_confirmation_key`` which is used to verify this
this email address with :func:`UserenaUser.objects.confirm_email`.
The other email is to the old email address to let the user know that
a request is made to change this email address.
"""
context = {
"user": self.user,
"new_email": self.email_unconfirmed,
"protocol": get_protocol(),
"confirmation_key": self.email_confirmation_key,
"site": Site.objects.get_current(),
}
# Email to the old address
subject_old = render_to_string("userena/emails/confirmation_email_subject_old.txt", context)
subject_old = "".join(subject_old.splitlines())
message_old = render_to_string("userena/emails/confirmation_email_message_old.txt", context)
send_mail(subject_old, message_old, settings.DEFAULT_FROM_EMAIL, [self.user.email])
# Email to the new address
subject_new = render_to_string("userena/emails/confirmation_email_subject_new.txt", context)
subject_new = "".join(subject_new.splitlines())
message_new = render_to_string("userena/emails/confirmation_email_message_new.txt", context)
send_mail(subject_new, message_new, settings.DEFAULT_FROM_EMAIL, [self.email_unconfirmed])
示例4: send_activation_email
def send_activation_email(self):
"""
Sends a activation email to the user.
This email is send when the user wants to activate their newly created
user.
"""
context= {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current()}
subject = render_to_string('userena/emails/activation_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
message = render_to_string('userena/emails/activation_email_message.txt',
context)
try:
send_mail(subject,
message,
settings.DEFAULT_FROM_EMAIL,
[self.user.email,])
except:
pass
示例5: send_activation_email
def send_activation_email(self):
"""
Sends a activation email to the user.
This email is send when the user wants to activate their newly created
user.
"""
context= {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current()}
subject = render_to_string('userena/emails/activation_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
message = render_to_string('userena/emails/activation_email_message.txt',
context)
# EMRE Modified this to use smtplib. This method doesn't work.
send_mail(subject,
message,
settings.DEFAULT_FROM_EMAIL,
[self.user.email,])
"""msg = ("From: %s\r\nTo: %s\r\nSubject:%s\r\n\r\n%s\r\n"
示例6: send_activation_email
def send_activation_email(
self, template="userena/emails/activation_email_message.txt", headers=None, attach_list=[]
):
"""
Sends a activation email to the user.
This email is send when the user wants to activate their newly created
user.
"""
context = {
"user": self.user,
"without_usernames": userena_settings.USERENA_WITHOUT_USERNAMES,
"protocol": get_protocol(),
"activation_days": userena_settings.USERENA_ACTIVATION_DAYS,
"activation_key": self.activation_key,
"site": Site.objects.get_current(),
}
subject = render_to_string("userena/emails/activation_email_subject.txt", context)
subject = "".join(subject.splitlines())
body = render_to_string(template, context)
message = EmailMessage(subject, body, settings.DEFAULT_FROM_EMAIL, [self.user.email], headers=headers)
if template.split(".")[-1] == "html":
message.content_subtype = "html"
for attachment in attach_list:
message.attach(attachment)
message.send()
示例7: send_confirmation_email
def send_confirmation_email(self):
"""
Sends an email to confirm the new email address.
This method sends out two emails. One to the new email address that
contains the ``email_confirmation_key`` which is used to verify this
this email address with :func:`UserenaUser.objects.confirm_email`.
The other email is to the old email address to let the user know that
a request is made to change this email address.
"""
context = {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'new_email': self.email_unconfirmed,
'protocol': get_protocol(),
'confirmation_key': self.email_confirmation_key,
'site': Site.objects.get_current()}
mailer = UserenaConfirmationMail(context=context)
mailer.generate_mail("confirmation", "_old")
if self.user.email:
mailer.send_mail(self.user.email)
mailer.generate_mail("confirmation", "_new")
mailer.send_mail(self.email_unconfirmed)
示例8: send_invite_email
def send_invite_email(self, promoter):
"""
Sends a invitation email to the user.
This email is sent when a user invites another user to to join.
"""
context = {'user': self.user,
'promoter': promoter,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current()}
subject = render_to_string('userena/emails/invitation_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
message = render_to_string('userena/emails/invitation_email_message.txt',
context)
send_mail(subject,
message,
settings.DEFAULT_FROM_EMAIL,
[self.user.email,])
示例9: send_activation_email_with_password
def send_activation_email_with_password(userena_signup_obj, password):
"""
Sends a activation email to the user, along with an
automatically generated password that they need to log in.
This function only exists because userena/models.py's
UserenaSignup.send_activation_email() doesn't have a way to
add custom context.
"""
context= {'user': userena_signup_obj.user,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': userena_signup_obj.activation_key,
'site': Site.objects.get_current(),
'password': password}
subject = render_to_string('userena/emails/activation_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
message = render_to_string('userena/emails/activation_email_message.txt',
context)
send_mail(subject,
message,
settings.DEFAULT_FROM_EMAIL,
[userena_signup_obj.user.email,])
示例10: send_message_notification
def send_message_notification(sender, instance, **kwargs):
"""
Send email when user receives a new message. This email contains the full text
and a link to read it online.
We trigger this when a MessageRecipient is saved and not when a Message is
saved because umessages first saves a message and then adds its recipients,
so when a Message is saved, it doesn't yet have a list of recipients.
"""
if not instance.user.email:
# Email can be missing for users registered with Twitter
# or LinkedIn
return
params = {"sender": instance.message.sender.username, "body": instance.message.body}
message_url_path = reverse("userena_umessages_detail", kwargs={"username": params["sender"]})
params["message_url"] = "%s://%s%s" % (get_protocol(), Site.objects.get_current(), message_url_path)
subject = _(u"New message from %(sender)s on Imagination For People") % params
message = render_to_string("umessages/message_notification.txt", params)
recipient = instance.user.email
# XXX Resets the Content-Transfer-Encoding in email header
# Avoids bad encoding of UTF-8 body
# See https://code.djangoproject.com/ticket/3472
from email import Charset
Charset.add_charset("utf-8", Charset.SHORTEST, "utf-8", "utf-8")
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [recipient])
示例11: send_message_notification
def send_message_notification(sender, instance, **kwargs):
"""
Send email when user receives a new message. This email contains the full text
and a link to read it online.
We trigger this when a MessageRecipient is saved and not when a Message is
saved because umessages first saves a message and then adds its recipients,
so when a Message is saved, it doesn't yet have a list of recipients.
"""
if not instance.user.email:
# Email can be missing for users registered with Twitter
# or LinkedIn
return
params = {
'sender': instance.message.sender.username,
'body': instance.message.body,
}
message_url_path = reverse('userena_umessages_detail',
kwargs={'username': params['sender']})
params['message_url'] = "%s://%s%s" % (
get_protocol(),
Site.objects.get_current(),
message_url_path)
subject = _(u'Message from %(sender)s') % params
message = render_to_string('umessages/message_notification.txt', params)
recipient = instance.user.email
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [recipient])
示例12: send_activation_email
def send_activation_email(self):
"""
Sends a activation email to the user.
This email is send when the user wants to activate their newly created
user.
"""
context = {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current(),
'settings': settings}
subject = render_to_string(userena_settings.USERENA_ACTIVATION_EMAIL_SUBJECT_TEMPLATE,
context)
subject = ''.join(subject.splitlines())
message = render_to_string(userena_settings.USERENA_ACTIVATION_EMAIL_MESSAGE_TEMPLATE,
context)
send_mail_module = importlib.import_module(userena_settings.USERENA_SEND_EMAIL_MODULE)
send_mail_module.send_mail(subject,
message,
settings.DEFAULT_FROM_EMAIL,
[self.user.email, ])
示例13: send_approval_email
def send_approval_email(self):
"""
Sends an approval email to the user.
This email is sent when USERENA_MODERATE_REGISTRATION, after an admin
has approved the registration.
"""
context= {'user': self.user,
'protocol': get_protocol(),
'site': Site.objects.get_current()}
subject = render_to_string('userena/emails/approval_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
message = render_to_string('userena/emails/approval_email_message.txt',
context)
if userena_settings.USERENA_HTML_EMAIL:
message_html = render_to_string('userena/emails/approval_email_message.html',
context)
else:
message_html = None
send_mail(subject,
message,
message_html,
settings.DEFAULT_FROM_EMAIL,
[self.user.email,])
示例14: send_activation_email
def send_activation_email(self):
"""
Sends a activation email to the user.
This email is sent_activation_email when the user wants to activate their newly created
user.
"""
context = {'user': self.user,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current()}
mailer = UserenaConfirmationMail(context=context)
mailer.generate_mail("activation")
mailer.send_mail(self.user.email)
#Send email to admins with the same message
emaillist = []
if settings.USERENA_ADMIN_MODERATION:
for k, v in settings.ADMINS:
emaillist.append(v)
send_mail(settings.SITE_NAME + " - Activation done",
message,
message_html,
settings.DEFAULT_FROM_EMAIL,
emaillist)
示例15: send_activation_email
def send_activation_email(self, first_name = '', last_name = ''):
"""
Sends a activation email to the user.
This email is send when the user wants to activate their newly created
user.
"""
context = {'user': self.user,
'first_name': first_name,
'last_name': last_name,
'without_usernames': userena_settings.USERENA_WITHOUT_USERNAMES,
'protocol': get_protocol(),
'activation_days': userena_settings.USERENA_ACTIVATION_DAYS,
'activation_key': self.activation_key,
'site': Site.objects.get_current()}
subject = render_to_string('userena/emails/activation_email_subject.txt',
context)
subject = ''.join(subject.splitlines())
text_content = render_to_string('userena/emails/activation_email_message.txt',
context)
html_content = render_to_string('userena/emails/activation_email_message.html',
context)
email = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.user.email, ])
email.attach_alternative(html_content, "text/html")
email.send()