Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create table project program area xref 45 #398

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ff71c12
feat: add and test many-to-many relationship between program_area and…
del9ra Oct 4, 2024
2e5fbb0
feat: update serializers: project and program_area
del9ra Oct 5, 2024
2d2e2fd
feat: add model: ProjectProgramAreaXref
del9ra Nov 1, 2024
fe73d30
feat: update serializers and add relationship test
del9ra Nov 1, 2024
58435ed
Update issue templates
ExperimentsInHonesty Oct 7, 2024
eca0fd7
Update issue templates
ExperimentsInHonesty Oct 7, 2024
d42a228
Issue 403 make project optional for user_permissions
ethanstrominger Oct 8, 2024
16f78fe
Migration scripts
ethanstrominger Oct 8, 2024
1a998e7
update Docker syntax
fyliu Sep 5, 2024
5d9d21f
scripts: add rebase_migration script
fyliu Sep 19, 2024
8849aad
split CONTRIBUTING.md into smaller files
fyliu Jul 23, 2024
0674439
move docker section into tools/docker.md
fyliu Oct 3, 2024
e83cbe3
split CONTRIBUTING.md from contributing/index.md
fyliu Jul 26, 2024
f554d4c
remove all header numbering
fyliu Jul 23, 2024
8bcebb2
move pre-commit section to the dev environment page
fyliu Jul 25, 2024
d0074c1
update titles for contributing pages
fyliu Jul 26, 2024
0a0b219
update links to contributing pages
fyliu Jul 26, 2024
85a2ddd
update team.md with slack channel link
fyliu Jul 26, 2024
ffae7ae
move how-to and tools to contributing
fyliu Jul 23, 2024
2c823a0
fix local dev api url in add model guide
fyliu Aug 24, 2024
df16191
fix link in contributing index.md
fyliu Sep 3, 2024
6bc00b1
Updated link to Prioritized Backlog and a few typos corrected
shmonks Oct 16, 2024
03dcd8f
list tools in alphabetical order
fyliu Oct 17, 2024
c884cde
Corrected typo
shmonks Oct 16, 2024
dfcf5bd
Corrected typo
shmonks Oct 16, 2024
e3021d8
fix link to How-to Guides in Contributing index
fyliu Oct 17, 2024
590cd97
fix link to Working with Docker
fyliu Oct 17, 2024
3c39e33
Revise issue templates (#407)
shmonks Oct 23, 2024
7f7b803
feat: add and test many-to-many relationship between program_area and…
del9ra Oct 4, 2024
c41ab2c
feat: add model: ProjectProgramAreaXref
del9ra Nov 1, 2024
6258799
fixed a merge conflict
del9ra Nov 1, 2024
9d5728f
feat: add model: ProjectProgramAreaXref
del9ra Nov 1, 2024
bd85788
Migration scripts
ethanstrominger Oct 8, 2024
27d9c07
fixed a merge conflict
del9ra Nov 1, 2024
eca9bd6
feat: fixed a merge conflict
del9ra Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class Meta:
class ProjectSerializer(serializers.ModelSerializer):
"""Used to retrieve project info"""

program_areas = serializers.StringRelatedField(many=True)

class Meta:
model = Project
fields = (
Expand All @@ -117,6 +119,7 @@ class Meta:
"image_logo",
"image_hero",
"image_icon",
"program_areas",
)
read_only_fields = (
"uuid",
Expand Down Expand Up @@ -227,9 +230,11 @@ class Meta:
class ProgramAreaSerializer(serializers.ModelSerializer):
"""Used to retrieve program_area info"""

projects = serializers.StringRelatedField(many=True)

class Meta:
model = ProgramArea
fields = ("uuid", "name", "description", "image")
fields = ("uuid", "name", "description", "image", "projects")
read_only_fields = ("uuid", "created_at", "updated_at")


Expand Down
20 changes: 20 additions & 0 deletions app/core/migrations/0028_project_program_areas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.11 on 2024-10-04 18:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0027_socmajor"),
]

operations = [
migrations.AddField(
model_name="project",
name="program_areas",
field=models.ManyToManyField(
blank=True, related_name="projects", to="core.programarea"
),
),
]
2 changes: 1 addition & 1 deletion app/core/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0027_socmajor
0028_project_program_areas
6 changes: 6 additions & 0 deletions app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ class Project(AbstractBaseModel):
image_logo = models.URLField(blank=True)
image_hero = models.URLField(blank=True)
image_icon = models.URLField(blank=True)
program_areas = models.ManyToManyField(
"ProgramArea",
related_name="projects",
blank=True,
# through="ProjectProgramAreaXref"
)

def __str__(self):
return f"{self.name}"
Expand Down
15 changes: 15 additions & 0 deletions app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SKILL_URL = reverse("skill-list")
STACK_ELEMENT_URL = reverse("stack-element-list")
PERMISSION_TYPE = reverse("permission-type-list")
PROJECT_URL = reverse("project-list")
STACK_ELEMENT_TYPE_URL = reverse("stack-element-type-list")
SDG_URL = reverse("sdg-list")
AFFILIATION_URL = reverse("affiliation-list")
Expand Down Expand Up @@ -381,3 +382,17 @@ def test_create_soc_major(auth_client):
res = auth_client.post(SOC_MAJOR_URL, payload)
assert res.status_code == status.HTTP_201_CREATED
assert res.data["title"] == payload["title"]


def test_project_program_area_xref(auth_client, project, program_area):
project.program_areas.add(program_area)
project.save()

proj_res = auth_client.get(PROJECT_URL)
program_area_res = auth_client.get(PROGRAM_AREA_URL)

assert filter(lambda proj: str(proj["uuid"]) == str(project.pk), proj_res.data)
assert filter(
lambda _program_area: str(_program_area["uuid"]) == str(program_area.pk),
program_area_res,
)
32 changes: 32 additions & 0 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pytest

from ..models import Event
from ..models import ProgramArea
from ..models import Project

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -145,3 +147,33 @@ def test_check_type(check_type):

def test_soc_major(soc_major):
assert str(soc_major) == "Test Soc Major"


def test_project_program_area_relationship(project):
civic_tech_infrastructure_program_area = ProgramArea.objects.get(
name="Civic Tech Infrastructure"
)
workforce_program_area = ProgramArea.objects.get(name="Workforce Development")
hack_for_la_project = Project.objects.create(name="Hack for LA Site")
hack_for_la_project.program_areas.add(
civic_tech_infrastructure_program_area, workforce_program_area
)
assert hack_for_la_project.program_areas.count() == 2
assert hack_for_la_project.program_areas.contains(
civic_tech_infrastructure_program_area
)
assert hack_for_la_project.program_areas.contains(workforce_program_area)
assert civic_tech_infrastructure_program_area.projects.contains(hack_for_la_project)
assert workforce_program_area.projects.contains(hack_for_la_project)

hack_for_la_project.program_areas.remove(civic_tech_infrastructure_program_area)
assert hack_for_la_project.program_areas.count() == 1
assert not hack_for_la_project.program_areas.contains(
civic_tech_infrastructure_program_area
)
assert hack_for_la_project.program_areas.contains(workforce_program_area)

assert not civic_tech_infrastructure_program_area.projects.contains(
hack_for_la_project
)
assert workforce_program_area.projects.contains(hack_for_la_project)
2 changes: 1 addition & 1 deletion scripts/createsuperuser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ set -x

# This command requires the DJANGO_SUPERUSER_USERNAME and
# DJANGO_SUPERUSER_PASSWORD environmental variables to be set when django starts
echo "DJANGO_SUPERUSER_USERNAME: $DJANGO_SUPERUSER_USERNAME"
# echo "DJANGO_SUPERUSER_USERNAME: $DJANGO_SUPERUSER_USERNAME"
docker-compose exec web python manage.py createsuperuser --no-input