Note: This document is a personal note where I add the unsaid coding conventions of the OpenWISP community. I usually find these while reviewing PRs of new contributors. Some of these are not hard rules but mere preferences, while some are the best practices adopted by the Python/Django community.
Any setting which is related to an OpenWISP module should not be accessed from the django.conf.settings
object.
Rather, it should be accessed by importing the settings file from the module.
Example:
- # Instead of doing this
- from django.conf import settings
- critical_metrics = getattr(settings, 'OPENWISP_MONITORING_CRITICAL_METRICS')
+ # Do this
+ from openwisp_monitoring.checks import settings as app_settings
+ critical_metrics = app_settings.CRITICAL_metrics
OpenWISP prefers to use the Signal.connect
in apps.py of the Django app to connect signals
to receivers instead of using the @receiver
decorator on the receiver function.
OpenWISP prefers to use the Model.DoesNotExist
instead of the blanket django.core.exceptions.ObjectDoesNotExists
.