Exemplo n.º 1
0
def get_default_context():
    return {'discussed': cached_sets.most_discussed()[:6],
            'category_bestof_fgs': helpers.get_category_bestof_fgs(),
            'mostviewed': cached_sets.most_viewed()[:6],
            'send_to_details': localsettings.FEATURE['send_to_details'],
            'posts': webhelpers.get_latest_fg_blog_posts(),
            }
Exemplo n.º 2
0
def hyperestraier_search(request, enc, q):
    searchphrase = ' AND '.join(q.split())
            
    queryset = []
    extra_context = {'mostviewed': cached_sets.most_viewed()[:6],
                     'q': q,
                     'get_args': "q=%s" % q,
                      'send_to_details': localsettings.FEATURE['send_to_details']}
    he_documents = searcher.search(str(searchphrase))
        
    for he_doc in he_documents:
        if searcher.get_attr(he_doc, '@flowgram_type') == 'flowgram':
            flowgram_id = searcher.get_attr(he_doc, '@flowgram_id')
            matching_flowgram = models.Flowgram.objects.filter(id=flowgram_id)
            matching_flowgram = matching_flowgram.filter(public=True) | \
                                matching_flowgram.filter(owner=request.user)
            if len(matching_flowgram):
                queryset.append(matching_flowgram[0])

    return webhelpers.flowgram_lister(request,
                                      enc='html',
                                      queryset=queryset,
                                      template_name='search/search_results.html',
                                      extra_context=extra_context,
                                      display_mode='list')
Exemplo n.º 3
0
def show_full_newsfeed(request, enc, username):
    user = get_object_or_404(auth_models.User, username=username)
    user_properties = webhelpers.get_user_properties(user, True)
    
    context = webhelpers.translate_user_properties(user_properties)

    favs = models.Favorite.objects.filter(owner=user)
    fav_fgs = [favorite.flowgram for favorite in favs if favorite.flowgram.public][:4]
                
    # Get User profiles items from list of subscriptions
    subscription_profiles = []
    for sub in controller.get_user_subscriptions(user):
        subscription_user = models.UserProfile.objects.get(user=sub["user"])
        avatar_url= models.UserProfile.avatar_100(subscription_user)
        subscription_profiles.append({'username': subscription_user.user,
                                      'avatar_url': avatar_url})

    # Get User profiles items from list of subscribers
    subscriber_profiles = []
    for sub in controller.get_user_subscribers(user):
        subscriber_user = models.UserProfile.objects.get(user=sub["subscriber"])
        avatar_url= models.UserProfile.avatar_100(subscriber_user)
        subscriber_profiles.append({'username':subscriber_user.user,
                                    'avatar_url':avatar_url})
    
    context.update({'u': user,
                    'subs_active': localsettings.FEATURE['subscriptions_fw'],
                    'mostviewed': cached_sets.most_viewed()[:6],
                    'fav_fgs': fav_fgs,
                    'profile_views': user_properties['profile'].views,
                    'subscription_profiles': subscription_profiles,
                    'subscriber_profiles': subscriber_profiles,
                    'newsfeed_display': newsfeed.render(request.user, user, False)})
    
    return helpers.req_render_to_response(request, 'user/show_profile_newsfeed_full.html', context)
Exemplo n.º 4
0
def view_most_viewed(request, enc):
    context = get_default_context()
    context['next'] = '/browse/mostviewed'
    controller.record_stat(request, 'view_browse_most_website', '0', '')
    return webhelpers.flowgram_lister(request,
                                      enc=enc,
                                      queryset=cached_sets.most_viewed(),
                                      template_name='flowgram/view_most_viewed.html',
                                      extra_context=context)
