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


Python utils.get_user_profile函数代码示例

本文整理汇总了Python中userena.utils.get_user_profile函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_profile函数的具体用法?Python get_user_profile怎么用?Python get_user_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: check_permissions

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':
                model_obj = get_profile_model()
            else:
                model_obj = get_user_model()

            model_content_type = ContentType.objects.get_for_model(model_obj)

            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)

        # it is safe to rely on settings.ANONYMOUS_USER_ID since it is a
        # requirement of django-guardian
        for user in get_user_model().objects.exclude(id=settings.ANONYMOUS_USER_ID):
            try:
                user_profile = get_user_profile(user=user)
            except ObjectDoesNotExist:
                warnings.append(_("No profile found for %(username)s") \
                                % {'username': user.username})
            else:
                all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                for model, perms in ASSIGNED_PERMISSIONS.items():
                    if model == 'profile':
                        perm_object = get_user_profile(user=user)
                    else:
                        perm_object = user

                    for perm in perms:
                        if perm[0] not in all_permissions:
                            assign_perm(perm[0], user, perm_object)
                            changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
开发者ID:openslack,项目名称:openslack-web,代码行数:54,代码来源:managers.py

示例2: test_activation_valid

    def test_activation_valid(self):
        """
        Valid activation of an user.

        Activation of an user with a valid ``activation_key`` should activate
        the user and set a new invalid ``activation_key`` that is defined in
        the setting ``USERENA_ACTIVATED``.

        """
        user = UserenaSignup.objects.create_user(**self.user_info)
        active_user = UserenaSignup.objects.activate_user(user.userena_signup.activation_key)
        profile = get_user_profile(user=active_user)

        # The returned user should be the same as the one just created.
        self.failUnlessEqual(user, active_user)

        # The user should now be active.
        self.failUnless(active_user.is_active)

        # The user should have permission to view and change its profile
        self.failUnless('view_profile' in get_perms(active_user, profile))
        self.failUnless('change_profile' in get_perms(active_user, profile))

        # The activation key should be the same as in the settings
        self.assertEqual(active_user.userena_signup.activation_key,
                         userena_settings.USERENA_ACTIVATED)
开发者ID:DjangoBD,项目名称:django-userena,代码行数:26,代码来源:tests_managers.py

示例3: test_create_inactive_user

    def test_create_inactive_user(self):
        """
        Test the creation of a new user.

        ``UserenaSignup.create_inactive_user`` should create a new user that is
        not active. The user should get an ``activation_key`` that is used to
        set the user as active.

        Every user also has a profile, so this method should create an empty
        profile.

        """
        # Check that the fields are set.
        new_user = UserenaSignup.objects.create_user(**self.user_info)
        self.assertEqual(new_user.username, self.user_info['username'])
        self.assertEqual(new_user.email, self.user_info['email'])
        self.failUnless(new_user.check_password(self.user_info['password']))

        # User should be inactive
        self.failIf(new_user.is_active)

        # User has a valid SHA1 activation key
        self.failUnless(re.match('^[a-f0-9]{40}$', new_user.userena_signup.activation_key))

        # User now has an profile.
        self.failUnless(get_user_profile(user=new_user))

        # User should be saved
        self.failUnlessEqual(User.objects.filter(email=self.user_info['email']).count(), 1)
开发者ID:DjangoBD,项目名称:django-userena,代码行数:29,代码来源:tests_managers.py

示例4: profile_detail

