From 0851fbd1ec09b142608667bf90ee806e59cafb28 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Thu, 17 Nov 2022 18:52:00 -0700 Subject: Add search and better notifications --- activities/views/posts.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activities/views/posts.py') diff --git a/activities/views/posts.py b/activities/views/posts.py index 7b93e42..14da9ca 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -5,6 +5,7 @@ from django.utils.decorators import method_decorator from django.views.generic import FormView, TemplateView, View from activities.models import Post, PostInteraction, PostInteractionStates +from core.models import Config from users.decorators import identity_required from users.shortcuts import by_handle_or_404 @@ -112,6 +113,7 @@ class Compose(FormView): template_name = "activities/compose.html" class form_class(forms.Form): + text = forms.CharField( widget=forms.Textarea( attrs={ @@ -137,6 +139,22 @@ class Compose(FormView): help_text="Optional - Post will be hidden behind this text until clicked", ) + def clean_text(self): + text = self.cleaned_data.get("text") + if not text: + return text + length = len(text) + if length > Config.system.post_length: + raise forms.ValidationError( + f"Maximum post length is {Config.system.post_length} characters (you have {length})" + ) + return text + + def get_form_class(self): + form = super().get_form_class() + form.declared_fields["text"] + return form + def form_valid(self, form): Post.create_local( author=self.request.identity, -- cgit v1.2.3