Skip to content

Instantly share code, notes, and snippets.

@pandafy
Last active May 27, 2024 13:29
Show Gist options
  • Save pandafy/73e8eca22fab4dffae5b5c296569fe59 to your computer and use it in GitHub Desktop.
Save pandafy/73e8eca22fab4dffae5b5c296569fe59 to your computer and use it in GitHub Desktop.
OpenWISP Coding Conventions

OpenWISP Coding Conventions

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.

1. Accessing the app setting

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

2. Connecting signals to signal receiver

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.

3. Don't use ObjectDoesNotExist

OpenWISP prefers to use the Model.DoesNotExist instead of the blanket django.core.exceptions.ObjectDoesNotExists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment