-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconf.py
75 lines (58 loc) · 2.82 KB
/
conf.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Custom Django settings for django-user-tasks.
"""
from datetime import timedelta
from django.conf import settings as django_settings
from django.core.files.storage import storages
from user_tasks import filters
def get_storage(import_path=None):
"""
Get the default storage backend or for the given import path.
"""
return storages["default"] if import_path is None else storages[import_path]
class LazySettings():
"""
The behavior of ``django-user-tasks`` can be customized via the following Django settings.
"""
@property
def USER_TASKS_ARTIFACT_FILTERS(self): # pylint: disable=invalid-name
"""
Tuple containing zero or more filters for UserTaskArtifact listing REST API calls.
Each entry should be a Django REST Framework filter backend class
object, such as ``django_filters.rest_framework.DjangoFilterBackend``.
The default value contains only ``user_tasks.filters.ArtifactFilterBackend``,
which allows superusers to see all artifacts but other users to see only
those for artifacts they triggered themselves.
"""
return getattr(django_settings, 'USER_TASKS_STATUS_FILTERS', (filters.ArtifactFilterBackend,))
@property
def USER_TASKS_ARTIFACT_STORAGE(self): # pylint: disable=invalid-name
"""
File storage backend to use for :py:attr:`user_tasks.models.UserTaskStatus.file`.
If explicitly set, the setting should be the import path of a storage
backend class.
"""
import_path = getattr(django_settings, 'USER_TASKS_ARTIFACT_STORAGE', None)
return get_storage(import_path)
@property
def USER_TASKS_MAX_AGE(self): # pylint: disable=invalid-name
"""
``timedelta`` reflecting the age after which UserTaskStatus records should be deleted.
For this setting to be useful, ``user_tasks.tasks.purge_old_user_tasks``
should be configured to run on an appropriate schedule. Note that the
age is calculated from task creation, not completion. The default
value is 30 days.
"""
return getattr(django_settings, 'USER_TASKS_MAX_AGE', timedelta(days=30))
@property
def USER_TASKS_STATUS_FILTERS(self):
"""
Tuple containing zero or more filters for UserTaskStatus listing REST API calls.
Each entry should be a Django REST Framework filter backend class
object, such as ``django_filters.rest_framework.DjangoFilterBackend``.
The default value contains only ``user_tasks.filters.StatusFilterBackend``,
which allows superusers to see all task statuses but other users to see only
those for tasks they triggered themselves.
"""
return getattr(django_settings, 'USER_TASKS_STATUS_FILTERS', (filters.StatusFilterBackend,))
settings = LazySettings()