示例#1
0
def search(request, pattern):
    tags = TagsSet.from_string(pattern)
    q, search = get_search(request)
    regex = r'(\s|\A)\.{}(\W|\Z)'
    for tag in tags:
        q &= Q(content__iregex=regex.format(re.escape(tag)))
    for tag in tags.iter_exclude():
        q &= ~Q(content__iregex=regex.format(re.escape(tag)))
    paginator = Paginator(
        Post.objects.filter(q, active=True).order_by('-created_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(
        request, {
            'page': posts,
            'form': PostForm(),
            'title': '{} - {}'.format(_('tag'), pattern),
            'search': search
        })
    return render_to_response('index.html', context)
示例#2
0
def search(request):
    q, search = get_search(request)
    paginator = Paginator(
        Post.objects.filter(q, active=True).order_by('-created_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(request, {
        'page': posts,
        'form': PostForm(),
        'title': _('search'),
        'search': search
    })
    return render_to_response('index.html', context)
示例#3
0
def search(request):
    q, search = get_search(request)
    paginator = Paginator(Post.objects.filter(q, active=True)
                          .order_by('-created_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(request, {
        'page': posts,
        'form': PostForm(),
        'title': _('search'),
        'search': search
    })
    return render_to_response('index.html', context)
示例#4
0
def search(request, pattern):
    tags = TagsSet.from_string(pattern)
    q, search = get_search(request)
    regex = r'(\s|\A)\.{}(\W|\Z)'
    for tag in tags:
        q &= Q(content__iregex=regex.format(re.escape(tag)))
    for tag in tags.iter_exclude():
        q &= ~Q(content__iregex=regex.format(re.escape(tag)))
    paginator = Paginator(Post.objects.filter(q, active=True)
                          .order_by('-created_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(request, {
        'page': posts,
        'form': PostForm(),
        'title': '{} - {}'.format(_('tag'), pattern),
        'search': search
    })
    return render_to_response('index.html', context)