summaryrefslogtreecommitdiffstats
path: root/statuses/views/home.py
blob: b9b98d2e95102ae37225fea21c9285e766bc5832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from django import forms
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.views.generic import FormView

from core.forms import FormHelper
from statuses.models import Status
from users.decorators import identity_required


@method_decorator(identity_required, name="dispatch")
class Home(FormView):

    template_name = "statuses/home.html"

    class form_class(forms.Form):
        text = forms.CharField()

        helper = FormHelper(submit_text="Post")

    def get_context_data(self):
        context = super().get_context_data()
        context.update(
            {
                "statuses": self.request.identity.statuses.all()[:100],
            }
        )
        return context

    def form_valid(self, form):
        Status.create_local(
            identity=self.request.identity,
            text=form.cleaned_data["text"],
        )
        return redirect(".")