Coverage for sample_project/settings.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-22 07:51 +0000

1import os 

2 

3from django.core.management.utils import get_random_secret_key 

4 

5SECRET_KEY = os.environ.get("SECRET_KEY", get_random_secret_key()) 

6DEBUG = True 

7 

8# we look for values in the environment and fallback to the 

9# Django defaults if there are none set 

10env_ah = os.environ.get("DJANGO_ALLOWED_HOSTS", "").split(",") 

11ALLOWED_HOSTS = list(filter(None, env_ah)) 

12env_csrf = os.environ.get("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",") 

13CSRF_TRUSTED_ORIGINS = list(filter(None, env_csrf)) 

14 

15 

16# Application definition 

17 

18INSTALLED_APPS = [ 

19 # our main app, containing the ontology (in the `models.py`) 

20 # and our customizations 

21 "sample_project", 

22 # `apis_override_select2js` is a workaround for APIS' 

23 # handling of autocomplete forms. It should be listed 

24 # at the beginning of the list, to make sure the 

25 # files shipped with it are served in precedence. 

26 "apis_override_select2js", 

27 "django.contrib.admin", 

28 "django.contrib.auth", 

29 "django.contrib.contenttypes", 

30 "django.contrib.sessions", 

31 "django.contrib.messages", 

32 "django.contrib.staticfiles", 

33 # ui stuff used by APIS 

34 "crispy_forms", 

35 "crispy_bootstrap4", 

36 "django_filters", 

37 "django_tables2", 

38 "dal", 

39 "dal_select2", 

40 # REST API 

41 "rest_framework", 

42 # swagger ui generation 

43 "drf_spectacular", 

44 # The APIS apps 

45 "apis_core.relations", 

46 "apis_core.apis_metainfo", 

47 "apis_core.apis_relations", 

48 "apis_core.apis_entities", 

49 # apis_vocabularies is deprecated, but there are 

50 # still migrations depending on it - it will be dropped 

51 # at some point 

52 "apis_core.apis_vocabularies", 

53 # APIS collections provide a collection model similar to 

54 # SKOS collections and allow tagging of content 

55 "apis_core.collections", 

56 # APIS history modules tracks changes of instances over 

57 # time and lets you revert changes 

58 "apis_core.history", 

59 # The core APIS apps come last, so other apps can override 

60 # and extend their templates 

61 "apis_core.generic", 

62 "apis_core.core", 

63 "apis_core.documentation", 

64] 

65 

66MIDDLEWARE = [ 

67 "django.middleware.security.SecurityMiddleware", 

68 "django.contrib.sessions.middleware.SessionMiddleware", 

69 "django.middleware.common.CommonMiddleware", 

70 "django.middleware.csrf.CsrfViewMiddleware", 

71 "django.contrib.auth.middleware.AuthenticationMiddleware", 

72 "django.contrib.messages.middleware.MessageMiddleware", 

73 "django.middleware.clickjacking.XFrameOptionsMiddleware", 

74 "crum.CurrentRequestUserMiddleware", 

75] 

76 

77# ROOT_URLCONF = "apis_core.urls" 

78ROOT_URLCONF = "sample_project.urls" 

79 

80TEMPLATES = [ 

81 { 

82 "BACKEND": "django.template.backends.django.DjangoTemplates", 

83 "DIRS": [], 

84 "APP_DIRS": True, 

85 "OPTIONS": { 

86 "context_processors": [ 

87 "django.template.context_processors.debug", 

88 "django.template.context_processors.request", 

89 "django.contrib.auth.context_processors.auth", 

90 "django.contrib.messages.context_processors.messages", 

91 ], 

92 }, 

93 }, 

94] 

95 

96STATIC_URL = "/static/" 

97STATIC_ROOT = "/tmp/staticfiles" 

98 

99DATABASES = { 

100 "default": { 

101 "ENGINE": "django.db.backends.sqlite3", 

102 "NAME": "/tmp/db.sqlite3", 

103 }, 

104} 

105 

106CRISPY_TEMPLATE_PACK = "bootstrap4" 

107DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap4.html" 

108 

109# for django spectacular to be able to generate the schema, we have to use its view inspector 

110REST_FRAMEWORK = {"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema"} 

111# we use our custom schema generator to make it pick up our custom routes 

112SPECTACULAR_SETTINGS = { 

113 "DEFAULT_GENERATOR_CLASS": "apis_core.generic.generators.CustomSchemaGenerator" 

114} 

115 

116LOGGING = { 

117 "version": 1, 

118 "disable_existing_loggers": False, 

119 "formatters": { 

120 "verbose": { 

121 "format": "%(asctime)s %(name)-6s %(levelname)-8s %(message)s", 

122 }, 

123 }, 

124 "handlers": { 

125 "console": { 

126 "class": "logging.StreamHandler", 

127 "formatter": "verbose", 

128 }, 

129 }, 

130 "root": { 

131 "handlers": ["console"], 

132 "level": "DEBUG", 

133 }, 

134}