Example #1
0
def channel_posts(request, channel_id, by_new=False, page_index=0):
    """
    Display posts from particular source like TechCrunch or Engadget
    """
    channel = get_object_or_404(Channel, channel_id=channel_id)
    channel.sync(request.app_user)
    source = {
        'title':
        channel.title,
        'absolute_url':
        channel.get_absolute_url(),
        'absolute_url_by_new':
        reverse('app_channel_new', args=[channel.channel_id]),
        'active':
        'new' if by_new else 'top'
    }
    posts = channel.get_posts(int(page_index), settings.PAGE_SIZE, by_new,
                              request.app_user)
    try:
        subscription = Subscription.objects.get(
            channel=channel, user=request.app_user
        ) if request.app_user.is_authenticated() else None
    except Subscription.DoesNotExist:
        subscription = None

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

    return render_response(request, 'app/channel.html', locals())
Example #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'))
Example #3
0
def index(request, by_new=False, page_index=0):
    """
    Display hot or new posts of all channels and users
    """
    now = datetime.datetime.now()
    page_index = int(page_index)    
    source = {'title': 'All',
              'absolute_url': reverse('app_index'),
              'absolute_url_by_new': reverse('app_index_new'),
              'active': 'new' if by_new else 'top'}
    posts = Post.get_posts(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])
    
    response = render_response(request, 'app/index.html', locals())
        
    return response
Example #4
0
def channel_posts(request, channel_id, by_new=False, page_index=0):
    """
    Display posts from particular source like TechCrunch or Engadget
    """
    channel = get_object_or_404(Channel, channel_id=channel_id)    
    channel.sync(request.app_user)
    source = {'title': channel.title,
              'absolute_url': channel.get_absolute_url(),
              'absolute_url_by_new': reverse('app_channel_new', args=[channel.channel_id]),
              'active': 'new' if by_new else 'top'}
    posts = channel.get_posts(int(page_index), settings.PAGE_SIZE, by_new, request.app_user)
    try:
        subscription = Subscription.objects.get(channel=channel, user=request.app_user) if request.app_user.is_authenticated() else None
    except Subscription.DoesNotExist:
        subscription = None;
        
    prev_url, next_url = paginated_url(request.resolver_match.url_name, posts, [channel_id, page_index])
    top_channels = Channel.top_channels()
    
    return render_response(request, 'app/channel.html', locals())
Example #5
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'))
Example #6
0
def index(request, by_new=False, page_index=0):
    """
    Display hot or new posts of all channels and users
    """
    now = datetime.datetime.now()
    page_index = int(page_index)
    source = {
        'title': 'All',
        'absolute_url': reverse('app_index'),
        'absolute_url_by_new': reverse('app_index_new'),
        'active': 'new' if by_new else 'top'
    }
    posts = Post.get_posts(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])

    response = render_response(request, 'app/index.html', locals())

    return response