本文整理匯總了Python中django.contrib.sites.models.get_current_site方法的典型用法代碼示例。如果您正苦於以下問題:Python models.get_current_site方法的具體用法?Python models.get_current_site怎麽用?Python models.get_current_site使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.sites.models
的用法示例。
在下文中一共展示了models.get_current_site方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _akismet_check
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def _akismet_check(self, comment, content_object, request):
"""
Connects to Akismet and returns True if Akismet marks this comment as
spam. Otherwise returns False.
"""
# Get Akismet data
AKISMET_API_KEY = appsettings.AKISMET_API_KEY
if not AKISMET_API_KEY:
raise ImproperlyConfigured('You must set AKISMET_API_KEY to use comment moderation with Akismet.')
current_domain = get_current_site(request).domain
auto_blog_url = '{0}://{1}/'.format(request.is_secure() and 'https' or 'http', current_domain)
blog_url = appsettings.AKISMET_BLOG_URL or auto_blog_url
akismet = Akismet(
AKISMET_API_KEY,
blog=blog_url,
is_test=int(bool(appsettings.AKISMET_IS_TEST)),
application_user_agent='django-fluent-comments/{0}'.format(fluent_comments.__version__),
)
akismet_data = self._get_akismet_data(blog_url, comment, content_object, request)
return akismet.check(**akismet_data) # raises AkismetServerError when key is invalid
示例2: sender
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def sender(request, subject, template_name, context, to):
site = get_current_site(request)
context.update({'site_name': site.name,
'domain': site.domain,
'protocol': 'https' if request.is_secure() else 'http'})
message = render_to_string(template_name, context)
from_email = "%(site_name)s <%(name)s@%(domain)s>" % {'name': "noreply",
'domain': site.domain,
'site_name': site.name}
if len(to) > 1:
kwargs = {'bcc': to, }
else:
kwargs = {'to': to, }
email = EmailMessage(subject, message, from_email, **kwargs)
try:
email.send()
except SMTPException as err:
logger.error(err)
示例3: send_email
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def send_email(self, email):
User = get_user_model()
protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
current_site = get_current_site(self.request)
email_qs = User.objects.filter(email__iexact=email)
for user in User.objects.filter(pk__in=email_qs.values("user")):
uid = int_to_base36(user.id)
token = self.make_token(user)
password_reset_url = "{0}://{1}{2}".format(
protocol,
current_site.domain,
reverse("account_password_reset_token", kwargs=dict(uidb36=uid, token=token))
)
ctx = {
"user": user,
"current_site": current_site,
"password_reset_url": password_reset_url,
}
hookset.send_password_reset_email([user.email], ctx)
示例4: on_comment_posted
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def on_comment_posted(sender, comment, request, **kwargs):
"""
Send email notification of a new comment to site staff when email notifications have been requested.
"""
# This code is copied from django_comments.moderation.
# That code doesn't offer a RequestContext, which makes it really
# hard to generate proper URL's with FQDN in the email
#
# Instead of implementing this feature in the moderator class, the signal is used instead
# so the notification feature works regardless of a manual moderator.register() call in the project.
if not appsettings.FLUENT_COMMENTS_USE_EMAIL_NOTIFICATION:
return
recipient_list = [manager_tuple[1] for manager_tuple in settings.MANAGERS]
site = get_current_site(request)
content_object = comment.content_object
if comment.is_removed:
subject = u'[{0}] Spam comment on "{1}"'.format(site.name, content_object)
elif not comment.is_public:
subject = u'[{0}] Moderated comment on "{1}"'.format(site.name, content_object)
else:
subject = u'[{0}] New comment posted on "{1}"'.format(site.name, content_object)
context = {
'site': site,
'comment': comment,
'content_object': content_object
}
if django.VERSION >= (1, 8):
message = render_to_string("comments/comment_notification_email.txt", context, request=request)
else:
message = render_to_string("comments/comment_notification_email.txt", context, context_instance=RequestContext(request))
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True)
示例5: send_activation_email
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def send_activation_email(
user=None, request=None, from_email=None,
subject_template='users/activation_email_subject.html',
email_template='users/activation_email.html', html_email_template=None):
if not user.is_active and settings.USERS_VERIFY_EMAIL:
token_generator = EmailActivationTokenGenerator()
current_site = get_current_site(request)
context = {
'email': user.email,
'site': current_site,
'expiration_days': settings.USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS,
'user': user,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': token_generator.make_token(user=user),
'protocol': 'https' if request.is_secure() else 'http',
}
subject = render_to_string(subject_template, context)
# email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
body = render_to_string(email_template, context)
email_message = EmailMultiAlternatives(subject, body, from_email, [user.email])
if html_email_template is not None:
html_email = render_to_string(html_email_template, context)
email_message.attach_alternative(html_email, 'text/html')
email_message.send()
示例6: send_email_confirmation
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def send_email_confirmation(self, email_address):
email_address.send_confirmation(site=get_current_site(self.request))
示例7: register
# 需要導入模塊: from django.contrib.sites import models [as 別名]
# 或者: from django.contrib.sites.models import get_current_site [as 別名]
def register(request,
template_name='users/registration_form.html',
activation_email_template_name='users/activation_email.html',
activation_email_subject_template_name='users/activation_email_subject.html',
activation_email_html_template_name=None,
registration_form=RegistrationForm,
registered_user_redirect_to=None,
post_registration_redirect=None,
activation_from_email=None,
current_app=None,
extra_context=None):
if registered_user_redirect_to is None:
registered_user_redirect_to = getattr(settings, 'LOGIN_REDIRECT_URL')
if request.user.is_authenticated:
return redirect(registered_user_redirect_to)
if not settings.USERS_REGISTRATION_OPEN:
return redirect(reverse('users_registration_closed'))
if post_registration_redirect is None:
post_registration_redirect = reverse('users_registration_complete')
if request.method == 'POST':
form = registration_form(request.POST)
if form.is_valid():
user = form.save()
if settings.USERS_AUTO_LOGIN_AFTER_REGISTRATION:
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
elif not user.is_active and settings.USERS_VERIFY_EMAIL:
opts = {
'user': user,
'request': request,
'from_email': activation_from_email,
'email_template': activation_email_template_name,
'subject_template': activation_email_subject_template_name,
'html_email_template': activation_email_html_template_name,
}
send_activation_email(**opts)
user_registered.send(sender=user.__class__, request=request, user=user)
return redirect(post_registration_redirect)
else:
form = registration_form()
current_site = get_current_site(request)
context = {
'form': form,
'site': current_site,
'site_name': current_site.name,
'title': _('Register'),
}
if extra_context is not None: # pragma: no cover
context.update(extra_context)
return TemplateResponse(request, template_name, context)