Exemplo n.º 5
0
def view_subscriptions(request):
    u = request.user
    p = u.get_profile() 
                   
    if request.method == 'POST':
        f = NotifyForm(request.POST)
        if f.is_valid():
            cleaned = f.cleaned_data
            p.notification_freq = cleaned['notification_freq']
            p.notify_by_email = cleaned['notify_by_email']
            p.has_public_news_feed = cleaned['has_public_news_feed']
            p.save()
            url = "/subscriptions/"
            add_good_message(request, "Your settings have been successfully updated.")
        return HttpResponseRedirect(url)

    
    initial = {
        'notification_freq': p.notification_freq,
        'notify_by_email': p.notify_by_email,
        'has_public_news_feed': p.has_public_news_feed,
    }
    f = NotifyForm(initial=initial)
    
    # Get User profiles items from list of subscriptions
    user_subscriptions = controller.get_user_subscriptions(u)
    subscription_profiles = []
    for sub in user_subscriptions:
        subscription_user = UserProfile.objects.get(user=sub["user"])
        avatar_url= UserProfile.avatar_100(subscription_user)
        subscription_profiles.append({'username':subscription_user.user,'avatar_url':avatar_url})

    # Get User profiles items from list of subscribers
    subscribers = controller.get_user_subscribers(u)    
    subscriber_profiles = []
    for sub in subscribers:
        subscriber_user = UserProfile.objects.get(user=sub["subscriber"])
        avatar_url= UserProfile.avatar_100(subscriber_user)
        subscriber_profiles.append({'username':subscriber_user.user,'avatar_url':avatar_url})


    # For secondary nav include
    activesecondary = 'subscriptions'

    show_unsubscribe = True
    
    return req_render_to_response(request, 'user/view_subscriptions.html', {
        'subscription_profiles':subscription_profiles,
        'activesecondary': activesecondary,
        'subs_active':subs_active,
        'profile':p,
        'form': f,
        'u':u,
        'show_unsubscribe': show_unsubscribe,
        'subscriber_profiles':subscriber_profiles,
        'mostviewed': cached_sets.most_viewed()[:6],
    })
Exemplo n.º 6
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)
Exemplo n.º 7
0
def admin_newest(request, enc):
    return webhelpers.flowgram_lister(request,
                                      enc='html',
                                      queryset=cached_sets.admin_newest(),
                                      template_name='admin/admin_newest.html',
                                      extra_context={
                                          'mostviewed' : cached_sets.most_viewed()[:6],
                                          'displayAdminTools': True,
                                          'fg_timestamp': True,
                                      })
Exemplo n.º 8
0
def view_featured(request, enc):
    context = {'hero': cached_sets.get_hero(models.feat.FEATURED_PAGE),
               'mostviewed': cached_sets.most_viewed()[:6],
               'category_bestof_fgs': helpers.get_category_bestof_fgs(),
               'next': '/browse/featured',
               'send_to_details': localsettings.FEATURE['send_to_details'],
               'posts': webhelpers.get_latest_fg_blog_posts(),
               }
    controller.record_stat(request, 'view_browse_feat_website', '0', '')
    return webhelpers.flowgram_lister(request,
                                      enc=enc,
                                      queryset=cached_sets.get_featured(models.feat.FEATURED_PAGE),
                                      template_name='flowgram/view_featured.html',
                                      extra_context=context)
Exemplo n.º 9
0
def view_favorites(request, enc, user, sort_criterion, prpusort):
    favs = models.Favorite.objects.filter(owner=user)
    
    controller.record_stat(request,
                           'view_favorites_website',
                           '0',
                           'fave owner user id = ' + str(user.id))
    
    fav_fgs = []
    for favorite in favs:
        flowgram = favorite.flowgram
        is_public_str = 'public' if flowgram.public else 'private'

        if request.user == user:
            if prpusort == 'all' or prpusort == is_public_str:
                fav_fgs.append(flowgram)
        elif flowgram.public:
            fav_fgs.append(flowgram)
    
    (page_owner, active) = (True, 'you') if request.user == user else (False, 'browse')
    
    fav_fgs = helpers.sort_flowgrams(fav_fgs,
                                     helpers.convert_sort_criterion(sort_criterion, '-modified_at'))
    
    extra_context = {
        'u': user,
        'profile': user.get_profile(),
        'fgs': fav_fgs,
        'active': active,
        'subs_active': localsettings.FEATURE['subscriptions_fw'],
        'activesecondary': 'favorites',
        'mostviewed': cached_sets.most_viewed()[:6],
        'pageowner': page_owner,
        'num_favs': len(fav_fgs),
        'sort_criterion': sort_criterion,
        'pub_priv': prpusort,
        'multiple_owners': True,
        'sortable': True,
        'send_to_details': localsettings.FEATURE['send_to_details'],
        'posts': webhelpers.get_latest_fg_blog_posts(),
    }
    
    return webhelpers.flowgram_lister(request,
                                      enc='html',
                                      queryset=fav_fgs,
                                      template_name='flowgram/view_favorites.html',
                                      extra_context=extra_context)
