]>
git.gir.st - subscriptionfeed.git/blob - app/__init__.py
4 from flask
import Flask
6 from . common
. common
import *
7 from . common
. user
import init_login
10 app
. secret_key
= base64
. b64decode ( cf
[ 'frontend' ]. get ( 'secret_key' , '' )) or \
11 secrets
. token_bytes ( 16 ) # development fallback; CSRF/cookies won't persist.
14 for name
in cf
[ 'frontend' ][ 'modules' ]. split ( ',' ):
15 blueprint
= importlib
. import_module ( '.' + name
, __name__
)
16 app
. register_blueprint ( blueprint
. frontend
)
18 # TODO: move this somewhere else
19 @app . template_global ()
20 def querystring_page ( fields
):
21 tmp
= dict ( request
. args
)
22 for field
, what
in fields
. items ():
23 if type ( what
) is tuple :
24 ( plusminus
, default
) = what
25 tmp
[ field
] = int ( tmp
. get ( field
) or str ( default
)) + plusminus
26 elif type ( what
) is type ( None ):
27 if field
in tmp
: del tmp
[ field
]
30 from werkzeug
. urls
import url_encode
31 return url_encode ( tmp
)
33 # TODO: should this go somewhere else?
34 # This error handler logs requests to external apis, and POST data. this makes debugging of api responses easier, as the request can be reconstructed and replayed.
35 from flask
import g
, request
36 from werkzeug
. exceptions
import InternalServerError
37 @app . errorhandler ( InternalServerError
)
39 if request
. method
== "POST" :
40 app
. logger
. error ( request
. data
)
41 if 'api_requests' in g
:
42 app
. logger
. error ( g
. api_requests
)
45 from . common
import anticsrf