當前位置: 首頁>>代碼示例>>Python>>正文


Python models.UserProfile類代碼示例

本文整理匯總了Python中wagtail.users.models.UserProfile的典型用法代碼示例。如果您正苦於以下問題:Python UserProfile類的具體用法?Python UserProfile怎麽用?Python UserProfile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UserProfile類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: change_avatar

def change_avatar(request):
    if request.method == 'POST':
        user_profile = UserProfile.get_for_user(request.user)
        form = AvatarPreferencesForm(request.POST, request.FILES, instance=user_profile)
        if form.is_valid():
            form.save()
            messages.success(request, _("Your preferences have been updated successfully!"))
            return redirect('wagtailadmin_account_change_avatar')
    else:
        form = AvatarPreferencesForm(instance=UserProfile.get_for_user(request.user))

    return render(request, 'wagtailadmin/account/change_avatar.html', {'form': form})
開發者ID:balazs-endresz,項目名稱:wagtail,代碼行數:12,代碼來源:account.py

示例2: current_time_zone

def current_time_zone(request):
    if request.method == 'POST':
        form = CurrentTimeZoneForm(request.POST, instance=UserProfile.get_for_user(request.user))

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

    return render(request, 'wagtailadmin/account/current_time_zone.html', {
        'form': form,
    })
開發者ID:balazs-endresz,項目名稱:wagtail,代碼行數:14,代碼來源:account.py

示例3: test_uploaded_avatar

    def test_uploaded_avatar(self):
        user_profile = UserProfile.get_for_user(self.test_user)
        user_profile.avatar = get_test_image_file(filename='custom-avatar.png')
        user_profile.save()

        url = avatar_url(self.test_user)
        self.assertIn('custom-avatar', url)
開發者ID:BertrandBordage,項目名稱:wagtail,代碼行數:7,代碼來源:test_templatetags.py

示例4: language_preferences

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:Henk-JanVanHasselaar,項目名稱:wagtail,代碼行數:17,代碼來源:account.py

示例5: test_set_custom_avatar_stores_and_get_custom_avatar

    def test_set_custom_avatar_stores_and_get_custom_avatar(self):
        response = self.client.post(reverse('wagtailadmin_account_change_avatar'),
                                    {'avatar': self.avatar},
                                    follow=True)

        self.assertEqual(response.status_code, 200)

        profile = UserProfile.get_for_user(get_user_model().objects.get(pk=self.user.pk))
        self.assertIn(os.path.basename(self.avatar.name), profile.avatar.url)
開發者ID:Proper-Job,項目名稱:wagtail,代碼行數:9,代碼來源:test_account_management.py

示例6: notification_preferences

def notification_preferences(request):
    if request.method == '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."))
            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:Henk-JanVanHasselaar,項目名稱:wagtail,代碼行數:19,代碼來源:account.py

示例7: test_unset_language_preferences

    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:Henk-JanVanHasselaar,項目名稱:wagtail,代碼行數:14,代碼來源:test_account_management.py

示例8: test_unset_current_time_zone

    def test_unset_current_time_zone(self):
        # Post new values to the current time zone page
        post_data = {
            'current_time_zone': ''
        }
        response = self.client.post(reverse('wagtailadmin_account_current_time_zone'), 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 current time zone are stored
        self.assertEqual(profile.current_time_zone, '')
開發者ID:Proper-Job,項目名稱:wagtail,代碼行數:14,代碼來源:test_account_management.py

示例9: test_user_upload_another_image_removes_previous_one

    def test_user_upload_another_image_removes_previous_one(self):
        response = self.client.post(reverse('wagtailadmin_account_change_avatar'),
                                    {'avatar': self.avatar},
                                    follow=True)
        self.assertEqual(response.status_code, 200)

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

        # Upload a new avatar
        new_response = self.client.post(reverse('wagtailadmin_account_change_avatar'),
                                        {'avatar': self.other_avatar},
                                        follow=True)
        self.assertEqual(new_response.status_code, 200)

        # Check old avatar doesn't exist anymore in filesystem
        with self.assertRaises(FileNotFoundError):
            open(old_avatar_path)
開發者ID:Proper-Job,項目名稱:wagtail,代碼行數:18,代碼來源:test_account_management.py

示例10: test_current_time_zone_view_post

    def test_current_time_zone_view_post(self):
        """
        This posts to the current time zone view and checks that the
        user profile is updated
        """
        # Post new values to the current time zone page
        post_data = {
            'current_time_zone': 'Pacific/Fiji'
        }
        response = self.client.post(reverse('wagtailadmin_account_current_time_zone'), 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 current time zone is stored
        self.assertEqual(profile.current_time_zone, 'Pacific/Fiji')
開發者ID:Proper-Job,項目名稱:wagtail,代碼行數:18,代碼來源:test_account_management.py

示例11: test_notification_preferences_view_post

    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(pk=self.user.pk))

        # Check that the notification preferences are as submitted
        self.assertFalse(profile.submitted_notifications)
        self.assertFalse(profile.approved_notifications)
        self.assertTrue(profile.rejected_notifications)
開發者ID:Henk-JanVanHasselaar,項目名稱:wagtail,代碼行數:22,代碼來源:test_account_management.py

示例12: test_language_preferences_view_post

    def test_language_preferences_view_post(self):
        """
        This posts to the language preferences view and checks that the
        user profile is updated
        """
        # Post new values to the language preferences page
        post_data = {
            'preferred_language': 'es'
        }
        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, 'es')

        # check that the updated language preference is now indicated in HTML header
        response = self.client.get(reverse('wagtailadmin_home'))
        self.assertContains(response, '<html class="no-js" lang="es">')
開發者ID:Proper-Job,項目名稱:wagtail,代碼行數:22,代碼來源:test_account_management.py

示例13: send_notification

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
        include_superusers = getattr(settings, 'WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS', True)
        recipients = users_with_page_permission(revision.page, 'publish', include_superusers)
    elif notification in ['rejected', 'approved']:
        # Get submitter
        recipients = [revision.user]
    else:
        return False

    # 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 True

    # 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
    sent_count = 0
    for recipient in email_recipients:
        try:
            # update context with this recipient
            context["user"] = recipient

            # Translate text to the recipient language settings
            with override(recipient.wagtail_userprofile.get_preferred_language()):
                # 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)
            sent_count += 1
        except Exception:
            logger.exception(
                "Failed to send notification email '%s' to %s",
                email_subject, recipient.email
            )

    return sent_count == len(email_recipients)
開發者ID:BertrandBordage,項目名稱:wagtail,代碼行數:66,代碼來源:utils.py


注:本文中的wagtail.users.models.UserProfile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。