Browse Source

Add some more hooks

Peter Justin 7 years ago
parent
commit
8507dd823c

+ 3 - 4
flaskbb/app.py

@@ -30,7 +30,6 @@ from flaskbb.extensions import (alembic, allows, babel, cache, celery, csrf,
                                 redis_store, themes, whooshee)
                                 redis_store, themes, whooshee)
 from flaskbb.forum.views import forum
 from flaskbb.forum.views import forum
 from flaskbb.management.views import management
 from flaskbb.management.views import management
-from flaskbb.message.views import message
 from flaskbb.plugins import spec
 from flaskbb.plugins import spec
 from flaskbb.plugins.manager import FlaskBBPluginManager
 from flaskbb.plugins.manager import FlaskBBPluginManager
 from flaskbb.plugins.models import PluginRegistry
 from flaskbb.plugins.models import PluginRegistry
@@ -162,9 +161,6 @@ def configure_blueprints(app):
     app.register_blueprint(
     app.register_blueprint(
         management, url_prefix=app.config["ADMIN_URL_PREFIX"]
         management, url_prefix=app.config["ADMIN_URL_PREFIX"]
     )
     )
-    app.register_blueprint(
-        message, url_prefix=app.config["MESSAGE_URL_PREFIX"]
-    )
 
 
     app.pluggy.hook.flaskbb_load_blueprints(app=app)
     app.pluggy.hook.flaskbb_load_blueprints(app=app)
 
 
@@ -221,6 +217,9 @@ def configure_extensions(app):
         """Loads the user. Required by the `login` extension."""
         """Loads the user. Required by the `login` extension."""
 
 
         user_instance = User.query.filter_by(id=user_id).first()
         user_instance = User.query.filter_by(id=user_id).first()
+
+        app.pluggy.hook.flaskbb_current_user_loader(user=user_instance)
+
         if user_instance:
         if user_instance:
             return user_instance
             return user_instance
         else:
         else:

+ 46 - 0
flaskbb/plugins/spec.py

@@ -63,6 +63,15 @@ def flaskbb_cli(cli):
     """Hook for registering CLI commands."""
     """Hook for registering CLI commands."""
 
 
 
 
+@spec
+def flaskbb_current_user_loader(user):
+    """This hook is emitted after querying the database for
+    the current_user by the Flask-Login extension.
+
+    :param user: The user instance.
+    """
+
+
 # Template Hooks
 # Template Hooks
 
 
 @spec
 @spec
@@ -134,6 +143,7 @@ def flaskbb_tpl_after_user_details_form():
     in :file:`templates/user/change_user_details.html`.
     in :file:`templates/user/change_user_details.html`.
     """
     """
 
 
+
 @spec
 @spec
 def flaskbb_tpl_profile_settings_menu():
 def flaskbb_tpl_profile_settings_menu():
     """This hook is emitted on the user settings page in order to populate the
     """This hook is emitted on the user settings page in order to populate the
@@ -162,3 +172,39 @@ def flaskbb_tpl_profile_settings_menu():
 
 
     in :file:`templates/user/settings_layout.html`
     in :file:`templates/user/settings_layout.html`
     """
     """
+
+
+@spec
+def flaskbb_tpl_profile_sidebar_stats(user):
+    """This hook is emitted on the users profile page below the standard
+    information. For example, it can be used to add additional items
+    such as a link to the profile.
+
+    in :file:`templates/user/profile_layout.html`
+
+    :param user: The user object for whom the profile is currently visited.
+    """
+
+
+@spec
+def flaskbb_tpl_before_post_author_info(user, post):
+    """This hook is emitted before the information about the
+    author of a post is displayed (but after the username).
+
+    in :file:`templates/forum/topic.html`
+
+    :param user: The user object of the post's author.
+    :param post: The post object.
+    """
+
+
+@spec
+def flaskbb_tpl_after_post_author_info(user, post):
+    """This hook is emitted after the information about the
+    author of a post is displayed (but after the username).
+
+    in :file:`templates/forum/topic.html`
+
+    :param user: The user object of the post's author.
+    :param post: The post object.
+    """

+ 3 - 8
flaskbb/templates/forum/topic.html

@@ -43,21 +43,16 @@
                     {% endif %}
                     {% endif %}
                     <div class="author-title"><h5>{{ user.primary_group.name }}</h5></div>
                     <div class="author-title"><h5>{{ user.primary_group.name }}</h5></div>
 
 
+                    {{ run_hook("flaskbb_tpl_before_post_author_info", user=user, post=post) }}
+
                     {% if user.avatar %}
                     {% if user.avatar %}
                         <div class="author-avatar"><img src="{{ user.avatar }}" alt="avatar"></div>
                         <div class="author-avatar"><img src="{{ user.avatar }}" alt="avatar"></div>
                     {% endif %}
                     {% endif %}
 
 
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-registered">{% trans %}Joined{% endtrans %}: {{ user.date_joined|format_date('%b %d %Y') }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
                     <div class="author-posts">{% trans %}Posts{% endtrans %}: {{ user.post_count }}</div>
-                    <div class="author-pm">
-                        {% if current_user.is_authenticated and post.user_id %}
-                        <a href="{{ url_for('message.new_conversation') }}?to_user={{ user.username }}">{% trans %}Message{% endtrans %}</a>
-                        {% endif %}
-                    </div>
 
 
-                    {% if user.website %}
+                    {{ run_hook("flaskbb_tpl_after_post_author_info", user=user, post=post) }}
-                    <div class="author-website"><a href="{{ user.website }}" rel="nofollow">{% trans %}Website{% endtrans %}</a></div>
-                    {% endif %}
 
 
                     {% else %}
                     {% else %}
                     <!-- user deleted or guest -->
                     <!-- user deleted or guest -->

+ 1 - 7
flaskbb/templates/user/profile_layout.html

@@ -41,13 +41,7 @@
                                 {{ user.date_joined|format_date('%b %d %Y') }}
                                 {{ user.date_joined|format_date('%b %d %Y') }}
                             </div>
                             </div>
 
 
-                            <div class="profile-buttons">
+                            {{ run_hook("flaskbb_tpl_profile_sidebar_stats", user=user) }}
-                                {% if current_user.is_authenticated %}
-                                <a class="btn btn-primary" href="{{url_for('message.new_conversation') }}?to_user={{ user.username }}">
-                                    {% trans %}Message{% endtrans %}
-                                </a>
-                                {% endif %}
-                            </div>
                         </div>
                         </div>
 
 
                         {% block profile_navigation %}
                         {% block profile_navigation %}