Exemplo n.º 10
0
def show_user(request, enc, user):
    user_properties = webhelpers.get_user_properties(user, True)
    
    profile = user_properties['profile']
    profile.views += 1
    profile.save()
    profile_views = profile.views

    newsfeed_display = newsfeed.render(request.user, user, True)

    context = {
        'u': user,
        'subs_active': localsettings.FEATURE['subscriptions_fw'],
        'send_to_details': localsettings.FEATURE['send_to_details'],
        'activesecondary': 'profile',
        'mostviewed': cached_sets.most_viewed()[:6],
        'profile_views': profile_views,
        'newsfeed_display': newsfeed_display,
        'posts': webhelpers.get_latest_fg_blog_posts(),
    }
    context.update(webhelpers.translate_user_properties(user_properties))

    if user == request.user:
        return helpers.req_render_to_response(request, 'user/show_profile_owner.html', context)
    else:
        favs = models.Favorite.objects.filter(owner=user)
        fav_fgs = [favorite.flowgram for favorite in favs if favorite.flowgram.public][:4]
                
        fgs = models.Flowgram.from_published.filter(owner=user,
                                                    public=True).order_by('-published_at')[:6]
        
        # Checking if user is sub'd to this user.
        is_subscribed = models.Subscription.objects.filter(user=user, subscriber=request.user)
        
        context.update({
            'is_subscribed': is_subscribed,
            'fgs': fgs,
            'active': 'browse',
            'pageowner' : False,
            'display_filters_suppress': True,
            'fg_timestamp': False,
            'fav_fgs': fav_fgs,
            'news_list': newsfeed.get_rendered_news_feed(request.user, user, 'S')
        })
        
        return helpers.req_render_to_response(request, 'user/show_profile.html', context)
Exemplo n.º 11
0
def show_flowgram(request, enc, flowgram):
    can_edit = permissions.can_edit(request.user, flowgram)
    context = {
        'fg': flowgram,
         'can_edit': can_edit,
         'subs_active': localsettings.FEATURE['subscriptions_fw'],
         'show_delete': can_edit,
         'active': 'you' if request.user == flowgram.owner else 'browse',
         'mostviewed': cached_sets.most_viewed()[:6],
         'send_to_details': localsettings.FEATURE['send_to_details']
    }
    context.update(webhelpers.get_flowgram_stats(flowgram))
    controller.record_stat(request, 'view_flowgram_det_website', '0', flowgram.id)
    return helpers.req_render_to_response(
        request,
        'flowgram/show_flowgram.html',
        context)
