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-18 02:52:00 +01:00
from django import forms
from django.views.generic import FormView
2022-12-11 19:22:06 +01:00
from activities.search import Searcher
2022-11-18 02:52:00 +01:00
class Search(FormView):
template_name = "activities/search.html"
class form_class(forms.Form):
2022-11-29 05:41:36 +01:00
query = forms.CharField(
2022-12-05 05:13:33 +01: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-04 03:47:09 +01:00
widget=forms.TextInput(attrs={"type": "search", "autofocus": "autofocus"}),
2022-11-29 05:41:36 +01:00
)
2022-11-29 05:41:36 +01:00
def form_valid(self, form):
2022-12-11 19:22:06 +01:00
searcher = Searcher(form.cleaned_data["query"], self.request.identity)
2022-11-18 02:52:00 +01:00
# Render results
context = self.get_context_data(form=form)
2022-12-11 19:22:06 +01:00
context["results"] = searcher.search_all()
2022-11-18 02:52:00 +01:00
return self.render_to_response(context)