Beispiel #1
0
def search(request):
    '''Render a search feed.

    Authentication is not required but is used if set.

    Search operates on a 'search' paramater in the GET dict that works the same
    way the FriendFeed search works (who:everyone would search the public feed).
    ''' 
    if not 'q' in request.GET:
        initial = {}
        if request.session.get('nickname', None):
            initial['q'] = 'friends:%s' % request.session['nickname']
        extra_context = {
            'form': SearchForm(initial=initial),
        }
        return render_to_response('search_form.html', extra_context, context_instance=RequestContext(request))
    else:
        form = SearchForm(request.GET)
        if not form.is_valid():
            extra_context = {
                'form': form,
            }
            return render_to_response('search_form.html', extra_context, context_instance=RequestContext(request))
    if request.session.get('nickname', None):
        f = friendfeed.FriendFeed(request.session['nickname'],
            request.session['key'])
    else:
        f = friendfeed.FriendFeed()
    start = max(get_integer_argument(request, 'start', 0), 0)
    num = get_integer_argument(request, 'num', NUM)
    q = form.data['q']
    data = f.search(q, **request_to_feed_args_dict(request))
    if 'errorCode' in data:
        return error(request, data)
    entries = [entry for entry in data['entries'] if not entry['hidden']]
    hidden = [entry for entry in data['entries'] if entry['hidden']]
    extra_context = {
        'entries': entries,
        'hidden': hidden,
        'next': start + num,
        'title': q,
        'form': form,
    }
    if start > 0:
        extra_context['has_previous'] = True
        extra_context['previous'] = max(start - num, 0)
    if request.GET.get('output', 'html') == 'atom':
        return atom(entries)
    return render_to_response('search.html', extra_context, context_instance=RequestContext(request))
Beispiel #2
0
def search(request):
    '''Render a search feed.

    Authentication is not required but is used if set.

    Search operates on a 'search' paramater in the GET dict that works the same
    way the FriendFeed search works (who:everyone would search the public feed).
    ''' 
    from fftogo.forms import SearchForm
    if not 'search' in request.GET:
        extra_context = {
            'form': SearchForm(),
        }
        return render_to_response('search_form.html', extra_context, context_instance=RequestContext(request))
    else:
        form = SearchForm(request.GET)
        if not form.is_valid():
            extra_context = {
                'form': form,
            }
            return render_to_response('search_form.html', extra_context, context_instance=RequestContext(request))
    if request.session.get('nickname', None):
        f = friendfeed.FriendFeed(request.session['nickname'],
            request.session['key'])
    else:
        f = friendfeed.FriendFeed()
    try:
        start = int(request.GET.get('start', 0))
    except:
        start = 0
    service = request.GET.get('service', None)
    num = int(request.session.get('num', NUM))
    search = form.data['search']
    try:
        data = f.search(search, num=num, start=start, service=service)
    except Exception, e:
        if e[0] == 401:
            del request.session['nickname']
            del request.session['key']
        return HttpResponseRedirect(reverse(str(e)))
Beispiel #3
0
def search(request):
    """Render a search feed.

    Authentication is not required but is used if set.

    Search operates on a 'search' paramater in the GET dict that works the same
    way the FriendFeed search works (who:everyone would search the public feed).
    """
    if not "q" in request.GET:
        initial = {}
        if request.session.get("nickname", None):
            initial["q"] = "friends:%s" % request.session["nickname"]
        extra_context = {"form": SearchForm(initial=initial)}
        return render_to_response("search_form.html", extra_context, context_instance=RequestContext(request))
    else:
        form = SearchForm(request.GET)
        if not form.is_valid():
            extra_context = {"form": form}
            return render_to_response("search_form.html", extra_context, context_instance=RequestContext(request))
    if request.session.get("nickname", None):
        f = friendfeed.FriendFeed(request.session["nickname"], request.session["key"])
    else:
        f = friendfeed.FriendFeed()
    start = max(get_integer_argument(request, "start", 0), 0)
    num = get_integer_argument(request, "num", NUM)
    q = form.data["q"]
    data = f.search(q, **request_to_feed_args_dict(request))
    if "errorCode" in data:
        return error(request, data)
    entries = [entry for entry in data["entries"] if not entry["hidden"]]
    hidden = [entry for entry in data["entries"] if entry["hidden"]]
    extra_context = {"entries": entries, "hidden": hidden, "next": start + num, "title": q, "form": form}
    if start > 0:
        extra_context["has_previous"] = True
        extra_context["previous"] = max(start - num, 0)
    if request.GET.get("output", "html") == "atom":
        return atom(entries)
    return render_to_response("search.html", extra_context, context_instance=RequestContext(request))