def profile_detail(request, username):
    user = get_object_or_404(User, username=username)
    profile = get_user_profile(user)
    context = {
        'profile': profile,
    }
    return render(request, 'accounts/detail.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:7,代码来源:views.py

示例5: profile_detail

def profile_detail(request, username,
    template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
    extra_context=None, **kwargs):
    """
    Detailed view of an user.

    :param username:
        String of the username of which the profile should be viewed.

    :param template_name:
        String representing the template name that should be used to display
        the profile.

    :param extra_context:
        Dictionary of variables which should be supplied to the template. The
        ``profile`` key is always the current profile.

    **Context**

    ``profile``
        Instance of the currently viewed ``Profile``.

    """
    user = get_object_or_404(get_user_model(), username__iexact=username)
    profile = get_user_profile(user=user)
    if not profile.can_view_profile(request.user):
        raise PermissionDenied
    if not extra_context: extra_context = dict()
    extra_context['profile'] = profile
    extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
    return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:Rsgm,项目名称:django-userena,代码行数:32,代码来源:views.py

示例6: profile_detail_extended

def profile_detail_extended(request, username, edit_profile_form=EditProfileForm, template_name='userena/profile_detail_extended.html', success_url=None,extra_context=None, **kwargs):
	user = get_object_or_404(get_user_model(), username__iexact=username)
	profile = get_user_profile(user=user)
	if not extra_context: extra_context = dict()
	extra_context['profile'] = profile
	extra_context['profExpData'] = Profile_Experience.objects.filter(profile = profile)
	extra_context['projExpData'] = Project_Experience.objects.filter(profile = profile)
	extra_context['awardsData'] = Awards.objects.filter(profile = profile)
	return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
开发者ID:aramais,项目名称:phoenixcs,代码行数:9,代码来源:views.py

示例7: favourite

def favourite(request, username):
    user = get_object_or_404(User, username=username)
    profile = get_user_profile(user)

    presenter_list = user.my_profile.follows.order_by('-presenterdetail__showing', '-presenterdetail__audience_count');
    context = {
        'profile': profile,
        'presenter_list': presenter_list,
    }
    return render(request, 'accounts/favourite.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:10,代码来源:views.py

示例8: get_queryset

    def get_queryset(self):

        logging.error(get_user_profile(self.request.user).__dict__)
        profile_model = get_profile_model()
        logging.error(profile_model.__dict__)
        logging.error(profile_model.objects.all())
        logging.error(profile_model.__doc__)
##        logging.error(self.__dict__)
##        logging.error(self.request.__dict__)
        queryset = profile_model.objects.get_visible_profiles(self.request.user).select_related()
        return queryset
开发者ID:behappyyoung,项目名称:pythonprojectm,代码行数:11,代码来源:views.py

示例9: process_request

    def process_request(self, request):
        lang_cookie = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
        if not lang_cookie:
            if request.user.is_authenticated():
                try:
                    profile = get_user_profile(user=request.user)
                except (ObjectDoesNotExist, SiteProfileNotAvailable):
                    profile = False

                if profile:
                    try:
                        lang = getattr(profile, userena_settings.USERENA_LANGUAGE_FIELD)
                        translation.activate(lang)
                        request.LANGUAGE_CODE = translation.get_language()
                    except AttributeError: pass
开发者ID:itmation,项目名称:django-userena,代码行数:15,代码来源:middleware.py

示例10: test_preference_user

    def test_preference_user(self):
        """ Test the language preference of two users """
        users = ((1, 'nl'),
                 (2, 'en'))

        for pk, lang in users:
            user = User.objects.get(pk=pk)
            profile = get_user_profile(user=user)

            req = self._get_request_with_user(user)

            # Check that the user has this preference
            self.assertEqual(profile.language, lang)

            # Request should have a ``LANGUAGE_CODE`` with dutch
            UserenaLocaleMiddleware().process_request(req)
            self.assertEqual(req.LANGUAGE_CODE, lang)
开发者ID:AmmsA,项目名称:django-userena,代码行数:17,代码来源:tests_middleware.py

示例11: create_user

    def create_user(self, username, email, password, active=False,
                    send_email=True):
        """
        A simple wrapper that creates a new :class:`User`.

        :param username:
            String containing the username of the new user.

        :param email:
            String containing the email address of the new user.

        :param password:
            String containing the password for the new user.

        :param active:
            Boolean that defines if the user requires activation by clicking
            on a link in an e-mail. Defaults to ``False``.

        :param send_email:
            Boolean that defines if the user should be sent an email. You could
            set this to ``False`` when you want to create a user in your own
            code, but don't want the user to activate through email.

        :return: :class:`User` instance representing the new user.

        """

        new_user = get_user_model().objects.create_user(
            username, email, password)
        new_user.is_active = active
        new_user.save()

        # Give permissions to view and change profile
        for perm in ASSIGNED_PERMISSIONS['profile']:
            assign_perm(perm[0], new_user, get_user_profile(user=new_user))

        # Give permissions to view and change itself
        for perm in ASSIGNED_PERMISSIONS['user']:
            assign_perm(perm[0], new_user, new_user)

        userena_profile = self.create_userena_profile(new_user)

        if send_email:
            userena_profile.send_activation_email()

        return new_user
开发者ID:DjangoBD,项目名称:django-userena,代码行数:46,代码来源:managers.py

示例12: test_profile_edit_view_success

    def test_profile_edit_view_success(self):
        """ A ``POST`` to the edit view """
        self.client.login(username='john', password='blowfish')
        new_about_me = 'I hate it when people use my name for testing.'
        response = self.client.post(reverse('userena_profile_edit',
                                            kwargs={'username': 'john'}),
                                    data={'about_me': new_about_me,
                                          'privacy': 'open',
                                          'language': 'en'})

        # A valid post should redirect to the detail page.
        self.assertRedirects(response, reverse('userena_profile_detail',
                                               kwargs={'username': 'john'}))

        # Users hould be changed now.
        profile = get_user_profile(user=User.objects.get(username='john'))
        self.assertEqual(profile.about_me, new_about_me)
开发者ID:bioinformatics-ua,项目名称:django-userena,代码行数:17,代码来源:tests_views.py

示例13: test_upload_mugshot

    def test_upload_mugshot(self):
        """
        Test the uploaded path of mugshots

        TODO: What if a image get's uploaded with no extension?

        """
        user = User.objects.get(pk=1)
        filename = 'my_avatar.png'
        path = upload_to_mugshot(get_user_profile(user=user), filename)

        # Path should be changed from the original
        self.failIfEqual(filename, path)

        # Check if the correct path is returned
        MUGSHOT_RE = re.compile('^%(mugshot_path)s[a-f0-9]{10}.png$' %
                                {'mugshot_path': userena_settings.USERENA_MUGSHOT_PATH})

        self.failUnless(MUGSHOT_RE.search(path))
开发者ID:chuan137,项目名称:yunda,代码行数:19,代码来源:tests_models.py

示例14: profile_edit

def profile_edit(request, username):
    user = get_object_or_404(User, username=username)
    profile = get_user_profile(user)

    if request.method == 'POST':
        print request.POST
        form = EditProfileForm(request.POST, request.FILES)
        if form.is_valid():
            mugshot = form.cleaned_data['mugshot']
            if mugshot:
                profile.mugshot = form.cleaned_data['mugshot']
                profile.save()
    else:
        form = EditProfileForm()

    context = {
        'profile': profile,
        'form': form,
    }
    return render(request, 'accounts/edit.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:20,代码来源:views.py

示例15: direct_to_user_template

def direct_to_user_template(request, username, template_name,
                            extra_context=None):
    """
    Simple wrapper for Django's :func:`direct_to_template` view.

    This view is used when you want to show a template to a specific user. A
    wrapper for :func:`direct_to_template` where the template also has access to
    the user that is found with ``username``. For ex. used after signup,
    activation and confirmation of a new e-mail.

    :param username:
        String defining the username of the user that made the action.

    :param template_name:
        String defining the name of the template to use. Defaults to
        ``userena/signup_complete.html``.

    **Keyword arguments**

    ``extra_context``
        A dictionary containing extra variables that should be passed to the
        rendered template. The ``account`` key is always the ``User``
        that completed the action.

    **Extra context**

    ``viewed_user``
        The currently :class:`User` that is viewed.

    """
    user = get_object_or_404(get_user_model(), username__iexact=username)

    if not extra_context: extra_context = dict()
    extra_context['viewed_user'] = user
    extra_context['request'] = request
    extra_context['profile'] = get_user_profile(user=user)

    return ExtraContextTemplateView.as_view(template_name=template_name,
                                            extra_context=extra_context)(request)
开发者ID:bioinformatics-ua,项目名称:django-userena,代码行数:39,代码来源:views.py


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