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


Python UserProfile.get_for_user方法代码示例

本文整理汇总了Python中wagtail.wagtailusers.models.UserProfile.get_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.get_for_user方法的具体用法?Python UserProfile.get_for_user怎么用?Python UserProfile.get_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.wagtailusers.models.UserProfile的用法示例。


在下文中一共展示了UserProfile.get_for_user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
    def setUp(self):
        # Find root page
        self.root_page = Page.objects.get(id=2)

        # Login
        self.user = self.login()

        # Create two moderator users for testing 'submitted' email
        self.moderator = User.objects.create_superuser('moderator', '[email protected]', 'password')
        self.moderator2 = User.objects.create_superuser('moderator2', '[email protected]', 'password')

        # Create a submitter for testing 'rejected' and 'approved' emails
        self.submitter = User.objects.create_user('submitter', '[email protected]', 'password')

        # User profiles for moderator2 and the submitter
        self.moderator2_profile = UserProfile.get_for_user(self.moderator2)
        self.submitter_profile = UserProfile.get_for_user(self.submitter)

        # Create a page and submit it for moderation
        self.child_page = SimplePage(
            title="Hello world!",
            slug='hello-world',
            live=False,
        )
        self.root_page.add_child(instance=self.child_page)

        # POST data to edit the page
        self.post_data = {
            'title': "I've been edited!",
            'content': "Some content",
            'slug': 'hello-world',
            'action-submit': "Submit",
        }
开发者ID:ostmodern,项目名称:wagtail,代码行数:35,代码来源:test_pages_views.py

示例2: send_notification

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def send_notification(page_revision_id, notification, excluded_user_id):
    # Get revision
    revision = PageRevision.objects.get(id=page_revision_id)

    # Get list of recipients
    if notification == 'submitted':
        # Get list of publishers
        recipients = users_with_page_permission(revision.page, 'publish')
    elif notification in ['rejected', 'approved']:
        # Get submitter
        recipients = [revision.user]
    else:
        return

    # Get list of email addresses
    email_addresses = [
        recipient.email for recipient in recipients
        if recipient.email and recipient.id != excluded_user_id and getattr(UserProfile.get_for_user(recipient), notification + '_notifications')
    ]

    # Return if there are no email addresses
    if not email_addresses:
        return

    # Get email subject and content
    template = 'wagtailadmin/notifications/' + notification + '.html'
    rendered_template = render_to_string(template, dict(revision=revision, settings=settings)).split('\n')
    email_subject = rendered_template[0]
    email_content = '\n'.join(rendered_template[1:])

    # Send email
    send_mail(email_subject, email_content, email_addresses)
开发者ID:dangquocthai,项目名称:wagtail,代码行数:34,代码来源:utils.py

示例3: language_preferences

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def language_preferences(request):
    if request.method == 'POST':
        form = PreferredLanguageForm(request.POST, instance=UserProfile.get_for_user(request.user))

        if form.is_valid():
            user_profile = form.save()
            # This will set the language only for this request/thread
            # (so that the 'success' messages is in the right language)
            activate(user_profile.get_preferred_language())
            messages.success(request, _("Your preferences have been updated."))
            return redirect('wagtailadmin_account')
    else:
        form = PreferredLanguageForm(instance=UserProfile.get_for_user(request.user))

    return render(request, 'wagtailadmin/account/language_preferences.html', {
        'form': form,
    })
开发者ID:kapito,项目名称:wagtail,代码行数:19,代码来源:account.py

示例4: notification_preferences

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def notification_preferences(request):

    if request.POST:
        form = NotificationPreferencesForm(request.POST, instance=UserProfile.get_for_user(request.user))

        if form.is_valid():
            form.save()
            messages.success(request, _("Your preferences have been updated successfully!"))
            return redirect("wagtailadmin_account")
    else:
        form = NotificationPreferencesForm(instance=UserProfile.get_for_user(request.user))

    # quick-and-dirty catch-all in case the form has been rendered with no
    # fields, as the user has no customisable permissions
    if not form.fields:
        return redirect("wagtailadmin_account")

    return render(request, "wagtailadmin/account/notification_preferences.html", {"form": form})
开发者ID:radowit,项目名称:wagtail,代码行数:20,代码来源:account.py

示例5: send_notification

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def send_notification(page_revision_id, notification, excluded_user_id):
    # Get revision
    revision = PageRevision.objects.get(id=page_revision_id)

    # Get list of recipients
    if notification == 'submitted':
        # Get list of publishers
        recipients = users_with_page_permission(revision.page, 'publish')
    elif notification in ['rejected', 'approved']:
        # Get submitter
        recipients = [revision.user]
    else:
        return

    # Get list of email addresses
    email_recipients = [
        recipient for recipient in recipients
        if recipient.email and recipient.pk != excluded_user_id and getattr(
            UserProfile.get_for_user(recipient),
            notification + '_notifications'
        )
    ]

    # Return if there are no email addresses
    if not email_recipients:
        return

    # Get template
    template_subject = 'wagtailadmin/notifications/' + notification + '_subject.txt'
    template_text = 'wagtailadmin/notifications/' + notification + '.txt'
    template_html = 'wagtailadmin/notifications/' + notification + '.html'

    # Common context to template
    context = {
        "revision": revision,
        "settings": settings,
    }

    # Send emails
    for recipient in email_recipients:
        # update context with this recipient
        context["user"] = recipient

        # Get email subject and content
        email_subject = render_to_string(template_subject, context).strip()
        email_content = render_to_string(template_text, context).strip()

        kwargs = {}
        if getattr(settings, 'WAGTAILADMIN_NOTIFICATION_USE_HTML', False):
            kwargs['html_message'] = render_to_string(template_html, context)

        # Send email
        send_mail(email_subject, email_content, [recipient.email], **kwargs)