Exemplo n.º 12
0
def view_ajax_browse(request, enc, browse_type, user):
    stat_string = 'FGs owner user id = ' + (user.username if user else 'None')

    if browse_type == 'featured':
        fg_data_set = [cached_sets.get_hero(models.feat.FEATURED_PAGE)] + \
                          cached_sets.get_featured(models.feat.FEATURED_PAGE)[:11]
        controller.record_stat(request, 'view_browse_feat_ajax_website', '0', '')
    elif browse_type == 'newest':
        fg_data_set = cached_sets.newest()[:12]
        controller.record_stat(request, 'view_browse_feat_new_website', '0', '')
    elif browse_type == 'most_viewed':
        fg_data_set = cached_sets.most_viewed()[:12]
        controller.record_stat(request, 'view_browse_most_ajax_website', '0', '')
    elif browse_type == 'most_discussed':
        fg_data_set = cached_sets.most_discussed()[:12]
        controller.record_stat(request, 'view_browse_disc_ajax_website', '0', '')
    elif browse_type == 'top_rated':
        fg_data_set = cached_sets.top_rated()[:12]
        controller.record_stat(request, 'view_browse_rate_ajax_website', '0', '')
    elif browse_type == 'user_newest':
        fg_data_set = cached_sets.user_newest(user.username)[:6]
        controller.record_stat(request, 'view_browse_new_ajax_website', '0', stat_string)
    elif browse_type == 'user_most_viewed':
        fg_data_set = cached_sets.user_most_viewed(user.username)[:6]
        controller.record_stat(request, 'view_browse_most_ajax_website', '0', stat_string)
    elif browse_type == 'user_most_discussed':
        fg_data_set = cached_sets.user_most_discussed(user.username)[:6]
        controller.record_stat(request, 'view_browse_disc_ajax_website', '0', stat_string)
    elif browse_type == 'user_top_rated':
        fg_data_set = cached_sets.user_top_rated(user.username)[:6]
        controller.record_stat(request, 'view_browse_rate_ajax_website', '0', stat_string)
    elif browse_type == 'user_title':
        fg_data_set = cached_sets.user_title(user.username)[:6]
        controller.record_stat(request, 'view_browse_title_ajax_website', '0', stat_string)
    
    return helpers.req_render_to_response(request,
                                          'includes/modules/flowgram/fg_modules_ajax.incl',
                                          {'fg_data_set': fg_data_set,
                                           'fg_timestamp': request.user == user,
                                           'send_to_details': localsettings.FEATURE['send_to_details'],})
Exemplo n.º 13
0
def get_most_popular_flowgrams():
    return cached_sets.most_viewed()
Exemplo n.º 14
0
def search(request, enc, q):
    controller.record_stat(request, 'view_search_website', '0', '')
    
    if localsettings.FEATURE['use_HEsearch']:
        return hyperestraier_search(request, enc, q)
    
    fgs = models.Flowgram.objects.filter(public=True)
    if request.user.is_authenticated():
        fgs |= models.Flowgram.objects.filter(owner=request.user)
    
    # Using filter with a non-sense id because .none returns an EmptyQueueSet, which causes |= to
    # fail with "TypeError: Cannot merge querysets of different types 'EmptyQuerySet' and
    # 'QuerySet'.".
    by_title = by_tag = by_page_url = by_description = fgs.filter(id='NONSENSE_ID')
    
    extra_context = {'mostviewed': cached_sets.most_viewed()[:6],
                     'q': q,
                     'get_args': "q=%s" % q,
                     'send_to_details': localsettings.FEATURE['send_to_details']}
    
    terms = q.split()
    query_terms = "%%%s%%" % "%".join(terms)
    
    by_title_description = fgs.extra(where=['(title LIKE %s OR description LIKE %s)'],
                                     params=[query_terms, query_terms])
    
    if not len(by_title_description):
        # By title:
        for term in terms:
            by_this_title = fgs.filter(title__icontains=term)
            by_title |= by_this_title
        
        # By description:
        for term in terms:
            by_this_description = fgs.filter(description__icontains=term)
            by_description |= by_this_description
            
        by_title_description = by_title | by_description
    
        # By tag:
        for term in terms:
            tags = models.Tag.objects.filter(name=term)
            by_this_tag = fgs.filter(id__in=[tag.flowgram.id for tag in tags])
            by_tag |= by_this_tag
        
    search_results = (by_tag | by_page_url | by_title_description).order_by('-created_at')

    # Check if author exists
    if len(terms) == 1:
        try:
            auth_models.User.objects.get(username=terms[0])
            by_username = True
        except auth_models.User.DoesNotExist:
            by_username = False
        extra_context['by_username'] = by_username

    return webhelpers.flowgram_lister(request,
                                      enc='html',
                                      queryset=search_results,
                                      template_name='search/search_results.html',
                                      extra_context=extra_context,
                                      display_mode='list')