Exemplo n.º 1
0
 def get_object(self, request, by_new=False):
     self.request = request
     channel = Channel(channel_id=0,
                       title='Latest Feed' if by_new else 'Top Feed')
     channel.request = request
     channel.by_new = by_new
     return channel
Exemplo n.º 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'))
Exemplo n.º 3
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())
Exemplo n.º 4
0
def bootstrip(request):
    """
    Setting basic context variables
    """
    user_messages = None
    new_messages = None
    last_message_id = None
    signup_form = None
    followings = None
    
    if request.app_user.is_authenticated():
        tags = request.app_user.get_tags()
        channels = request.app_user.get_channels()
        user_messages = request.app_user.get_messages()
        followings = request.app_user.get_followings()
        new_messages = len([msg for msg in user_messages if msg.viewed_on == None])
        last_message_id = max(user_messages, key=lambda msg: msg.message_id).message_id if len(user_messages) else None
    else:
        tags = Tag.get_tags()
        channels = Channel.get_channels()
        signup_form = SignUp()
        
    return {
            'app_user': request.app_user,
            'tags': tags,
            'channels': channels,
            'user_messages': user_messages,
            'new_messages': new_messages,
            'last_message_id': last_message_id,
            'followings': followings,            
            'signup_form': signup_form,
            'utc_now': datetime.datetime.now(),
            'STATIC_CONTENT_VERSION': settings.STATIC_CONTENT_VERSION
            }
Exemplo n.º 5
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
Exemplo n.º 6
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())
Exemplo n.º 7
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'))
Exemplo n.º 8
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
Exemplo n.º 9
0
 def get_object(self, request, tag_name, by_new=False):
     channel = Channel(channel_id=0, title=tag_name)
     channel.request = request
     channel.by_new = by_new
     return channel
Exemplo n.º 10
0
 def get_object(self, request, by_new=False):
     self.request =request
     channel = Channel(channel_id=0, title='Latest Feed' if by_new else 'Top Feed')
     channel.request = request
     channel.by_new = by_new
     return channel
Exemplo n.º 11
0
 def get_object(self, request, tag_name, by_new=False):
     channel = Channel(channel_id=0, title= tag_name)
     channel.request = request
     channel.by_new = by_new
     return channel