Exemple #1
0
def user_profile(username):
    user = get_object_or_404(User.objects.select_related('userinfo', 'userinfo__avatar'), username=username)

    if not user.is_active:
        raise Http404("Deactivated user.")

    follow_counts = following_models.counts(user)

    return {
        'user': user.details(),
        'bio': user.userinfo.bio_text,
        'quest_completion_count': Quest.completed_by_user_count(user),
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],
    }
def user_profile(username):
    user = get_object_or_404(User.objects.select_related(
        'userinfo', 'userinfo__avatar'),
                             username=username)

    if not user.is_active:
        raise Http404("Deactivated user.")

    follow_counts = following_models.counts(user)

    ret = {
        'user': user.details(),
        'bio': user.userinfo.bio_text,
        'quest_completion_count': Quest.completed_by_user_count(user),
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],
    }

    if not user.kv.web_profile_privacy.get():
        ret['web_profile_url'] = 'https://{}/{}'.format(
            settings.DOMAIN, user.username)

    for service, attr in [('facebook', 'fb_uid'), ('twitter', 'screen_name')]:
        try:
            privacy_kv = lambda: getattr(user.kv, '{}_privacy'.format(service))
            service_user = getattr(user, '{}user'.format(service))
            private = privacy_kv().get()

            # Migrate users from before this feature was added.
            if private is None:
                privacy_kv().set(False)
                private = False

            if not private:
                ret['{}_url'.format(service)] = 'https://{}.com/{}'.format(
                    service, getattr(service_user, attr))
        except (
                FacebookUser.DoesNotExist,
                TwitterUser.DoesNotExist,
        ):
            pass

    return ret
def user_profile(username):
    user = get_object_or_404(User.objects.select_related('userinfo', 'userinfo__avatar'), username=username)

    if not user.is_active:
        raise Http404("Deactivated user.")

    follow_counts = following_models.counts(user)

    ret = {
        'user': user.details(),
        'bio': user.userinfo.bio_text,
        'quest_completion_count': Quest.completed_by_user_count(user),
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],
    }

    if not user.kv.web_profile_privacy.get():
        ret['web_profile_url'] = 'https://{}/{}'.format(settings.DOMAIN, user.username)

    for service, attr in [('facebook', 'fb_uid'), ('twitter', 'screen_name')]:
        try:
            privacy_kv = lambda: getattr(user.kv, '{}_privacy'.format(service))
            service_user = getattr(user, '{}user'.format(service))
            private = privacy_kv().get()

            # Migrate users from before this feature was added.
            if private is None:
                privacy_kv().set(False)
                private = False

            if not private:
                ret['{}_url'.format(service)] = 'https://{}.com/{}'.format(service, getattr(service_user, attr))
        except (FacebookUser.DoesNotExist, TwitterUser.DoesNotExist,):
            pass

    return ret