diff options
author | Andrew Godwin | 2022-11-11 22:02:43 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-11 22:02:43 -0700 |
commit | feb5d9b74fa1e8454eaaf29afae3643c6d7c81f1 (patch) | |
tree | 3889a826dfc2c852aa4873daff2a27cb7c1a2b01 /activities/views | |
parent | fbfad9fbf5e061cb7c658dada3c4014c9796021c (diff) | |
download | takahe-feb5d9b74fa1e8454eaaf29afae3643c6d7c81f1.tar.gz takahe-feb5d9b74fa1e8454eaaf29afae3643c6d7c81f1.tar.bz2 takahe-feb5d9b74fa1e8454eaaf29afae3643c6d7c81f1.zip |
Got up to incoming posts working
Diffstat (limited to 'activities/views')
-rw-r--r-- | activities/views/__init__.py | 0 | ||||
-rw-r--r-- | activities/views/home.py | 42 |
2 files changed, 42 insertions, 0 deletions
diff --git a/activities/views/__init__.py b/activities/views/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/activities/views/__init__.py diff --git a/activities/views/home.py b/activities/views/home.py new file mode 100644 index 0000000..867856d --- /dev/null +++ b/activities/views/home.py @@ -0,0 +1,42 @@ +from django import forms +from django.shortcuts import redirect +from django.template.defaultfilters import linebreaks_filter +from django.utils.decorators import method_decorator +from django.views.generic import FormView + +from activities.models import Post, TimelineEvent +from core.forms import FormHelper +from users.decorators import identity_required + + +@method_decorator(identity_required, name="dispatch") +class Home(FormView): + + template_name = "activities/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( + { + "timeline_posts": [ + te.subject_post + for te in TimelineEvent.objects.filter( + identity=self.request.identity, + type=TimelineEvent.Types.post, + ).order_by("-created")[:100] + ], + } + ) + return context + + def form_valid(self, form): + Post.create_local( + author=self.request.identity, + content=linebreaks_filter(form.cleaned_data["text"]), + ) + return redirect(".") |