コード例 #1
0
ファイル: views.py プロジェクト: Heldroe/pyverts-2011
def profile_detail_likes(request, username, public_profile_field=None,
                   template_name='profiles/profile_detail_likes.html',
                   extra_context=None):
    user = get_object_or_404(User, username=username)
    try:
        profile_obj = user.get_profile()
    except ObjectDoesNotExist:
        raise Http404
    if public_profile_field is not None and \
       not getattr(profile_obj, public_profile_field):
        profile_obj = None
    
    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    my_profile = False
    if request.user.is_authenticated():
        my_profile = (request.user == user)
    
    interests = []
    userinterests = UserInterests.objects.filter(user=user)
    for userinterest in userinterests:
        interests.append(userinterest.interest)

    scoresby = get_score_by_category(user)
    scoresby_sorted = sorted(scoresby.iteritems(), key=operator.itemgetter(1))
    scoresby_sorted.reverse()

    return render_to_response(template_name,
                              { 'profile': profile_obj,
                                'profilepage': True,
                                'my_profile': my_profile,
                                'achievements_score': get_user_score(user),
                                'interests': interests,
                                'last_interests': interests,
                                'scores_by_category': scoresby_sorted},
                              context_instance=context)
コード例 #2
0
ファイル: views.py プロジェクト: Heldroe/pyverts-2011
def profile_detail(request, username, public_profile_field=None,
                   template_name='profiles/profile_detail.html',
                   extra_context=None):
    """
    Detail view of a user's profile.
    
    If no profile model has been specified in the
    ``AUTH_PROFILE_MODULE`` setting,
    ``django.contrib.auth.models.SiteProfileNotAvailable`` will be
    raised.
    
    If the user has not yet created a profile, ``Http404`` will be
    raised.
    
    **Required arguments:**
    
    ``username``
        The username of the user whose profile is being displayed.
    
    **Optional arguments:**

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``public_profile_field``
        The name of a ``BooleanField`` on the profile model; if the
        value of that field on the user's profile is ``False``, the
        ``profile`` variable in the template will be ``None``. Use
        this feature to allow users to mark their profiles as not
        being publicly viewable.
        
        If this argument is not specified, it will be assumed that all
        users' profiles are publicly viewable.
    
    ``template_name``
        The name of the template to use for displaying the profile. If
        not specified, this will default to
        :template:`profiles/profile_detail.html`.
    
    **Context:**
    
    ``profile``
        The user's profile, or ``None`` if the user's profile is not
        publicly viewable (see the description of
        ``public_profile_field`` above).
    
    **Template:**
    
    ``template_name`` keyword argument or
    :template:`profiles/profile_detail.html`.
    
    """
    user = get_object_or_404(User, username=username)
    try:
        profile_obj = user.get_profile()
    except ObjectDoesNotExist:
        raise Http404
    if public_profile_field is not None and \
       not getattr(profile_obj, public_profile_field):
        profile_obj = None
    
    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    my_profile = False
    if request.user.is_authenticated():
        my_profile = (request.user == user)
    
    interests = []
    userinterests = UserInterests.objects.filter(user=user)
    for userinterest in userinterests:
        interests.append(userinterest.interest)

    scoresby = get_score_by_category(user)
    scoresby_sorted = sorted(scoresby.iteritems(), key=operator.itemgetter(1))
    scoresby_sorted.reverse()

    return render_to_response(template_name,
                              { 'profile': profile_obj,
                                'profilepage': True,
                                'my_profile': my_profile,
                                'achievements_score': get_user_score(user),
                                'interests': interests,
                                'last_interests': interests[:20],
                                'scores_by_category': scoresby_sorted},
                              context_instance=context)
コード例 #3
0
def show_score_for(user, request, *args, **kwargs):
    if user.is_authenticated():
        return get_user_score(user)
    elif request.user.is_authenticated():
        return get_user_score(request.user)
    return ''