From 495e955378d62dc439c4c210785e5d401bc77f64 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 16 Nov 2022 06:53:39 -0700 Subject: Tag and visibility handling --- activities/views/posts.py | 49 ++++++++++++++++++++++++++++++++++++++++--- activities/views/timelines.py | 11 ++++------ 2 files changed, 50 insertions(+), 10 deletions(-) (limited to 'activities/views') diff --git a/activities/views/posts.py b/activities/views/posts.py index ece7cf3..3ee35cc 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -1,13 +1,15 @@ +from django import forms from django.shortcuts import get_object_or_404, redirect, render +from django.template.defaultfilters import linebreaks_filter from django.utils.decorators import method_decorator -from django.views.generic import TemplateView, View +from django.views.generic import FormView, TemplateView, View -from activities.models import PostInteraction, PostInteractionStates +from activities.models import Post, PostInteraction, PostInteractionStates from users.decorators import identity_required from users.shortcuts import by_handle_or_404 -class Post(TemplateView): +class Individual(TemplateView): template_name = "activities/post.html" @@ -100,3 +102,44 @@ class Boost(View): }, ) return redirect(post.urls.view) + + +@method_decorator(identity_required, name="dispatch") +class Compose(FormView): + + template_name = "activities/compose.html" + + class form_class(forms.Form): + text = forms.CharField( + widget=forms.Textarea( + attrs={ + "placeholder": "What's on your mind?", + }, + ) + ) + visibility = forms.ChoiceField( + choices=[ + (Post.Visibilities.public, "Public"), + (Post.Visibilities.unlisted, "Unlisted"), + (Post.Visibilities.followers, "Followers & Mentioned Only"), + (Post.Visibilities.mentioned, "Mentioned Only"), + ], + ) + content_warning = forms.CharField( + required=False, + widget=forms.TextInput( + attrs={ + "placeholder": "Content Warning", + }, + ), + help_text="Optional - Post will be hidden behind this text until clicked", + ) + + 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"), + visibility=form.cleaned_data["visibility"], + ) + return redirect("/") diff --git a/activities/views/timelines.py b/activities/views/timelines.py index c59c3b6..45a0c30 100644 --- a/activities/views/timelines.py +++ b/activities/views/timelines.py @@ -95,12 +95,9 @@ class Notifications(TemplateView): def get_context_data(self): context = super().get_context_data() - context["events"] = ( - TimelineEvent.objects.filter( - identity=self.request.identity, - ) - .exclude(type__in=[TimelineEvent.Types.post, TimelineEvent.Types.boost]) - .select_related("subject_post", "subject_post__author", "subject_identity") - ) + context["events"] = TimelineEvent.objects.filter( + identity=self.request.identity, + type__in=[TimelineEvent.Types.mentioned, TimelineEvent.Types.boosted], + ).select_related("subject_post", "subject_post__author", "subject_identity") context["current_page"] = "notifications" return context -- cgit v1.2.3