Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chores] Shortened internal settings for consistency #291

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openwisp_notifications/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _related_object(self, field):
cache.set(
cache_key,
obj,
timeout=app_settings.OPENWISP_NOTIFICATIONS_CACHE_TIMEOUT,
timeout=app_settings.CACHE_TIMEOUT,
)
return obj

Expand Down
2 changes: 1 addition & 1 deletion openwisp_notifications/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@checks.register
def check_cors_configuration(app_configs, **kwargs):
errors = []
if not app_settings.OPENWISP_NOTIFICATIONS_HOST:
if not app_settings.HOST:
return errors

if not (
Expand Down
6 changes: 2 additions & 4 deletions openwisp_notifications/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

def notification_api_settings(request):
return {
'OPENWISP_NOTIFICATIONS_HOST': app_settings.OPENWISP_NOTIFICATIONS_HOST,
'OPENWISP_NOTIFICATIONS_SOUND': static(
app_settings.OPENWISP_NOTIFICATIONS_SOUND
),
'OPENWISP_NOTIFICATIONS_HOST': app_settings.HOST,
'OPENWISP_NOTIFICATIONS_SOUND': static(app_settings.SOUND),
}
9 changes: 4 additions & 5 deletions openwisp_notifications/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

CONFIG_DEFAULTS.update({'USE_JSONFIELD': True})

OPENWISP_NOTIFICATIONS_HOST = getattr(settings, 'OPENWISP_NOTIFICATIONS_HOST', None)
HOST = getattr(settings, 'OPENWISP_NOTIFICATIONS_HOST', None)

OPENWISP_NOTIFICATIONS_CACHE_TIMEOUT = getattr(
CACHE_TIMEOUT = getattr(
settings, 'OPENWISP_NOTIFICATIONS_CACHE_TIMEOUT', 2 * 24 * 60 * 60
)

Expand All @@ -31,16 +31,15 @@
},
)

OPENWISP_NOTIFICATIONS_SOUND = getattr(
SOUND = getattr(
settings,
'OPENWISP_NOTIFICATIONS_SOUND',
'openwisp-notifications/audio/notification_bell.mp3',
)

# Remove the leading "/static/" here as it will
# conflict with the "static()" call in context_processors.py.
# This is done for backward compatibility.
OPENWISP_NOTIFICATIONS_SOUND = re.sub('^/static/', '', OPENWISP_NOTIFICATIONS_SOUND)
SOUND = re.sub('^/static/', '', SOUND)


def get_config():
Expand Down
4 changes: 2 additions & 2 deletions openwisp_notifications/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_default_notification_setting(self):
# For more info, look at TestAdmin.test_default_notification_setting
@patch.object(
app_settings,
'OPENWISP_NOTIFICATIONS_SOUND',
'SOUND',
'/static/notification.mp3',
)
def test_notification_sound_setting(self):
Expand All @@ -141,7 +141,7 @@ def test_notification_sound_setting(self):

@patch.object(
app_settings,
'OPENWISP_NOTIFICATIONS_HOST',
'HOST',
'https://example.com',
)
def test_notification_host_setting(self):
Expand Down
2 changes: 1 addition & 1 deletion openwisp_notifications/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def test_related_objects_database_query(self):
self.assertEqual(n.action_object, operator)
self.assertEqual(n.target, operator)

@patch.object(app_settings, 'OPENWISP_NOTIFICATIONS_CACHE_TIMEOUT', 0)
@patch.object(app_settings, 'CACHE_TIMEOUT', 0)
def test_notification_cache_timeout(self):
# Timeout=0 means value is not cached
operator = self._get_operator()
Expand Down
2 changes: 1 addition & 1 deletion openwisp_notifications/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_populate_notification_preferences_command(self, mocked_task):
class TestChecks(TestCase, TestOrganizationMixin):
@patch.object(
app_settings,
'OPENWISP_NOTIFICATIONS_HOST',
'HOST',
'https://example.com',
)
def test_cors_not_configured(self):
Expand Down
Loading