summaryrefslogtreecommitdiffstats
path: root/activities/views/search.py
blob: 93c001249a449583f9f186ac08d22f45551f0793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django import forms
from django.views.generic import FormView

from activities.search import Searcher


class Search(FormView):

    template_name = "activities/search.html"

    class form_class(forms.Form):
        query = forms.CharField(
            help_text="Search for:\nA user by @username@domain or their profile URL\nA hashtag by #tagname\nA post by its URL",
            widget=forms.TextInput(attrs={"type": "search", "autofocus": "autofocus"}),
        )

    def form_valid(self, form):
        searcher = Searcher(form.cleaned_data["query"], self.request.identity)
        # Render results
        context = self.get_context_data(form=form)
        context["results"] = searcher.search_all()
        return self.render_to_response(context)