From d2de96fceb4bef87f24f0eee3da844c4b7fc7811 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Tue, 5 Jun 2018 18:36:44 -0400 Subject: [PATCH] Views and routes for search --- brutaldon/urls.py | 2 ++ brutaldon/views.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/brutaldon/urls.py b/brutaldon/urls.py index f47ccb9..30706ac 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -45,5 +45,7 @@ urlpatterns = [ path('fav/', views.fav, name='fav'), path('boost/', views.boost, name='boost'), path('delete/', views.delete, name='delete'), + path('search', views.search, name='search'), + path('search_results', views.search_results, name='search_results'), path('', views.home), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index 58ecbb3..02af397 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -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)})