]> git.gir.st - subscriptionfeed.git/blob - app/example_plugin/__init__.py
bypass android rate limiting/ipban
[subscriptionfeed.git] / app / example_plugin / __init__.py
1 """
2 This is an example Blueprint to base your plugin off of.
3 to use it, add the blueprint's name (e.g. "example_plugin") in
4 config/config.ini, under the [frontend] section, to the modules key (csv).
5 first-named blueprints take precidence (which allows overwriting existing
6 routes from other blueprints).
7 """
8 from flask import Blueprint, g, url_for
9 from flask_login import current_user
10
11 from ..common.common import *
12
13 frontend = Blueprint(__name__.rpartition('.')[2], __name__)
14
15 @frontend.route('/hello/')
16 @frontend.route('/hello/<name>')
17 def index(name=None):
18 token = getattr(current_user, 'token', 'guest') # 'standard' way to get user info when log-in is not required
19 # assume there's some other /hello/world endpoint to handle this special case:
20 if name == "world":
21 return fallback_route(name)
22 return f"hello, {name or 'you'} from user {token}!" # note: token is usually not a username, but a random string
23
24 @frontend.before_app_request
25 def inject_header_item(): # makes a submodule accessible.
26 if not 'header_items' in g:
27 g.header_items = []
28 g.header_items.append({
29 'name': 'hello', # link text
30 'url': url_for(frontend.name+'.index'), # must use absolute endpoint name!
31 'parent': frontend.name, # required, so it gets printed boldface when blueprint is active
32 'priority': 1, # higher priority, further left.
33 })
Imprint / Impressum