Exemple #1
0
def tag_posts(request, tag_name, by_new=False, page_index=0):
    """
    Display posts were tag found in title or tags field
    """
    source = {
        'title': tag_name,
        'absolute_url': reverse('app_tag', args=[tag_name]),
        'absolute_url_by_new': reverse('app_tag_new', args=[tag_name]),
        'active': 'new' if by_new else 'top'
    }
    posts = Post.tag_posts(tag_name, int(page_index), settings.PAGE_SIZE,
                           by_new, request.app_user)
    try:
        tag = Tag.objects.get(name__iexact=tag_name)
        pin = None if request.app_user.is_anonymous() else Pin.objects.get(
            user=request.app_user, tag=tag)
    except Tag.DoesNotExist:
        tag = {'name': tag_name, 'pin_count': 0}
        pin = None
    except Pin.DoesNotExist:
        pin = None

    top_tags = Tag.top_tags()
    prev_url, next_url = paginated_url(request.resolver_match.url_name, posts,
                                       [tag_name, page_index])

    return render_response(request, 'app/tag.html', locals())
Exemple #2
0
def search(request, by_new=False, page_index=0):
    """
    Search for query text in title and tags fields of post
    """
    q = request.REQUEST.get('q', None)
    if q:        
        channels_q = Channel.objects.filter(title__iexact=q)[:1]
        if channels_q:
            return HttpResponseRedirect(reverse('app_channel', args=[channels_q[0].channel_id]))
        
        tags_q = Tag.objects.filter(name__iexact=q)[:1]
        if tags_q:            
            return HttpResponseRedirect(reverse('app_tag', args=[tags_q[0].name]))
        
        users_q = User.objects.filter(username__iexact=q)[:1]
        if users_q:            
            return HttpResponseRedirect(reverse('app_user', args=[users_q[0].username]))
        
        params = { 'q': q.encode('utf-8')}
        query = '?' + urllib.urlencode(params)
        source = {'title': q,
                  'absolute_url': reverse('app_search') + query,
                  'absolute_url_by_new': reverse('app_search_new') + query,
                  'active': 'new' if by_new else 'top'}
        posts = Post.tag_posts(q, int(page_index), settings.PAGE_SIZE, by_new, request.app_user)
                
        top_tags = Tag.top_tags()
        top_channels = Channel.top_channels()                
        prev_url, next_url = paginated_url(request.resolver_match.url_name, posts, [page_index], params)
                
        return render_response(request, 'app/search.html', locals())
    
    return HttpResponseRedirect(reverse('app_index'))
Exemple #3
0
def search(request, by_new=False, page_index=0):
    """
    Search for query text in title and tags fields of post
    """
    q = request.REQUEST.get('q', None)
    if q:
        channels_q = Channel.objects.filter(title__iexact=q)[:1]
        if channels_q:
            return HttpResponseRedirect(
                reverse('app_channel', args=[channels_q[0].channel_id]))

        tags_q = Tag.objects.filter(name__iexact=q)[:1]
        if tags_q:
            return HttpResponseRedirect(
                reverse('app_tag', args=[tags_q[0].name]))

        users_q = User.objects.filter(username__iexact=q)[:1]
        if users_q:
            return HttpResponseRedirect(
                reverse('app_user', args=[users_q[0].username]))

        params = {'q': q.encode('utf-8')}
        query = '?' + urllib.urlencode(params)
        source = {
            'title': q,
            'absolute_url': reverse('app_search') + query,
            'absolute_url_by_new': reverse('app_search_new') + query,
            'active': 'new' if by_new else 'top'
        }
        posts = Post.tag_posts(q, int(page_index), settings.PAGE_SIZE, by_new,
                               request.app_user)

        top_tags = Tag.top_tags()
        top_channels = Channel.top_channels()
        prev_url, next_url = paginated_url(request.resolver_match.url_name,
                                           posts, [page_index], params)

        return render_response(request, 'app/search.html', locals())

    return HttpResponseRedirect(reverse('app_index'))
Exemple #4
0
def tag_posts(request, tag_name, by_new=False, page_index=0):
    """
    Display posts were tag found in title or tags field
    """    
    source = {'title': tag_name,
              'absolute_url': reverse('app_tag', args=[tag_name]),
              'absolute_url_by_new': reverse('app_tag_new', args=[tag_name]),
              'active': 'new' if by_new else 'top'}
    posts = Post.tag_posts(tag_name, int(page_index), settings.PAGE_SIZE, by_new, request.app_user)
    try:
        tag = Tag.objects.get(name__iexact=tag_name)
        pin = None if request.app_user.is_anonymous() else Pin.objects.get(user=request.app_user, tag=tag) 
    except Tag.DoesNotExist:
        tag = {'name': tag_name, 'pin_count': 0 }
        pin = None
    except Pin.DoesNotExist:
        pin = None
    
    top_tags = Tag.top_tags()
    prev_url, next_url = paginated_url(request.resolver_match.url_name, posts, [tag_name, page_index])
                
    return render_response(request, 'app/tag.html', locals())
Exemple #5
0
 def items(self, channel):
     return [
         post for post in Post.tag_posts(
             channel.title, 0, 50, channel.by_new, channel.request.app_user)
         if post.img_url
     ][:30]
Exemple #6
0
 def items(self, channel):
     return [post for post in Post.tag_posts(channel.title, 0, 50, channel.by_new, channel.request.app_user) if post.img_url][:30]