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