Views and routes for search

This commit is contained in:
Jason McBrayer 2018-06-05 18:36:44 -04:00
parent e05601db22
commit d2de96fceb
2 changed files with 20 additions and 0 deletions

View File

@ -45,5 +45,7 @@ urlpatterns = [
path('fav/<int:id>', views.fav, name='fav'),
path('boost/<int:id>', views.boost, name='boost'),
path('delete/<int:id>', views.delete, name='delete'),
path('search', views.search, name='search'),
path('search_results', views.search_results, name='search_results'),
path('', views.home),
]

View File

@ -418,6 +418,24 @@ def delete(request, id):
{"toot": toot, 'confirm_page': True,
"fullbrutalism": fullbrutalism_p(request)})
def search(request):
return render(request, 'search.html',
{"fullbrutalism": fullbrutalism_p(request)})
def search_results(request):
if request.method == 'GET':
query = request.GET.get('q', '')
elif request.method == 'POST':
query = request.POST.get('q', '')
else:
query = ''
mastodon = get_mastodon(request)
results = mastodon.search(query)
return render(request, 'search_results.html',
{"results": results,
"fullbrutalism": fullbrutalism_p(request)})
def about(request):
return render(request, 'about.html',
{"fullbrutalism": fullbrutalism_p(request)})