settings.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. __package__ = 'archivebox.core'
  2. import os
  3. import sys
  4. import inspect
  5. from pathlib import Path
  6. from django.utils.crypto import get_random_string
  7. import abx
  8. import archivebox
  9. from archivebox.config import DATA_DIR, PACKAGE_DIR, ARCHIVE_DIR, CONSTANTS # noqa
  10. from archivebox.config.common import SHELL_CONFIG, SERVER_CONFIG # noqa
  11. IS_MIGRATING = 'makemigrations' in sys.argv[:3] or 'migrate' in sys.argv[:3]
  12. IS_TESTING = 'test' in sys.argv[:3] or 'PYTEST_CURRENT_TEST' in os.environ
  13. IS_SHELL = 'shell' in sys.argv[:3] or 'shell_plus' in sys.argv[:3]
  14. IS_GETTING_VERSION_OR_HELP = 'version' in sys.argv or 'help' in sys.argv or '--version' in sys.argv or '--help' in sys.argv
  15. ################################################################################
  16. ### ArchiveBox Plugin Settings
  17. ################################################################################
  18. ALL_PLUGINS = archivebox.ALL_PLUGINS
  19. LOADED_PLUGINS = archivebox.LOADED_PLUGINS
  20. ################################################################################
  21. ### Django Core Settings
  22. ################################################################################
  23. WSGI_APPLICATION = 'core.wsgi.application'
  24. ASGI_APPLICATION = "core.asgi.application"
  25. ROOT_URLCONF = 'core.urls'
  26. LOGIN_URL = '/accounts/login/'
  27. LOGOUT_REDIRECT_URL = os.environ.get('LOGOUT_REDIRECT_URL', '/')
  28. PASSWORD_RESET_URL = '/accounts/password_reset/'
  29. APPEND_SLASH = True
  30. DEBUG = SHELL_CONFIG.DEBUG or ('--debug' in sys.argv)
  31. INSTALLED_APPS = [
  32. 'daphne',
  33. # Django default apps
  34. 'django.contrib.auth',
  35. 'django.contrib.contenttypes',
  36. 'django.contrib.sessions',
  37. 'django.contrib.messages',
  38. 'django.contrib.staticfiles',
  39. 'django.contrib.admin',
  40. # 3rd-party apps from PyPI
  41. 'django_jsonform', # handles rendering Pydantic models to Django HTML widgets/forms https://github.com/bhch/django-jsonform
  42. 'signal_webhooks', # handles REST API outbound webhooks https://github.com/MrThearMan/django-signal-webhooks
  43. 'django_object_actions', # provides easy Django Admin action buttons on change views https://github.com/crccheck/django-object-actions
  44. # Our ArchiveBox-provided apps
  45. # 'abid_utils', # handles ABID ID creation, handling, and models
  46. 'config', # ArchiveBox config settings (loaded as a plugin, don't need to add it here)
  47. 'machine', # handles collecting and storing information about the host machine, network interfaces, installed binaries, etc.
  48. 'actors', # handles starting and managing background workers and processes (orchestrators and actors)
  49. 'queues', # handles starting and managing background workers and processes (supervisord)
  50. 'seeds', # handles Seed model and URL source management
  51. 'crawls', # handles Crawl and CrawlSchedule models and management
  52. 'personas', # handles Persona and session management
  53. 'core', # core django model with Snapshot, ArchiveResult, etc.
  54. 'api', # Django-Ninja-based Rest API interfaces, config, APIToken model, etc.
  55. # ArchiveBox plugins
  56. *abx.as_list(abx.pm.hook.get_INSTALLED_APPS()), # all plugin django-apps found in archivebox/plugins_* and data/user_plugins,
  57. # 3rd-party apps from PyPI that need to be loaded last
  58. 'admin_data_views', # handles rendering some convenient automatic read-only views of data in Django admin
  59. 'django_extensions', # provides Django Debug Toolbar (and other non-debug helpers)
  60. 'django_huey', # provides multi-queue support for django huey https://github.com/gaiacoop/django-huey
  61. 'bx_django_utils', # needed for huey_monitor https://github.com/boxine/bx_django_utils
  62. 'huey_monitor', # adds an admin UI for monitoring background huey tasks https://github.com/boxine/django-huey-monitor
  63. # load plugins last so all other apps are already .ready() when we call plugins.ready()
  64. 'abx',
  65. ]
  66. MIDDLEWARE = [
  67. 'core.middleware.TimezoneMiddleware',
  68. 'django.middleware.security.SecurityMiddleware',
  69. 'django.contrib.sessions.middleware.SessionMiddleware',
  70. 'django.middleware.common.CommonMiddleware',
  71. 'django.middleware.csrf.CsrfViewMiddleware',
  72. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  73. 'core.middleware.ReverseProxyAuthMiddleware',
  74. 'django.contrib.messages.middleware.MessageMiddleware',
  75. 'core.middleware.CacheControlMiddleware',
  76. *abx.as_list(abx.pm.hook.get_MIDDLEWARES()),
  77. ]
  78. ################################################################################
  79. ### Authentication Settings
  80. ################################################################################
  81. # AUTH_USER_MODEL = 'auth.User' # cannot be easily changed unfortunately
  82. AUTHENTICATION_BACKENDS = [
  83. 'django.contrib.auth.backends.RemoteUserBackend',
  84. 'django.contrib.auth.backends.ModelBackend',
  85. *abx.as_list(abx.pm.hook.get_AUTHENTICATION_BACKENDS()),
  86. ]
  87. # from ..plugins_auth.ldap.settings import LDAP_CONFIG
  88. # if LDAP_CONFIG.LDAP_ENABLED:
  89. # AUTH_LDAP_BIND_DN = LDAP_CONFIG.LDAP_BIND_DN
  90. # AUTH_LDAP_SERVER_URI = LDAP_CONFIG.LDAP_SERVER_URI
  91. # AUTH_LDAP_BIND_PASSWORD = LDAP_CONFIG.LDAP_BIND_PASSWORD
  92. # AUTH_LDAP_USER_ATTR_MAP = LDAP_CONFIG.LDAP_USER_ATTR_MAP
  93. # AUTH_LDAP_USER_SEARCH = LDAP_CONFIG.AUTH_LDAP_USER_SEARCH
  94. # AUTHENTICATION_BACKENDS = LDAP_CONFIG.AUTHENTICATION_BACKENDS
  95. ################################################################################
  96. ### Staticfile and Template Settings
  97. ################################################################################
  98. STATIC_URL = '/static/'
  99. TEMPLATES_DIR_NAME = 'templates'
  100. CUSTOM_TEMPLATES_ENABLED = os.path.isdir(CONSTANTS.CUSTOM_TEMPLATES_DIR) and os.access(CONSTANTS.CUSTOM_TEMPLATES_DIR, os.R_OK)
  101. STATICFILES_DIRS = [
  102. *([str(CONSTANTS.CUSTOM_TEMPLATES_DIR / 'static')] if CUSTOM_TEMPLATES_ENABLED else []),
  103. # *[
  104. # str(plugin_dir / 'static')
  105. # for plugin_dir in PLUGIN_DIRS.values()
  106. # if (plugin_dir / 'static').is_dir()
  107. # ],
  108. *abx.as_list(abx.pm.hook.get_STATICFILES_DIRS()),
  109. str(PACKAGE_DIR / TEMPLATES_DIR_NAME / 'static'),
  110. ]
  111. TEMPLATE_DIRS = [
  112. *([str(CONSTANTS.CUSTOM_TEMPLATES_DIR)] if CUSTOM_TEMPLATES_ENABLED else []),
  113. # *[
  114. # str(plugin_dir / 'templates')
  115. # for plugin_dir in PLUGIN_DIRS.values()
  116. # if (plugin_dir / 'templates').is_dir()
  117. # ],
  118. *abx.as_list(abx.pm.hook.get_TEMPLATE_DIRS()),
  119. str(PACKAGE_DIR / TEMPLATES_DIR_NAME / 'core'),
  120. str(PACKAGE_DIR / TEMPLATES_DIR_NAME / 'admin'),
  121. str(PACKAGE_DIR / TEMPLATES_DIR_NAME),
  122. ]
  123. TEMPLATES = [
  124. {
  125. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  126. 'DIRS': TEMPLATE_DIRS,
  127. 'APP_DIRS': True,
  128. 'OPTIONS': {
  129. 'context_processors': [
  130. 'django.template.context_processors.debug',
  131. 'django.template.context_processors.request',
  132. 'django.contrib.auth.context_processors.auth',
  133. 'django.contrib.messages.context_processors.messages',
  134. ],
  135. },
  136. },
  137. ]
  138. ################################################################################
  139. ### External Service Settings
  140. ################################################################################
  141. # CACHE_DB_FILENAME = 'cache.sqlite3'
  142. # CACHE_DB_PATH = CONSTANTS.CACHE_DIR / CACHE_DB_FILENAME
  143. # CACHE_DB_TABLE = 'django_cache'
  144. DATABASE_NAME = os.environ.get("ARCHIVEBOX_DATABASE_NAME", str(CONSTANTS.DATABASE_FILE))
  145. SQLITE_CONNECTION_OPTIONS = {
  146. "ENGINE": "django.db.backends.sqlite3",
  147. "TIME_ZONE": CONSTANTS.TIMEZONE,
  148. "OPTIONS": {
  149. # https://gcollazo.com/optimal-sqlite-settings-for-django/
  150. # https://litestream.io/tips/#busy-timeout
  151. # https://docs.djangoproject.com/en/5.1/ref/databases/#setting-pragma-options
  152. "timeout": 10,
  153. "check_same_thread": False,
  154. "transaction_mode": "IMMEDIATE",
  155. "init_command": (
  156. "PRAGMA foreign_keys=ON;"
  157. "PRAGMA journal_mode = WAL;"
  158. "PRAGMA synchronous = NORMAL;"
  159. "PRAGMA temp_store = MEMORY;"
  160. "PRAGMA mmap_size = 134217728;"
  161. "PRAGMA journal_size_limit = 67108864;"
  162. "PRAGMA cache_size = 2000;"
  163. ),
  164. },
  165. }
  166. DATABASES = {
  167. "default": {
  168. "NAME": DATABASE_NAME,
  169. **SQLITE_CONNECTION_OPTIONS,
  170. },
  171. "queue": {
  172. "NAME": CONSTANTS.QUEUE_DATABASE_FILE,
  173. **SQLITE_CONNECTION_OPTIONS,
  174. },
  175. # 'cache': {
  176. # 'NAME': CACHE_DB_PATH,
  177. # **SQLITE_CONNECTION_OPTIONS,
  178. # },
  179. }
  180. MIGRATION_MODULES = {'signal_webhooks': None}
  181. # as much as I'd love this to be a UUID or ULID field, it's not supported yet as of Django 5.0
  182. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  183. if not IS_GETTING_VERSION_OR_HELP: # dont create queue.sqlite3 file if we're just running to get --version or --help
  184. HUEY = {
  185. "huey_class": "huey.SqliteHuey",
  186. "filename": CONSTANTS.QUEUE_DATABASE_FILENAME,
  187. "name": "commands",
  188. "results": True,
  189. "store_none": True,
  190. "immediate": False,
  191. "utc": True,
  192. "consumer": {
  193. "workers": 1,
  194. "worker_type": "thread",
  195. "initial_delay": 0.1, # Smallest polling interval, same as -d.
  196. "backoff": 1.15, # Exponential backoff using this rate, -b.
  197. "max_delay": 10.0, # Max possible polling interval, -m.
  198. "scheduler_interval": 1, # Check schedule every second, -s.
  199. "periodic": True, # Enable crontab feature.
  200. "check_worker_health": True, # Enable worker health checks.
  201. "health_check_interval": 1, # Check worker health every second.
  202. },
  203. }
  204. # https://huey.readthedocs.io/en/latest/contrib.html#setting-things-up
  205. # https://github.com/gaiacoop/django-huey
  206. DJANGO_HUEY = {
  207. "default": "commands",
  208. "queues": {
  209. HUEY["name"]: HUEY.copy(),
  210. # more registered here at plugin import-time by BaseQueue.register()
  211. **abx.as_dict(abx.pm.hook.get_DJANGO_HUEY_QUEUES(QUEUE_DATABASE_NAME=CONSTANTS.QUEUE_DATABASE_FILENAME)),
  212. },
  213. }
  214. class HueyDBRouter:
  215. """
  216. A router to store all the Huey result k:v / Huey Monitor models in the queue.sqlite3 database.
  217. We keep the databases separate because the queue database receives many more reads/writes per second
  218. and we want to avoid single-write lock contention with the main database. Also all the in-progress task
  219. data is ephemeral/not-important-long-term. This makes it easier to for the user to clear non-critical
  220. temp data by just deleting queue.sqlite3 and leaving index.sqlite3.
  221. """
  222. route_app_labels = {"huey_monitor", "django_huey", "djhuey"}
  223. def db_for_read(self, model, **hints):
  224. if model._meta.app_label in self.route_app_labels:
  225. return "queue"
  226. return 'default'
  227. def db_for_write(self, model, **hints):
  228. if model._meta.app_label in self.route_app_labels:
  229. return "queue"
  230. return 'default'
  231. def allow_relation(self, obj1, obj2, **hints):
  232. if obj1._meta.app_label in self.route_app_labels or obj2._meta.app_label in self.route_app_labels:
  233. return obj1._meta.app_label == obj2._meta.app_label
  234. return None
  235. def allow_migrate(self, db, app_label, model_name=None, **hints):
  236. if app_label in self.route_app_labels:
  237. return db == "queue"
  238. return db == "default"
  239. DATABASE_ROUTERS = ['core.settings.HueyDBRouter']
  240. CACHES = {
  241. 'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'},
  242. # 'sqlite': {'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'cache'},
  243. # 'dummy': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
  244. # 'filebased': {"BACKEND": "django.core.cache.backends.filebased.FileBasedCache", "LOCATION": CACHE_DIR / 'cache_filebased'},
  245. }
  246. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  247. STORAGES = {
  248. "default": {
  249. "BACKEND": "django.core.files.storage.FileSystemStorage",
  250. },
  251. "staticfiles": {
  252. "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
  253. },
  254. "archive": {
  255. "BACKEND": "django.core.files.storage.FileSystemStorage",
  256. "OPTIONS": {
  257. "base_url": "/archive/",
  258. "location": ARCHIVE_DIR,
  259. },
  260. },
  261. # "personas": {
  262. # "BACKEND": "django.core.files.storage.FileSystemStorage",
  263. # "OPTIONS": {
  264. # "base_url": "/personas/",
  265. # "location": PERSONAS_DIR,
  266. # },
  267. # },
  268. }
  269. ################################################################################
  270. ### Security Settings
  271. ################################################################################
  272. SECRET_KEY = SERVER_CONFIG.SECRET_KEY or get_random_string(50, 'abcdefghijklmnopqrstuvwxyz0123456789_')
  273. ALLOWED_HOSTS = SERVER_CONFIG.ALLOWED_HOSTS.split(',')
  274. CSRF_TRUSTED_ORIGINS = list(set(SERVER_CONFIG.CSRF_TRUSTED_ORIGINS.split(',')))
  275. # automatically fix case when user sets ALLOWED_HOSTS (e.g. to archivebox.example.com)
  276. # but forgets to add https://archivebox.example.com to CSRF_TRUSTED_ORIGINS
  277. for hostname in ALLOWED_HOSTS:
  278. https_endpoint = f'https://{hostname}'
  279. if hostname != '*' and https_endpoint not in CSRF_TRUSTED_ORIGINS:
  280. print(f'[!] WARNING: {https_endpoint} from ALLOWED_HOSTS should be added to CSRF_TRUSTED_ORIGINS')
  281. CSRF_TRUSTED_ORIGINS.append(https_endpoint)
  282. SECURE_BROWSER_XSS_FILTER = True
  283. SECURE_CONTENT_TYPE_NOSNIFF = True
  284. SECURE_REFERRER_POLICY = 'strict-origin-when-cross-origin'
  285. CSRF_COOKIE_SECURE = False
  286. SESSION_COOKIE_SECURE = False
  287. SESSION_COOKIE_HTTPONLY = True
  288. SESSION_COOKIE_DOMAIN = None
  289. SESSION_COOKIE_AGE = 1209600 # 2 weeks
  290. SESSION_EXPIRE_AT_BROWSER_CLOSE = False
  291. SESSION_SAVE_EVERY_REQUEST = False
  292. SESSION_ENGINE = "django.contrib.sessions.backends.db"
  293. AUTH_PASSWORD_VALIDATORS = [
  294. {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
  295. {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
  296. {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
  297. {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
  298. ]
  299. DATA_UPLOAD_MAX_NUMBER_FIELDS = None
  300. DATA_UPLOAD_MAX_MEMORY_SIZE = 26_214_400 # 25MB
  301. ################################################################################
  302. ### Shell Settings
  303. ################################################################################
  304. SHELL_PLUS = 'ipython'
  305. SHELL_PLUS_PRINT_SQL = False
  306. IPYTHON_ARGUMENTS = ['--no-confirm-exit', '--no-banner']
  307. IPYTHON_KERNEL_DISPLAY_NAME = 'ArchiveBox Django Shell'
  308. if IS_SHELL:
  309. os.environ['PYTHONSTARTUP'] = str(PACKAGE_DIR / 'misc' / 'shell_welcome_message.py')
  310. ################################################################################
  311. ### Internationalization & Localization Settings
  312. ################################################################################
  313. LANGUAGE_CODE = 'en-us'
  314. USE_I18N = True
  315. USE_TZ = True
  316. DATETIME_FORMAT = 'Y-m-d h:i:s A'
  317. SHORT_DATETIME_FORMAT = 'Y-m-d h:i:s A'
  318. TIME_ZONE = CONSTANTS.TIMEZONE # django convention is TIME_ZONE, archivebox config uses TIMEZONE, they are equivalent
  319. from django.conf.locale.en import formats as en_formats # type: ignore
  320. en_formats.DATETIME_FORMAT = DATETIME_FORMAT # monkey patch en_format default with our preferred format
  321. en_formats.SHORT_DATETIME_FORMAT = SHORT_DATETIME_FORMAT
  322. ################################################################################
  323. ### Logging Settings
  324. ################################################################################
  325. from .settings_logging import SETTINGS_LOGGING, LOGS_DIR, ERROR_LOG
  326. LOGGING = SETTINGS_LOGGING
  327. ################################################################################
  328. ### REST API Outbound Webhooks settings
  329. ################################################################################
  330. # Add default webhook configuration to the User model
  331. SIGNAL_WEBHOOKS_CUSTOM_MODEL = 'api.models.OutboundWebhook'
  332. SIGNAL_WEBHOOKS = {
  333. "HOOKS": {
  334. # ... is a special sigil value that means "use the default autogenerated hooks"
  335. "django.contrib.auth.models.User": ...,
  336. "core.models.Snapshot": ...,
  337. "core.models.ArchiveResult": ...,
  338. "core.models.Tag": ...,
  339. "api.models.APIToken": ...,
  340. },
  341. }
  342. ################################################################################
  343. ### Admin Data View Settings
  344. ################################################################################
  345. ADMIN_DATA_VIEWS = {
  346. "NAME": "Environment",
  347. "URLS": [
  348. {
  349. "route": "config/",
  350. "view": "core.views.live_config_list_view",
  351. "name": "Configuration",
  352. "items": {
  353. "route": "<str:key>/",
  354. "view": "core.views.live_config_value_view",
  355. "name": "config_val",
  356. },
  357. },
  358. {
  359. "route": "binaries/",
  360. "view": "archivebox.config.views.binaries_list_view",
  361. "name": "Dependencies",
  362. "items": {
  363. "route": "<str:key>/",
  364. "view": "archivebox.config.views.binary_detail_view",
  365. "name": "binary",
  366. },
  367. },
  368. {
  369. "route": "plugins/",
  370. "view": "archivebox.config.views.plugins_list_view",
  371. "name": "Plugins",
  372. "items": {
  373. "route": "<str:key>/",
  374. "view": "archivebox.config.views.plugin_detail_view",
  375. "name": "plugin",
  376. },
  377. },
  378. {
  379. "route": "workers/",
  380. "view": "archivebox.config.views.worker_list_view",
  381. "name": "Workers",
  382. "items": {
  383. "route": "<str:key>/",
  384. "view": "archivebox.config.views.worker_detail_view",
  385. "name": "worker",
  386. },
  387. },
  388. {
  389. "route": "logs/",
  390. "view": "archivebox.config.views.log_list_view",
  391. "name": "Logs",
  392. "items": {
  393. "route": "<str:key>/",
  394. "view": "archivebox.config.views.log_detail_view",
  395. "name": "log",
  396. },
  397. },
  398. *abx.as_list(abx.pm.hook.get_ADMIN_DATA_VIEWS_URLS()),
  399. ],
  400. }
  401. ################################################################################
  402. ### Debug Settings
  403. ################################################################################
  404. # only enable debug toolbar when in DEBUG mode with --nothreading (it doesnt work in multithreaded mode)
  405. DEBUG_TOOLBAR = False
  406. DEBUG_TOOLBAR = DEBUG_TOOLBAR and DEBUG and ('--nothreading' in sys.argv) and ('--reload' not in sys.argv)
  407. if DEBUG_TOOLBAR:
  408. try:
  409. import debug_toolbar # noqa
  410. DEBUG_TOOLBAR = True
  411. except ImportError:
  412. DEBUG_TOOLBAR = False
  413. if DEBUG_TOOLBAR:
  414. INSTALLED_APPS = [*INSTALLED_APPS, 'debug_toolbar']
  415. INTERNAL_IPS = ['0.0.0.0', '127.0.0.1', '*']
  416. DEBUG_TOOLBAR_CONFIG = {
  417. "SHOW_TOOLBAR_CALLBACK": lambda request: True,
  418. "RENDER_PANELS": True,
  419. }
  420. DEBUG_TOOLBAR_PANELS = [
  421. 'debug_toolbar.panels.history.HistoryPanel',
  422. 'debug_toolbar.panels.versions.VersionsPanel',
  423. 'debug_toolbar.panels.timer.TimerPanel',
  424. 'debug_toolbar.panels.settings.SettingsPanel',
  425. 'debug_toolbar.panels.headers.HeadersPanel',
  426. 'debug_toolbar.panels.request.RequestPanel',
  427. 'debug_toolbar.panels.sql.SQLPanel',
  428. 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
  429. # 'debug_toolbar.panels.templates.TemplatesPanel',
  430. 'debug_toolbar.panels.cache.CachePanel',
  431. 'debug_toolbar.panels.signals.SignalsPanel',
  432. 'debug_toolbar.panels.logging.LoggingPanel',
  433. 'debug_toolbar.panels.redirects.RedirectsPanel',
  434. 'debug_toolbar.panels.profiling.ProfilingPanel',
  435. 'djdt_flamegraph.FlamegraphPanel',
  436. ]
  437. MIDDLEWARE = [*MIDDLEWARE, 'debug_toolbar.middleware.DebugToolbarMiddleware']
  438. if DEBUG:
  439. from django_autotyping.typing import AutotypingSettingsDict
  440. INSTALLED_APPS += ['django_autotyping']
  441. AUTOTYPING: AutotypingSettingsDict = {
  442. "STUBS_GENERATION": {
  443. "LOCAL_STUBS_DIR": PACKAGE_DIR / "typings",
  444. }
  445. }
  446. # https://github.com/bensi94/Django-Requests-Tracker (improved version of django-debug-toolbar)
  447. # Must delete archivebox/templates/admin to use because it relies on some things we override
  448. # visit /__requests_tracker__/ to access
  449. DEBUG_REQUESTS_TRACKER = True
  450. DEBUG_REQUESTS_TRACKER = DEBUG_REQUESTS_TRACKER and DEBUG
  451. if DEBUG_REQUESTS_TRACKER:
  452. import requests_tracker
  453. INSTALLED_APPS += ["requests_tracker"]
  454. MIDDLEWARE += ["requests_tracker.middleware.requests_tracker_middleware"]
  455. INTERNAL_IPS = ["127.0.0.1", "10.0.2.2", "0.0.0.0", "*"]
  456. TEMPLATE_DIRS.insert(0, str(Path(inspect.getfile(requests_tracker)).parent / "templates"))
  457. REQUESTS_TRACKER_CONFIG = {
  458. "TRACK_SQL": True,
  459. "ENABLE_STACKTRACES": False,
  460. "IGNORE_PATHS_PATTERNS": (
  461. r".*/favicon\.ico",
  462. r".*\.png",
  463. r"/admin/jsi18n/",
  464. ),
  465. "IGNORE_SQL_PATTERNS": (
  466. r"^SELECT .* FROM django_migrations WHERE app = 'requests_tracker'",
  467. r"^SELECT .* FROM django_migrations WHERE app = 'auth'",
  468. ),
  469. }
  470. # # https://docs.pydantic.dev/logfire/integrations/django/ (similar to DataDog / NewRelic / etc.)
  471. # DEBUG_LOGFIRE = False
  472. # DEBUG_LOGFIRE = DEBUG_LOGFIRE and os.access(DATA_DIR / '.logfire', os.W_OK) and (DATA_DIR / '.logfire').is_dir()
  473. # For usage with https://www.jetadmin.io/integrations/django
  474. # INSTALLED_APPS += ['jet_django']
  475. # JET_PROJECT = 'archivebox'
  476. # JET_TOKEN = 'some-api-token-here'
  477. # import ipdb; ipdb.set_trace()