Coverage for sample_project/settings.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-06-25 10:00 +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 "django.contrib.admin", 

23 "django.contrib.auth", 

24 "django.contrib.contenttypes", 

25 "django.contrib.sessions", 

26 "django.contrib.messages", 

27 "django.contrib.staticfiles", 

28 # ui stuff used by APIS 

29 "crispy_forms", 

30 "crispy_bootstrap4", 

31 "crispy_bootstrap5", 

32 "django_filters", 

33 "django_tables2", 

34 "dal", 

35 "dal_select2", 

36 # REST API 

37 "rest_framework", 

38 # swagger ui generation 

39 "drf_spectacular", 

40 # The APIS apps 

41 "apis_core.generic", 

42 # APIS collections provide a collection model similar to 

43 # SKOS collections and allow tagging of content 

44 "apis_core.collections", 

45 "apis_core.apis_metainfo", 

46 "apis_core.relations", 

47 "apis_core.history", 

48 "apis_core.apis_entities", 

49 # APIS history modules tracks changes of instances over 

50 # time and lets you revert changes 

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

52 # and extend their templates 

53 "apis_core.core", 

54 "apis_core.documentation", 

55] 

56 

57MIDDLEWARE = [ 

58 "django.middleware.security.SecurityMiddleware", 

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

60 "django.middleware.locale.LocaleMiddleware", 

61 "django.middleware.common.CommonMiddleware", 

62 "django.middleware.csrf.CsrfViewMiddleware", 

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

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

65 "django.middleware.clickjacking.XFrameOptionsMiddleware", 

66 "crum.CurrentRequestUserMiddleware", 

67 "simple_history.middleware.HistoryRequestMiddleware", 

68] 

69 

70# ROOT_URLCONF = "apis_core.urls" 

71ROOT_URLCONF = "sample_project.urls" 

72 

73TEMPLATES = [ 

74 { 

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

76 "DIRS": [], 

77 "APP_DIRS": True, 

78 "OPTIONS": { 

79 "context_processors": [ 

80 "django.template.context_processors.debug", 

81 "django.template.context_processors.request", 

82 "django.contrib.auth.context_processors.auth", 

83 "django.contrib.messages.context_processors.messages", 

84 ], 

85 }, 

86 }, 

87] 

88 

89STATIC_URL = "/static/" 

90STATIC_ROOT = "/tmp/staticfiles" 

91 

92DATABASES = { 

93 "default": { 

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

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

96 }, 

97} 

98 

99CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" 

100CRISPY_TEMPLATE_PACK = "bootstrap5" 

101DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html" 

102 

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

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

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

106SPECTACULAR_SETTINGS = { 

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

108} 

109 

110LOGGING = { 

111 "version": 1, 

112 "disable_existing_loggers": False, 

113 "formatters": { 

114 "verbose": { 

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

116 }, 

117 }, 

118 "handlers": { 

119 "console": { 

120 "class": "logging.StreamHandler", 

121 "formatter": "verbose", 

122 }, 

123 }, 

124 "root": { 

125 "handlers": ["console"], 

126 "level": "DEBUG", 

127 }, 

128}