Skip to content

Olivia/28-add-villages-and-supplyitems - #38

Open
oliviamrkw wants to merge 6 commits into
mainfrom
olivia/28-add-villages-and-supplies
Open

oliviamrkw wants to merge 6 commits into
mainfrom
olivia/28-add-villages-and-supplies

Conversation

@oliviamrkw

Copy link
Copy Markdown
Collaborator

What this changes

Closes #27

  • Adds Village (unique name per region, ignoring case) and an optional village on Site, which must be in the site's region
  • Adds SupplyItem. quantity_kind comes from the unit (count = positive whole numbers, measure = positive decimals) and is not editable
  • Registers both in the admin. A supply item's unit can't be changed after it's created
  • Farm responses now include village ({id, name, region} or null)
  • Adds GET /api/supply-items/ (login required, active items only)
  • Adds villages and supply items to seed_projects, plus migration 0002_village_supplyitem.py and tests

How to test it

  1. docker compose up -d from the repo root
  2. Since Fix the existing app and setup errors #35 isn't merged yet, run migrations separately:
  • docker compose exec backend python src/manage.py migrate accounts
  • docker compose exec backend python src/manage.py migrate admin
  • docker compose exec backend python src/manage.py migrate sessions
  • docker compose exec backend python src/manage.py migrate projects
  1. docker compose exec backend python src/manage.py seed_projects, then docker compose exec backend python src/manage.py createsuperuser
  2. In /admin/, set "Finca Las Palmas" (Yoro) to the village "El Naranjo" (Atlántida). It should be rejected
  3. GET /api/supply-items/ returns 401 logged out and 5 active items with a token. GET /api/projects/1/sites/ shows village on each farm (null for Finca Las Palmas)
  4. Run tests: docker compose exec backend python -m pytest tests/test_village_supply_models.py tests/test_village_supply_api.py --nomigrations (51 passed)

Checklist

  • Backend tests pass (cd backend && python -m pytest)
  • I ran the app and the screen I touched still works
  • If I changed a model, the migration is committed
  • No .env, credentials, or LAN IP in the diff
  • Review requested from my pair

Notes for the reviewer

@CaellumYHL CaellumYHL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a couple nit-picks before it's ready to merge.

class Village(StandardModel):
"""A village within a region. Sites can optionally be linked to one."""

region = models.ForeignKey(Region, on_delete=models.PROTECT, related_name="villages")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you prevent changing a village’s region when it would cause linked farms to point to a different region? Right now moving a village from Atlántida to Yoro leaves its existing farms pointing to Atlántida so the location data is inconsistent.

villages = {}
for region_name, names in VILLAGES.items():
for name in names:
village, _ = Village.objects.get_or_create(region=regions[region_name], name=name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use case-insensitive name lookups here and in the supply-item lookup? So that we dont have to worry about capitals messing up the database models

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.

Add villages and a list of supplies

2 participants