diff options
author | Andrew Godwin | 2022-11-13 16:14:38 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-13 16:15:14 -0700 |
commit | 34b24a0dcb044cb755e201ad1a83253d0690e78e (patch) | |
tree | 51e6842d9e1392fafcd617cf4de0fa7e28397c87 /activities/views | |
parent | 5a8b6bb3d022a532562ad5fa6d629cfc48c51b46 (diff) | |
download | takahe-34b24a0dcb044cb755e201ad1a83253d0690e78e.tar.gz takahe-34b24a0dcb044cb755e201ad1a83253d0690e78e.tar.bz2 takahe-34b24a0dcb044cb755e201ad1a83253d0690e78e.zip |
More UI!
Diffstat (limited to 'activities/views')
-rw-r--r-- | activities/views/home.py | 42 | ||||
-rw-r--r-- | activities/views/timelines.py | 70 |
2 files changed, 70 insertions, 42 deletions
diff --git a/activities/views/home.py b/activities/views/home.py deleted file mode 100644 index 867856d..0000000 --- a/activities/views/home.py +++ /dev/null @@ -1,42 +0,0 @@ -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(".") diff --git a/activities/views/timelines.py b/activities/views/timelines.py new file mode 100644 index 0000000..76cf018 --- /dev/null +++ b/activities/views/timelines.py @@ -0,0 +1,70 @@ +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, TemplateView + +from activities.models import Post, TimelineEvent +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( + widget=forms.Textarea( + attrs={ + "placeholder": "What's on your mind?", + }, + ) + ) + content_warning = forms.CharField( + required=False, + widget=forms.TextInput( + attrs={ + "placeholder": "Content Warning", + "class": "hidden", + }, + ), + ) + + def get_context_data(self): + context = super().get_context_data() + context["timeline_posts"] = [ + te.subject_post + for te in TimelineEvent.objects.filter( + identity=self.request.identity, + type=TimelineEvent.Types.post, + ) + .select_related("subject_post", "subject_post__author") + .order_by("-created")[:100] + ] + context["current_page"] = "home" + return context + + def form_valid(self, form): + Post.create_local( + author=self.request.identity, + content=linebreaks_filter(form.cleaned_data["text"]), + summary=form.cleaned_data.get("content_warning"), + ) + return redirect(".") + + +@method_decorator(identity_required, name="dispatch") +class Federated(TemplateView): + + template_name = "activities/federated.html" + + def get_context_data(self): + context = super().get_context_data() + context["timeline_posts"] = ( + Post.objects.filter(visibility=Post.Visibilities.public) + .select_related("author") + .order_by("-created")[:100] + ) + context["current_page"] = "federated" + return context |