python -m venv env
env\Scripts\activate
pip install wheel pip-tools
pip-compile
pip-sync
uv venv
uv pip compile requirements.in -o requirements.txt
uv pip sync requirements.txt
uv pip compile requirements.in -o requirements.txt
uv pip sync requirements.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
ruff check . --fix
ruff format .
# create app
dokku apps:create uk-grantmaking-data
# postgres
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku postgres:create uk-grantmaking-data-db
dokku postgres:link uk-grantmaking-data-db uk-grantmaking-data
# letsencrypt
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku letsencrypt:set uk-grantmaking-data [email protected]
dokku letsencrypt:enable uk-grantmaking-data
dokku letsencrypt:cron-job --add
# set secret key
# To generate use:
# `python -c "import secrets; print(secrets.token_urlsafe())"`
dokku config:set --no-restart uk-grantmaking-data SECRET_KEY='<insert secret key>'
# setup account directory
dokku storage:ensure-directory uk-grantmaking-data
dokku storage:mount uk-grantmaking-data /var/lib/dokku/data/storage/uk-grantmaking-data:/app/storage
dokku config:set uk-grantmaking-data --no-restart MEDIA_ROOT=/app/storage/media/
# setup hosts
dokku config:set uk-grantmaking-data --no-restart DEBUG=false ALLOWED_HOSTS="hostname.example.com"
# create superuser account
dokku run uk-grantmaking-data python manage.py createsuperuser
git remote add dokku dokku@SERVER_HOST:uk-grantmaking-data
git push dokku main
# create superuser account
dokku run uk-grantmaking-data python manage.py createsuperuser
These commands fetch new or updated data from an external source.
Fetch updated data for all current funders from Find that Charity.
Command line options:
--debug
: Enable debug mode--skip-funders
: Skip loading new funder information--skip-financial
: Skip loading new financial information for funders
What the command does:
- Funder data updates:
- Get a list of org ids of the current funders
- Fetch updated name, date registered, date removed and whether currently active from Find that Charity
- Update the
ukgrantmaking_funder
table with the updated data.
- Funder financial information:
- Run the SQL queries from
python manage.py update financial-year
to ensure all funders have the needed financial years - Get a list of all current funder financial years from the database
- Get a list of successor lookups from the database - this is where a funder has a "successor" organisation marked (i.e. they have re-registered with a different charity number or have merged with another organisation).
- Fetch updated financial records from Find that Charity.
- Match to the corrent funder_financial_year (including the
new_funder_financial_year_id
for organisations with a successor) - Update the
ukgrantmaking_funderyear
table with the new records.
- Run the SQL queries from
Fetches updated grants data from the 360Giving Datastore.
Command line options:
db_con
- Connection to the 360Giving Database. Usually doesn't need to be specified as it is taken from theTSG_DATASTORE_URL
environmental variable.
What the command does:
- Work out the current financial year
- Fetch all grants from the Datastore between the start and end dates specified in the current financial year
- Calculate the
planned_dates_duration
field - either using the existing value, or calculating fromplanned_dates_endDate
andplanned_dates_startDate
. - Fetch all grants from the DCMS lottery database between the start and end dates.
- Rename columns from the DCMS data to match the 360Giving data.
- Mark grants where the recipient is "Grant to Individual" or "Grant Awarded to Individual", or where the description is "Athlete Performance Award" as grants to individuals.
- Exclude grants from the DCMS data where it is already in the data from the 360Giving Datastore:
- Exclude any grants where the grant ID matches (including renaming the NLCF grant IDs from "DCMS-tnlcomfund-" to "360G-tnlcomfund-")
- Match grants based on:
- Grant title
- Amount awarded
- Award date
- Recipient organisation name
- Funding organisation ID
- Merge the two datasets into one
- Remove any duplicate grant IDs
- Ensure column formats are correct (amount awarded is a number, award date is a date, etc)
- Add a financial year column
- Save currencies to the database (these need to be periodically checked to ensure they have exchanged rates)
- Save grant records to the database
- Update grant inclusions for government grants:
- All grants not in central or devolved government are included by default
- All grants with a recipient organisation ID starting with
GB-CHC-
,GB-SC-
orGB-NIC-
are included by default
Fetch data for grant recipients from Find that Charity
What this command does:
- Get a list of all grant recipients (excluding grants to individuals)
- Check for any recipients that don't already have a
GrantRecipient
record, and create a record. Match this record to the grant object. - Update all existing
GrantRecipient
records with the type of recipient and their name from the latest grant to them. - Fetch updated data on all these recipient from Find that Charity. Update these records in the database
- Fetch updated financial data for all these recipients from Find that Charity. Add a financial year and update these records in the database.
These commands perform procedures to update the data currently in the database, without fetching any new data.
This runs a series of SQL commands to keep the financial data up to date. The commands are:
- Ensure every funder has a funder financial year for the current financial year
- Set the current year to the correct year
- Set the latest year to the correct year
- Recalculate aggregate values for funder financial years
- Update current funder financial years with the latest funder data
- Ensure that the current funder financial year has the correct tags
- Remove existing tags from the current funder financial year
These commands were used for the initial construction of the database for the 2024 UK Grantmaking publication but are no longer used.
Create a list of funders from an Excel sheet
Create Funder years from a list of excel files
Add tags to Funders from an Excel spreadsheet.
Should instead use the endpoint at /grantmakers/upload
.
Used to import data from the back catalogue of Foundation Giving Trends.
dokku postgres:export uk-grantmaking-data-db > ~/uk-grantmaking-data-db-20251701.export