Skip to content

Refactor settings (mostly)#117

Open
chrisarridge wants to merge 15 commits into
developfrom
ca/refactor-settings
Open

Refactor settings (mostly)#117
chrisarridge wants to merge 15 commits into
developfrom
ca/refactor-settings

Conversation

@chrisarridge
Copy link
Copy Markdown
Contributor

@chrisarridge chrisarridge commented May 19, 2026

This PR (mainly) contains a refactoring of the settings for IATI Account. This aims to achieve two things, and make a start on a third:

  1. Best practice in Django is to reference settings via django.conf.settings whereas the current implementation imports iati_account_web.settings quite liberally. In addition, the env object is imported quite liberally to fetch settings directly from the environment variables, rather than relying on "unpacking" these variables in settings.py. This PR addresses this by unpacking the variables and changing the code to get settings from django.conf.settings.
  2. Also, settings.py contains a mix of pure settings and constant data, which is not best practice. This PR moves the data into a separate constant.py module. This is also a step towards fetching codelist and licences from an external SSOT.
  3. The PR also contains a start on simplifying the environment variable setup for IATI Account. A number of environment variables are removed and the database connection is simplified to a connection string (closing Refactor POSTGRES_* environment variables to use a single connection string #116, which is related to Config options for postgres db #10). A review of issues You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path #9 and Config options for allowed hosts #12 was also carried out as part of the work leading up to this PR.

A small bug was also caught as part of testing this refactoring and fixed while in the neighbourhood.

There are a significant number of commits, some of them are bigger and establish the pattern for the refactoring, others are relatively small. I recommend going through commit-by-commit.

This commit starts the process of refactoring the settings file so that
it does not contain data and constants, but just settings information.
This will also involve refactoring other files to access settings with
django.conf.settings rather than a direct import which is not best
practice.
This commit moves the generation of a list of timezones and other
choice fields, such as user roles and reporting source types, from
settings into constants.
Codelists and licences are currently loaded by settings.py and accessed
from there, but this is not best practice.  This commit refactors
settings.py to move these constant pieces of data into constants.py.
We anticipate handling these codelist values separately in the future,
e.g., via a periodic refresh from a separate SSOT and storage in the
database, but for now this cleans up settings.
This commit removes the environment variables used to set the names
of the codelist files.  These are essentially fixed and so this
change reduces complexity in the environment variables.
This commit simplifies the database setup and removes each individual
env variable for host, name, password with a single connection string
URL env variable.  This closes
#116 which is related
to #10.
This commit fixes a small bug where Superadmin could be selected
as a valid role to change an organisation user to in the list of
organisation users.
@chrisarridge chrisarridge requested a review from simon-20 May 19, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants