Guest User

Untitled

a guest
May 1st, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = []
  6.     notecard_list = []
  7.     results = Notecard.objects.filter(section__semester__user=request.user)
  8.     if query:
  9.       results = results.filter(Q(notecard_body__icontains=query)|Q(notecard_name__icontains=query))
  10.  
  11.     paginator = Paginator(results, 6)
  12.     try:
  13.         page = int(request.GET.get('page', '1'))
  14.     except ValueError:
  15.         page = 1
  16.     try:
  17.         notecard_list = paginator.page(page)
  18.     except (EmptyPage, InvalidPage):
  19.         notecard_list = paginator.page(paginator.num_pages)
  20.     return list_detail.object_list(
  21.         request,
  22.         queryset = Notecard.objects.filter(section__semester__user=request.user),
  23.         template_name = "notecards/search.html",
  24.         template_object_name = "results",
  25.         extra_context = {"results": results, "notecard_list": notecard_list,},
  26.     )
Advertisement
Add Comment
Please, Sign In to add comment