SHOW:
|
|
- or go back to the newest paste.
| 1 | # If no query is entered, will bring you to blank search screen. Otherwise will pull results from keyword, and results from content and display in search.html | |
| 2 | @login_required(login_url='/auth/login/') | |
| 3 | def search(request): | |
| 4 | query = request.GET.get('q')
| |
| 5 | - | results = [] |
| 5 | + | |
| 6 | - | notecard_list = [] |
| 6 | + | |
| 7 | results = results.filter(Q(notecard_body__icontains=query)|Q(notecard_name__icontains=query)) | |
| 8 | paginator = Paginator(results, 6) | |
| 9 | - | results = results.filter(Q(notecard_body__icontains=query)|Q(notecard_name__icontains=query)) |
| 9 | + | |
| 10 | - | |
| 10 | + | |
| 11 | page = int(request.GET.get('page', '1'))
| |
| 12 | page = min(page, paginator.num_pages) | |
| 13 | page = max(page, 0) | |
| 14 | except ValueError: | |
| 15 | page = 1 | |
| 16 | ||
| 17 | - | notecard_list = paginator.page(page) |
| 17 | + | notecard_list = paginator.page(page) |
| 18 | - | except (EmptyPage, InvalidPage): |
| 18 | + | |
| 19 | - | notecard_list = paginator.page(paginator.num_pages) |
| 19 | + | |
| 20 | queryset = Notecard.objects.filter(section__semester__user=request.user), | |
| 21 | template_name = "notecards/search.html", | |
| 22 | template_object_name = "results", | |
| 23 | extra_context = {"results": results, "notecard_list": notecard_list,},
| |
| 24 | ) |