terraso-backend

A Django project that powers the backend of Terraso platform.

https://github.com/techmatters/terraso-backend

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.5%) to scientific vocabulary

Keywords from Contributors

projection interactive serializer cycles packaging charts network-simulation archival shellcodes hacking
Last synced: 11 months ago · JSON representation

Repository

A Django project that powers the backend of Terraso platform.

Basic Info
  • Host: GitHub
  • Owner: techmatters
  • License: agpl-3.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 5.42 MB
Statistics
  • Stars: 20
  • Watchers: 3
  • Forks: 4
  • Open Issues: 77
  • Releases: 0
Created over 4 years ago · Last pushed 11 months ago
Metadata Files
Readme Contributing License

README.md

Terraso Backend

Terraso backend is a Django project that powers the backend of the Terraso platform.

Requirements

  • Docker: version 24 or better
  • Python: 3.12 or better

Running locally with Docker

Set up your environment file

sh $ cp .env.sample .env

In the .env file

  • set values for GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRETbased on what you have set up in console.cloud.google.com > APIs & Services > Credentials.

  • set values for APPLE_CLIENT_ID, APPLE_KEY_ID, APPLE_TEAM_ID, APPLE_PRIVATE_KEY and based on what you have set up on developer.apple.com > Certificates, Identifiers & Profiles > Keys.

  • set values for MICROSOFT_CLIENT_ID and either MICROSOFT_CLIENT_SECRET (less secure) or both MICROSOFT_PRIVATE_KEY and MICROSOFT_CERTIFICATE_THUMBPRINT based on what you have set up on portal.azure.com > App Registrations > [App Name] > Certificates & Secrets

Start building the Docker images (make sure there's requirements.txt file created before building the images):

sh $ make build

Run the database migrations before the first run:

sh $ make migrate

Than the run command can be executed:

sh $ make run

If you want to have a user to access the admin panel, you need to create it:

```sh $ make bash

(inside the web container)

$ python terraso_backend/manage.py createsuperuser $ exit ```

Debugging locally with Docker

To debug while running tests, just use regular Python breakpoint() and run the tests normally. Pytest will stop properly on break point giving you access to the Python debugger.

To debug while using the application locally, it's also possible to use Python breakpoint(). To have access to the Python debugger, you'll need to attach to the application running container.

So, assuming that the application is running with make run:

List the running containers

sh $ docker ps

Get the id of the web container before next step

sh $ docker attach <web-container-id>

This will give you access to the web running container

Make the application request call that will pass on breakpoint, like calling an API or clicking in some button. As soon as the process get to the break point, the attached shell should open the Python debugger. To continue the application request processing, just release the debugger.

Interacting with the database

Connect to the database

While the database is running (e.g. via make run), use:

sh make connect_db

Run or rollback a specific migration

You can tell the database to migrate a specific app to a specific number with:

sh APP_MIGRATION_NAME="{app_name} {migration_number}" make migrate

So to e.g. rollback migration 0014 of the soil_id app, you could run:

sh APP_MIGRATION_NAME="soil_id 0014" make migrate

Loading sample data

Import sample landscape data (names, descriptions, links):

sh $ python terraso_backend/manage.py loaddata sampledata.json

Import landscape boundaries geodata:

sh $ python terraso_backend/manage.py load_landscapes_geojson --airtable_api_key xxxxx

Download Soil ID data:

sh $ make download-soil-data

Reset the database

You can reset the database back to its default state:

sh $ python terraso_backend/manage.py flush

Backup the database

The contents of the database can be dumped to a JSON file for backup. Optionally, they can also be uploaded to a S3 bucket. This can be activated to be triggered from a button in the Django admin console. See the relevant README.md for more details.

Print migration SQL

You can view the SQL commands that a migration will issue by running

sh $ python terraso_backend/manage.py sqlmigrate {app_name} {migration_name}

or in Docker using the make command

sh $ APP_MIGRATION_NAME="{app_name} {migration_name}" make print_migration_sql

For example:

sh $ APP_MIGRATION_NAME="story_map 0001_initial" make print_migration_sql

Contributing

Before contributing to the project, it's recommended that you set up your local git running the following command:

sh $ make setup-git-hooks

This will activate two git hooks to automatically check Python code style and commit message structure before each commit.

Dealing with dependencies

It is possible to lock the dependencies to run the project with the following command

sh $ make lock

It is also possible to lock development dependencies with:

sh $ make lock-dev

The lock process creates/updates the files requirements.txt and requirements-dev.txt. With these files in place it's possible to install dependencies running:

sh $ make install

To install development dependencies run:

sh $ make install-dev

Local development

Your local machine needs:

  • Docker
  • Python

make lock requires GDAL and Cython:

sh $ brew install gdal

sh $ apt install gdal

cython

sh $ pip3 install cython

Generating GraphQL public documentation

The API docs are generated by SpectaQL. So, make sure you followed their README to have it installed before proceding. Run the following command to generate the documentation:

sh $ make api_doc

Enjoy! ;-)

