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


Python models.get_current_site方法代码示例

本文整理汇总了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 
开发者ID:82Flex,项目名称:DCRM,代码行数:25,代码来源:moderation.py

示例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) 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:23,代码来源:email.py

示例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) 
开发者ID:madre,项目名称:devops,代码行数:21,代码来源:views.py

示例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) 
开发者ID:82Flex,项目名称:DCRM,代码行数:37,代码来源:models.py

示例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() 
开发者ID:mishbahr,项目名称:django-users2,代码行数:33,代码来源:utils.py

示例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)) 
开发者ID:madre,项目名称:devops,代码行数:4,代码来源:views.py

示例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) 
开发者ID:mishbahr,项目名称:django-users2,代码行数:60,代码来源:views.py


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