开发者ID:MuhammadYossry,项目名称:wagtail,代码行数:55,代码来源:utils.py

示例6: test_unset_language_preferences

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
    def test_unset_language_preferences(self):
        # Post new values to the language preferences page
        post_data = {
            'preferred_language': ''
        }
        response = self.client.post(reverse('wagtailadmin_account_language_preferences'), post_data)

        # Check that the user was redirected to the account page
        self.assertRedirects(response, reverse('wagtailadmin_account'))

        profile = UserProfile.get_for_user(get_user_model().objects.get(pk=self.user.pk))

        # Check that the language preferences are stored
        self.assertEqual(profile.preferred_language, '')
开发者ID:kapito,项目名称:wagtail,代码行数:16,代码来源:test_account_management.py

示例7: send_notification

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def send_notification(page_revision_id, notification, excluded_user_id):
    # Get revision
    revision = PageRevision.objects.get(id=page_revision_id)

    # Get list of recipients
    if notification == 'submitted':
        # Get list of publishers
        recipients = users_with_page_permission(revision.page, 'publish')
    elif notification in ['rejected', 'approved']:
        # Get submitter
        recipients = [revision.user]
    else:
        return

    # Get list of email addresses
    email_recipients = [
        recipient for recipient in recipients
        if recipient.email and recipient.id != excluded_user_id and getattr(
            UserProfile.get_for_user(recipient),
            notification + '_notifications'
        )
    ]

    # Return if there are no email addresses
    if not email_recipients:
        return

    # Get template
    template = 'wagtailadmin/notifications/' + notification + '.html'

    # Common context to template
    context = {
        "revision": revision,
        "settings": settings,
    }

    # Send emails
    for recipient in email_recipients:
        # update context with this recipient
        context["user"] = recipient

        # Get email subject and content
        email_subject, email_content = render_to_string(template, context).split('\n', 1)

        # Send email
        send_mail(email_subject, email_content, [recipient.email])
开发者ID:AdamBolfik,项目名称:wagtail,代码行数:48,代码来源:utils.py

示例8: send_notification

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
def send_notification(page_revision_id, notification, excluded_user_id):
    # Get revision
    revision = PageRevision.objects.get(id=page_revision_id)

    # Get list of recipients
    if notification == "submitted":
        # Get list of publishers
        recipients = users_with_page_permission(revision.page, "publish")
    elif notification in ["rejected", "approved"]:
        # Get submitter
        recipients = [revision.user]
    else:
        return

    # Get list of email addresses
    email_addresses = [
        recipient.email
        for recipient in recipients
        if recipient.email
        and recipient.id != excluded_user_id
        and getattr(UserProfile.get_for_user(recipient), notification + "_notifications")
    ]

    # Return if there are no email addresses
    if not email_addresses:
        return

    # Get email subject and content
    template = "wagtailadmin/notifications/" + notification + ".html"
    rendered_template = render_to_string(template, dict(revision=revision, settings=settings)).split("\n")
    email_subject = rendered_template[0]
    email_content = "\n".join(rendered_template[1:])

    # Get from email
    if hasattr(settings, "WAGTAILADMIN_NOTIFICATION_FROM_EMAIL"):
        from_email = settings.WAGTAILADMIN_NOTIFICATION_FROM_EMAIL
    elif hasattr(settings, "DEFAULT_FROM_EMAIL"):
        from_email = settings.DEFAULT_FROM_EMAIL
    else:
        from_email = "[email protected]"

    # Send email
    send_mail(email_subject, email_content, from_email, email_addresses)
开发者ID:0b3r,项目名称:wagtail,代码行数:45,代码来源:tasks.py

示例9: test_notification_preferences_view_post

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
    def test_notification_preferences_view_post(self):
        """
        This posts to the notification preferences view and checks that the
        user's profile is updated
        """
        # Post new values to the notification preferences page
        post_data = {
            'submitted_notifications': 'false',
            'approved_notifications': 'false',
            'rejected_notifications': 'true',
        }
        response = self.client.post(reverse('wagtailadmin_account_notification_preferences'), post_data)

        # Check that the user was redirected to the account page
        self.assertRedirects(response, reverse('wagtailadmin_account'))

        profile = UserProfile.get_for_user(get_user_model().objects.get(username='test'))

        # Check that the notification preferences are as submitted
        self.assertFalse(profile.submitted_notifications)
        self.assertFalse(profile.approved_notifications)
        self.assertTrue(profile.rejected_notifications)
开发者ID:EricSchles,项目名称:wagtail,代码行数:24,代码来源:test_account_management.py

示例10: test_user_profile_created_when_method_called

# 需要导入模块: from wagtail.wagtailusers.models import UserProfile [as 别名]
# 或者: from wagtail.wagtailusers.models.UserProfile import get_for_user [as 别名]
 def test_user_profile_created_when_method_called(self):
     self.assertIsInstance(UserProfile.get_for_user(self.test_user), UserProfile)
     # and get it from the db too
     self.assertEqual(UserProfile.objects.filter(user=self.test_user).count(), 1)
开发者ID:pjdelport,项目名称:wagtail,代码行数:6,代码来源:tests.py


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