Skip to content

Commit

Permalink
Merge pull request #76 from Segelzwerg/75-bug-dont-raise-theme-error-…
Browse files Browse the repository at this point in the history
…in-debug-mode

75-bug-dont-raise-theme-error-in-debug-mode
  • Loading branch information
Segelzwerg authored May 2, 2024
2 parents cd370ef + d235658 commit b13ab0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django_dynamic_theme/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Middlewares for the dynamic theme app."""

import warnings

from django.conf import settings
from django_dynamic_theme.errors import ThemeMissingError
from django_dynamic_theme.models import Theme

Expand Down Expand Up @@ -28,8 +31,11 @@ def process_exception(self, request, exception):
theme = Theme.objects.get(default=True)
except Theme.DoesNotExist:
theme = Theme.objects.first()
if theme is None:
if theme is None and settings.DEBUG:
raise ThemeMissingError from exception
if theme is None:
warnings.warn("Theme is missing.")
return None
theme.write_export()
response = self.get_response(request)
return response
2 changes: 2 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import mkdir, path, remove
from unittest.mock import MagicMock
from compressor.exceptions import UncompressableFileError
from django.conf import settings
from django.http import HttpResponse
from django.test import TestCase

Expand Down Expand Up @@ -59,6 +60,7 @@ def test_save_file_no_default(self):
self.assertTrue(path.exists(self.file_path))

def test_save_file_no_theme(self):
settings.DEBUG = True
request = MagicMock()
get_response = MagicMock()
middleware = MissingThemeHandleMiddleware(get_response)
Expand Down

0 comments on commit b13ab0c

Please sign in to comment.