-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathconfiguration.py
37 lines (31 loc) · 1.55 KB
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Configuration of libweasyl.
libweasyl depends on some global state to be set up in order for e.g. database
access to work correctly. This might be nicer if python had a way of
parameterizing modules, but we can't, so this is what we have. It does mean
that only one libweasyl configuration can exist in a running python process.
"""
from libweasyl.models.media import MediaItem
from libweasyl.models.meta import _configure_dbsession
from libweasyl.staff import _init_staff
def configure_libweasyl(
dbsession, base_file_path,
staff_config_dict, media_link_formatter_callback):
"""
Configure libweasyl for the current application. This sets up some
global state around libweasyl.
This function can be called multiple times without issues; each call will
replace the values set by the previous call.
Parameters:
dbsession: A SQLAlchemy ``scoped_session`` instance configured for the
application's database usage.
base_file_path: The path to where static content lives on disk.
staff_config_dict: A dictionary of staff levels and user IDs.
media_link_formatter_callback: A callback to format the URL for a media
link. The callback will be called as ``callback(media_item, link)``
and is expected to return a URL or ``None`` to use the default.
"""
_configure_dbsession(dbsession)
MediaItem._base_file_path = staticmethod(base_file_path)
_init_staff(**staff_config_dict)
MediaItem._media_link_formatter_callback = staticmethod(media_link_formatter_callback)