summaryrefslogtreecommitdiffstats
path: root/activities/views/posts.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-17 18:52:00 -0700
committerAndrew Godwin2022-11-17 15:10:09 -0700
commit0851fbd1ec09b142608667bf90ee806e59cafb28 (patch)
treeeb4bfa7e52ef0a66460840747ea83b7685e1a5e8 /activities/views/posts.py
parent2154e6f02252576d8652e66f26fa4ae635d0f8ee (diff)
downloadtakahe-0851fbd1ec09b142608667bf90ee806e59cafb28.tar.gz
takahe-0851fbd1ec09b142608667bf90ee806e59cafb28.tar.bz2
takahe-0851fbd1ec09b142608667bf90ee806e59cafb28.zip
Add search and better notifications
Diffstat (limited to 'activities/views/posts.py')
-rw-r--r--activities/views/posts.py18
1 files changed, 18 insertions, 0 deletions
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,