Owner

  • Name: Tech Matters
  • Login: techmatters
  • Kind: organization

We help social change leaders understand what tech can and can’t do, and build the tech solutions behind solving a social problem.

GitHub Events

Total
  • Issues event: 30
  • Watch event: 1
  • Delete event: 213
  • Issue comment event: 71
  • Push event: 374
  • Pull request review comment event: 69
  • Pull request review event: 247
  • Pull request event: 442
  • Fork event: 1
  • Create event: 231
Last Year
  • Issues event: 30
  • Watch event: 1
  • Delete event: 213
  • Issue comment event: 71
  • Push event: 374
  • Pull request review comment event: 69
  • Pull request review event: 247
  • Pull request event: 442
  • Fork event: 1
  • Create event: 231

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 1,320
  • Total Committers: 16
  • Avg Commits per committer: 82.5
  • Development Distribution Score (DDS): 0.402
Past Year
  • Commits: 289
  • Committers: 7
  • Avg Commits per committer: 41.286
  • Development Distribution Score (DDS): 0.322
Top Committers
Name Email Commits
dependabot[bot] 4****] 790
Paul Schreiber p****l@t****g 227
Caio Carrara c****a 104
Jose Buitron j****n@g****m 60
David Code Howard d****d@t****g 50
garo (they/them) 3****m 42
Jodie Zhu 8****u 14
Carissa Knipe c****a@t****g 11
Jeancarlo Barrios J****s 5
ajabeckett 3****t 4
tm-ruxandra r****a@t****g 4
Andrew Carter 6****e 2
Caio Carrara c****o@t****g 2
garo (they/them) 3****k 2
Paul Schreiber p****l@t****g 2
Robert Bo Davis bo@i****g 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 239
  • Total pull requests: 2,006
  • Average time to close issues: 3 months
  • Average time to close pull requests: 4 days
  • Total issue authors: 14
  • Total pull request authors: 14
  • Average comments per issue: 0.77
  • Average comments per pull request: 0.24
  • Merged pull requests: 1,573
  • Bot issues: 9
  • Bot pull requests: 1,302
Past Year
  • Issues: 28
  • Pull requests: 549
  • Average time to close issues: 15 days
  • Average time to close pull requests: 4 days
  • Issue authors: 6
  • Pull request authors: 7
  • Average comments per issue: 0.39
  • Average comments per pull request: 0.13
  • Merged pull requests: 361
  • Bot issues: 6
  • Bot pull requests: 392
Top Authors
Issue Authors
  • david-code (64)
  • paulschreiber (40)
  • shrouxm (39)
  • ltseng (28)
  • caiocarrara (20)
  • josebui (13)
  • DerekCaelin (12)
  • dependabot[bot] (9)
  • garobrik (5)
  • JeancarloBarrios (3)
  • Hanal-code (2)
  • knipec (2)
  • tm-ruxandra (1)
  • robert-bo-davis (1)
