示例#1
0
def get_user_properties(user, should_delete_blank_flowgrams=False):
    profile = user.get_profile()
    profile_complete = sum([bool(profile.gender),
                            bool(profile.homepage),
                            bool(profile.description)]) == 3
    
    badges = {'teamFg': 'TeamFG' if user.is_staff else ''}
    
    flowgrams = models.Flowgram.objects.filter(owner=user)
    if should_delete_blank_flowgrams:
        helpers.delete_blank_flowgrams(flowgrams)
    
    total_num_views = sum([flowgram.views for flowgram in flowgrams])
    badges['views'] = helpers.get_badge_view_level(total_num_views)

    num_public_flowgrams = flowgrams.filter(public=True).count()
    num_unlisted_flowgrams = flowgrams.count() - num_public_flowgrams
    num_times_flowgrams_favorited = models.Favorite.objects.filter(flowgram__in=flowgrams).count()

    return {
        'profile': profile,
        'profile_complete': profile_complete,
        'badges': badges,
        'flowgrams': flowgrams,
        'total_num_views': total_num_views,
        'num_public_flowgrams': num_public_flowgrams,
        'num_unlisted_flowgrams': num_unlisted_flowgrams,
        'num_times_flowgrams_favorited': num_times_flowgrams_favorited
    }
示例#2
0
def view_your_flowgrams_thumb(request, enc, user, sort_criterion, prpusort, page):
    controller.record_stat(request, 'view_browse_userFGs_website', '0',
                               'FGs owner user id = ' + str(user.id))

    users_flowgrams = models.Flowgram.objects.filter(owner=user)

    fgs = {}

    page_owner = request.user == user
    if page_owner:
        active = 'you'
        activesecondary = 'viewall'

        if prpusort == 'private':
            fgs = users_flowgrams.filter(public=False)
        elif prpusort == 'public':
            fgs = users_flowgrams.filter(public=True)
        else:
            fgs = users_flowgrams

        fgs = fgs.order_by(helpers.convert_sort_criterion(sort_criterion, '-modified_at'))
    else:
        #TODO(cyap) figure out multiple views on this for owner/non-owners
        active = 'browse'
        activesecondary = 'viewalluser'

        fgs = users_flowgrams.filter(public=True)\
                  .order_by(helpers.convert_sort_criterion(sort_criterion, '-modified_at'))

    helpers.delete_blank_flowgrams(fgs)
        
    args = {'template_name': 'flowgram/view_your_flowgrams_thumb.html',
            'template_object_name': 'flowgram',
            'paginate_by': 14, 
            'allow_empty': True,
            'page': page,
            'extra_context': {
                'user': request.user,
                'u': user,
                'profile': user.get_profile(),
                'active': active,
                'subs_active': localsettings.FEATURE['subscriptions_fw'],
                'activesecondary': activesecondary,
                'pageowner': page_owner,
                'mostviewed': cached_sets.most_viewed()[:6],
                'display_mode': request.COOKIES.get('flowgram_results_filter_type', 'grid'),
                'num_favs': len(models.Favorite.objects.filter(owner=user)),
                'sort_criterion': sort_criterion,
                'pub_priv': prpusort,
                'multiple_owners': False,
                'sortable': True,
                'send_to_details': localsettings.FEATURE['send_to_details'],
                'posts': webhelpers.get_latest_fg_blog_posts(),
                },
            'queryset': fgs}
    return object_list(request, **args)