Browse Source

Renamed hooks for more consistency

Peter Justin 6 years ago
parent
commit
510af6ff2d
4 changed files with 24 additions and 14 deletions
  1. 4 4
      docs/development/hooks/forms.rst
  2. 4 2
      flaskbb/forum/forms.py
  3. 4 4
      flaskbb/forum/views.py
  4. 12 4
      flaskbb/plugins/spec.py

+ 4 - 4
docs/development/hooks/forms.rst

@@ -5,9 +5,9 @@
 FlaskBB Form Hooks
 ==================
 
-.. autofunction:: flaskbb_form_new_post_save
-.. autofunction:: flaskbb_form_new_post
-.. autofunction:: flaskbb_form_new_topic
-.. autofunction:: flaskbb_form_new_topic_save
+.. autofunction:: flaskbb_form_post
+.. autofunction:: flaskbb_form_post_save
+.. autofunction:: flaskbb_form_topic
+.. autofunction:: flaskbb_form_topic_save
 .. autofunction:: flaskbb_form_registration
 

+ 4 - 2
flaskbb/forum/forms.py

@@ -36,7 +36,7 @@ class PostForm(FlaskForm):
 
     def save(self, user, topic):
         post = Post(content=self.content.data)
-        current_app.pluggy.hook.flaskbb_form_post_save(form=self)
+        current_app.pluggy.hook.flaskbb_form_post_save(form=self, post=post)
         return post.save(user=user, topic=topic)
 
 
@@ -66,7 +66,9 @@ class ReplyForm(PostForm):
         else:
             user.untrack_topic(topic)
 
-        current_app.pluggy.hook.flaskbb_form_post_save(form=self)
+        current_app.pluggy.hook.flaskbb_form_post_save(
+            form=self, post=self.post
+        )
         return self.post.save(user=user, topic=topic)
 
 

+ 4 - 4
flaskbb/forum/views.py

@@ -285,7 +285,7 @@ class NewTopic(MethodView):
         )
 
     def form(self):
-        current_app.pluggy.hook.flaskbb_form_new_topic(form=NewTopicForm)
+        current_app.pluggy.hook.flaskbb_form_topic(form=NewTopicForm)
         return NewTopicForm()
 
 
@@ -328,7 +328,7 @@ class EditTopic(MethodView):
         )
 
     def form(self, **kwargs):
-        current_app.pluggy.hook.flaskbb_form_new_topic(form=NewTopicForm)
+        current_app.pluggy.hook.flaskbb_form_topic(form=NewTopicForm)
         return EditTopicForm(**kwargs)
 
 
@@ -550,7 +550,7 @@ class NewPost(MethodView):
         return render_template("forum/new_post.html", topic=topic, form=form)
 
     def form(self):
-        current_app.pluggy.hook.flaskbb_form_new_post(form=ReplyForm)
+        current_app.pluggy.hook.flaskbb_form_post(form=ReplyForm)
         return ReplyForm()
 
 
@@ -594,7 +594,7 @@ class EditPost(MethodView):
         )
 
     def form(self, **kwargs):
-        current_app.pluggy.hook.flaskbb_form_new_post(form=ReplyForm)
+        current_app.pluggy.hook.flaskbb_form_post(form=ReplyForm)
         return ReplyForm(**kwargs)
 
 

+ 12 - 4
flaskbb/plugins/spec.py

@@ -486,13 +486,13 @@ def flaskbb_reauth_failed(user):
 
 # Form hooks
 @spec
-def flaskbb_form_new_post(form):
+def flaskbb_form_post(form):
     """Hook for modifying the :class:`~flaskbb.forum.forms.ReplyForm`.
 
     For example::
 
         @impl
-        def flaskbb_form_new_post(form):
+        def flaskbb_form_post(form):
             form.example = TextField("Example Field", validators=[
                 DataRequired(message="This field is required"),
                 Length(min=3, max=50)])
@@ -502,7 +502,7 @@ def flaskbb_form_new_post(form):
 
 
 @spec
-def flaskbb_form_post_save(form):
+def flaskbb_form_post_save(form, post):
     """Hook for modifying the :class:`~flaskbb.forum.forms.ReplyForm`.
 
     This hook is called while populating the post object with
@@ -515,9 +515,17 @@ def flaskbb_form_post_save(form):
 
 
 @spec
-def flaskbb_form_new_topic(form):
+def flaskbb_form_topic(form):
     """Hook for modifying the :class:`~flaskbb.forum.forms.NewTopicForm`
 
+    For example::
+
+        @impl
+        def flaskbb_form_topic(form):
+            form.example = TextField("Example Field", validators=[
+                DataRequired(message="This field is required"),
+                Length(min=3, max=50)])
+
     :param form: The :class:`~flaskbb.forum.forms.NewTopicForm` class.
     """