Pull Request Authors
  • dependabot[bot] (1,302)
  • paulschreiber (317)
  • caiocarrara (114)
  • josebui (82)
  • shrouxm (67)
  • david-code (59)
  • knipec (22)
  • jodiezhuu (12)
  • JeancarloBarrios (9)
  • tm-ruxandra (7)
  • ajabeckett (6)
  • robert-bo-davis (4)
  • garobrik (3)
  • plentydone (2)
Top Labels
Issue Labels
landpks (58) Engineering (43) tech-debt (30) slim MVP (24) High (17) enhancement (12) site creation (10) Medium (10) python (9) dependencies (9) project management (7) good first issue (6) bug (6) profiles (6) 1000L (6) audit log (5) Low (3) needs triage (2) kobotoolbox (1) testing (1) stale (1) Capri MVP (1) Research (1)
Pull Request Labels
dependencies (1,302) python (1,172) blocked (66) github_actions (8) Engineering (1)

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/check-commits.yml actions
  • actions/checkout v3 composite
  • agenthunt/conventional-commit-checker-action v1.0.0 composite
Dockerfile docker
  • python 3.11.1-slim-bullseye build
requirements/base.in pypi
  • boto3 *
  • dj-database-url *
  • django *
  • django-cors-headers *
  • django-dirtyfields *
  • django-filter *
  • django-oauth-toolkit *
  • django-safedelete *
  • django-storages *
  • django-structlog *
  • geopandas *
  • graphene-django *
  • httpx *
  • prettyconf *
  • psycopg2 *
  • pyjwt *
  • pyproj *
  • python-magic *
  • rules *
  • shapely *
requirements/deploy.in pypi
  • ddtrace *
  • gunicorn *
requirements/dev.in pypi
  • black * development
  • flake8 * development
  • freezegun * development
  • ipdb * development
  • isort * development
  • mixer * development
  • moto * development
  • pytest * development
  • pytest-cov * development
  • pytest-django * development
  • respx * development
requirements-dev.txt pypi
  • anyio ==3.6.2 development
  • appnope ==0.1.3 development
  • asttokens ==2.2.1 development
  • attrs ==22.2.0 development
  • backcall ==0.2.0 development
  • black ==23.1.0 development
  • boto3 ==1.26.64 development
  • botocore ==1.29.69 development
  • certifi ==2022.12.7 development
  • cffi ==1.15.1 development
  • charset-normalizer ==3.0.1 development
  • click ==8.1.3 development
  • coverage ==7.1.0 development
  • cryptography ==39.0.1 development
  • decorator ==5.1.1 development
  • exceptiongroup ==1.1.0 development
  • executing ==1.2.0 development
  • faker ==12.0.1 development
  • flake8 ==6.0.0 development
  • freezegun ==1.2.2 development
  • h11 ==0.14.0 development
  • httpcore ==0.16.3 development
  • httpx ==0.23.3 development
  • idna ==3.4 development
  • iniconfig ==2.0.0 development
  • ipdb ==0.13.11 development
  • ipython ==8.10.0 development
  • isort ==5.12.0 development
  • jedi ==0.18.2 development
  • jinja2 ==3.1.2 development
  • jmespath ==1.0.1 development
  • markupsafe ==2.1.2 development
  • matplotlib-inline ==0.1.6 development
  • mccabe ==0.7.0 development
  • mixer ==7.2.2 development
  • moto ==4.1.2 development
  • mypy-extensions ==1.0.0 development
  • packaging ==23.0 development
  • parso ==0.8.3 development
  • pathspec ==0.11.0 development
  • pexpect ==4.8.0 development
  • pickleshare ==0.7.5 development
  • platformdirs ==3.0.0 development
  • pluggy ==1.0.0 development
  • prompt-toolkit ==3.0.36 development
  • ptyprocess ==0.7.0 development
  • pure-eval ==0.2.2 development
  • pycodestyle ==2.10.0 development
  • pycparser ==2.21 development
  • pyflakes ==3.0.1 development
  • pygments ==2.14.0 development
  • pytest ==7.2.1 development
  • pytest-cov ==4.0.0 development
  • pytest-django ==4.5.2 development
  • python-dateutil ==2.8.2 development
  • requests ==2.28.2 development
  • responses ==0.22.0 development
  • respx ==0.20.1 development
  • rfc3986 ==1.5.0 development
  • s3transfer ==0.6.0 development
  • six ==1.16.0 development
  • sniffio ==1.3.0 development
  • stack-data ==0.6.2 development
  • toml ==0.10.2 development
  • tomli ==2.0.1 development
  • traitlets ==5.9.0 development
  • types-toml ==0.10.8.3 development
  • urllib3 ==1.26.14 development
  • wcwidth ==0.2.6 development
  • werkzeug ==2.2.3 development
  • xmltodict ==0.13.0 development
