30 lines
738 B
Python
30 lines
738 B
Python
|
#!/usr/bin/env python3
|
||
|
"""
|
||
|
/search app views.
|
||
|
"""
|
||
|
from django.shortcuts import render
|
||
|
|
||
|
from quest.models import Quest
|
||
|
from user.models import User
|
||
|
|
||
|
def index(request):
|
||
|
"""The search page index."""
|
||
|
if request.GET:
|
||
|
author = request.GET.get('author')
|
||
|
title = request.GET.get('title')
|
||
|
tags = request.GET.get('tags')
|
||
|
if not any((author, title, tags)):
|
||
|
return
|
||
|
|
||
|
results = Quest.objects.all()
|
||
|
if author:
|
||
|
results = results.filter(
|
||
|
owner__username__unaccent__icontains=author)
|
||
|
if title:
|
||
|
results = results.filter(title__unaccent__icontains=title)
|
||
|
if tags:
|
||
|
results = results.filter(tags__name__in=tags.split())
|
||
|
results = results.distinct()
|
||
|
context = locals()
|
||
|
return render(request, 'search/index.html', context)
|