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/home.py

43 lines
1.2 KiB
Python
Raw Normal View History

2022-11-05 21:17:27 +01:00
from django import forms
from django.shortcuts import redirect
2022-11-12 06:02:43 +01:00
from django.template.defaultfilters import linebreaks_filter
2022-11-05 21:17:27 +01:00
from django.utils.decorators import method_decorator
from django.views.generic import FormView
2022-11-12 06:02:43 +01:00
from activities.models import Post, TimelineEvent
2022-11-05 21:17:27 +01:00
from core.forms import FormHelper
from users.decorators import identity_required
@method_decorator(identity_required, name="dispatch")
class Home(FormView):
2022-11-12 06:02:43 +01:00
template_name = "activities/home.html"
2022-11-05 21:17:27 +01:00
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(
{
2022-11-12 06:02:43 +01:00
"timeline_posts": [
te.subject_post
for te in TimelineEvent.objects.filter(
identity=self.request.identity,
type=TimelineEvent.Types.post,
).order_by("-created")[:100]
],
2022-11-05 21:17:27 +01:00
}
)
return context
def form_valid(self, form):
2022-11-12 06:02:43 +01:00
Post.create_local(
author=self.request.identity,
content=linebreaks_filter(form.cleaned_data["text"]),
2022-11-05 21:17:27 +01:00
)
return redirect(".")