requirements.txt pypi
  • aniso8601 ==9.0.1
  • anyio ==3.6.2
  • asgiref ==3.6.0
  • attrs ==22.2.0
  • boto3 ==1.26.64
  • botocore ==1.29.69
  • bytecode ==0.14.0
  • cattrs ==22.2.0
  • certifi ==2022.12.7
  • cffi ==1.15.1
  • charset-normalizer ==3.0.1
  • click ==8.1.3
  • click-plugins ==1.1.1
  • cligj ==0.7.2
  • cryptography ==39.0.1
  • ddsketch ==2.0.4
  • ddtrace ==1.7.5
  • deprecated ==1.2.13
  • dj-database-url ==1.2.0
  • django ==4.1.7
  • django-cors-headers ==3.13.0
  • django-dirtyfields ==1.9.1
  • django-filter ==22.1
  • django-ipware ==4.0.2
  • django-oauth-toolkit ==2.2.0
  • django-safedelete ==1.3.1
  • django-storages ==1.13.2
  • django-structlog ==4.1.0
  • envier ==0.4.0
  • exceptiongroup ==1.1.0
  • fiona ==1.9.0
  • geopandas ==0.12.2
  • graphene ==3.2.1
  • graphene-django ==3.0.0
  • graphql-core ==3.2.3
  • graphql-relay ==3.2.0
  • gunicorn ==20.1.0
  • h11 ==0.14.0
  • httpcore ==0.16.3
  • httpx ==0.23.3
  • idna ==3.4
  • jmespath ==1.0.1
  • jsonschema ==4.17.3
  • jwcrypto ==1.4.2
  • munch ==2.5.0
  • numpy ==1.24.2
  • oauthlib ==3.2.2
  • packaging ==23.0
  • pandas ==1.5.3
  • prettyconf ==2.2.1
  • promise ==2.3
  • protobuf ==4.21.12
  • psycopg2 ==2.9.5
  • pycparser ==2.21
  • pyjwt ==2.6.0
  • pyproj ==3.4.1
  • pyrsistent ==0.19.3
  • python-dateutil ==2.8.2
  • python-magic ==0.4.27
  • pytz ==2022.7.1
  • requests ==2.28.2
  • rfc3986 ==1.5.0
  • rules ==3.3
  • s3transfer ==0.6.0
  • shapely ==2.0.1
  • six ==1.16.0
  • sniffio ==1.3.0
  • sqlparse ==0.4.3
  • structlog ==22.3.0
  • tenacity ==8.1.0
  • text-unidecode ==1.3
  • typing-extensions ==4.4.0
  • urllib3 ==1.26.14
  • wrapt ==1.14.1
  • xmltodict ==0.13.0
.github/workflows/codeql.yml actions
  • actions/checkout v4 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
docker-compose.base.yml docker
  • postgis/postgis 14-master
  • techmatters/terraso_backend latest
docker-compose.ci.yml docker
docker-compose.dev.yml docker
package.json npm
pyproject.toml pypi
.github/workflows/auto-approve.yml actions
  • hmarr/auto-approve-action v3 composite