| |
@@ -381,6 +381,43 @@
|
| |
|
| |
Destroy your database, rebuild it, and re-run the app. Your widget should show up.
|
| |
|
| |
+ Widget-specific views
|
| |
+ ---------------------
|
| |
+ A widget may also register additional routes by using the
|
| |
+ ``hubs.widgets.base.widget_route`` decorator. There are some differences from
|
| |
+ the usual ``route`` decorator or the ``add_url_rule`` function:
|
| |
+
|
| |
+ - The view function will be passed the database ``session`` and ``widget``
|
| |
+ instances as first arguments, and then the URL kwargs.
|
| |
+ - The endpoint will be prefixed with ``<widget_name>_``, for example
|
| |
+ ``meetings_``. Remember that when you want to reverse the URL with
|
| |
+ ``url_for``.
|
| |
+ - When reversing the URL, you need to pass the ``hub`` and ``idx`` kwargs.
|
| |
+
|
| |
+ Example: consider this additional method that needs to be exported as a view
|
| |
+ in the ``meetings`` plugin::
|
| |
+
|
| |
+ from hubs.widgets.base import widget_route
|
| |
+ @widget_route(rule="search/<requester>/", methods=["GET", "POST"])
|
| |
+ def search(session, widget, requester):
|
| |
+ # Do something, probably using the "requester" variable.
|
| |
+ return flask.jsonify({"hope_sources": ["Obi-Wan Kenobi"]})
|
| |
+
|
| |
+ Then, a valid call to ``url_for`` to reverse this URL would look like::
|
| |
+
|
| |
+ url_for("meetings_search", hub=widget.hub.name, idx=widget.idx, requester="Leia")
|
| |
+
|
| |
+ Behind the scenes, the ``widget_route`` decorator adds a ``ROUTES`` global
|
| |
+ variable in the widget module, that contains dictionaries representing the
|
| |
+ arguments passed to Flask's `add_url_rule
|
| |
+ <http://flask.pocoo.org/docs/latest/api/#flask.Flask.add_url_rule>`_ function.
|
| |
+
|
| |
+ If you want more control, you can edit this ``ROUTES`` list directly, but there
|
| |
+ are a difference from the basic ``add_url_rule`` function: the view function
|
| |
+ name must be given with the dict key ``view_func_name``, and not ``view_func``
|
| |
+ as in the ``add_url_rule`` function.
|
| |
+
|
| |
+
|
| |
A proposal, client-side templates
|
| |
=================================
|
| |
|
| |
This commit adds a way for plugins to declare their own routes to Flask, should they need additional endpoints.