This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/activities/views/search.py

23 lines
760 B
Python
Raw Normal View History

2022-11-17 18:52:00 -07:00
from django import forms
from django.views.generic import FormView
2022-12-11 11:22:06 -07:00
from activities.search import Searcher
2022-11-17 18:52:00 -07:00
class Search(FormView):
template_name = "activities/search.html"
class form_class(forms.Form):
2022-11-28 23:41:36 -05:00
query = forms.CharField(
2022-12-04 21:13:33 -07:00
help_text="Search for:\nA user by @username@domain or their profile URL\nA hashtag by #tagname\nA post by its URL",
2022-12-03 21:47:09 -05:00
widget=forms.TextInput(attrs={"type": "search", "autofocus": "autofocus"}),
2022-11-28 23:41:36 -05:00
)
2022-11-28 23:41:36 -05:00
def form_valid(self, form):
2022-12-11 11:22:06 -07:00
searcher = Searcher(form.cleaned_data["query"], self.request.identity)
2022-11-17 18:52:00 -07:00
# Render results
context = self.get_context_data(form=form)
2022-12-11 11:22:06 -07:00
context["results"] = searcher.search_all()
2022-11-17 18:52:00 -07:00
return self.render_to_response(context)