diff --git a/backend/root/management/commands/seed_scripts/gangs.py b/backend/root/management/commands/seed_scripts/gangs.py index 694c906e0..0da3c576a 100755 --- a/backend/root/management/commands/seed_scripts/gangs.py +++ b/backend/root/management/commands/seed_scripts/gangs.py @@ -79,7 +79,7 @@ def seed(): # noqa: C901 for gang_type in GANGS[org]: gtype = None if gang_type != '': - gtype, _ = GangType.objects.get_or_create(title_nb=gang_type) + gtype, _ = GangType.objects.get_or_create(title_nb=gang_type, organization=organization) for gang in GANGS[org][gang_type]: name, abbr, sections = gang diff --git a/backend/root/utils/routes.py b/backend/root/utils/routes.py index fc1b27776..127f55124 100644 --- a/backend/root/utils/routes.py +++ b/backend/root/utils/routes.py @@ -564,8 +564,6 @@ samfundet__recruitment_applications_for_position_detail = 'samfundet:recruitment_applications_for_position-detail' samfundet__interview_list = 'samfundet:interview-list' samfundet__interview_detail = 'samfundet:interview-detail' -samfundet__api_root = 'samfundet:api-root' -samfundet__api_root = 'samfundet:api-root' samfundet__schema = 'samfundet:schema' samfundet__swagger_ui = 'samfundet:swagger_ui' samfundet__redoc = 'samfundet:redoc' @@ -584,6 +582,7 @@ samfundet__home = 'samfundet:home' samfundet__assign_group = 'samfundet:assign_group' samfundet__webhook = 'samfundet:webhook' +samfundet__gangsorganized = 'samfundet:gangsorganized' samfundet__check_reservation = 'samfundet:check_reservation' samfundet__active_recruitments = 'samfundet:active_recruitments' samfundet__recruitment_positions = 'samfundet:recruitment_positions' diff --git a/backend/samfundet/migrations/0011_gangtype_organization.py b/backend/samfundet/migrations/0011_gangtype_organization.py new file mode 100644 index 000000000..ef7861197 --- /dev/null +++ b/backend/samfundet/migrations/0011_gangtype_organization.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.1 on 2024-12-09 15:42 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("samfundet", "0010_recruitment_promo_media"), + ] + + operations = [ + migrations.AddField( + model_name="gangtype", + name="organization", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="gangtypes", + to="samfundet.organization", + verbose_name="Organisasjon", + ), + ), + ] diff --git a/backend/samfundet/models/general.py b/backend/samfundet/models/general.py index 7b6786377..54b9d290d 100644 --- a/backend/samfundet/models/general.py +++ b/backend/samfundet/models/general.py @@ -289,6 +289,15 @@ class GangType(CustomBaseModel): title_nb = models.CharField(max_length=64, blank=True, null=True, verbose_name='Gruppetype Norsk') title_en = models.CharField(max_length=64, blank=True, null=True, verbose_name='Gruppetype Engelsk') + organization = models.ForeignKey( + to=Organization, + related_name='gangtypes', + verbose_name='Organisasjon', + on_delete=models.CASCADE, + null=True, + blank=True, + ) + class Meta: verbose_name = 'GangType' verbose_name_plural = 'GangTypes' @@ -296,6 +305,12 @@ class Meta: def __str__(self) -> str: return f'{self.title_nb}' + def resolve_org(self, *, return_id: bool = False) -> Organization | int: + if return_id: + # noinspection PyTypeChecker + return self.organization_id + return self.organization + class Gang(CustomBaseModel): name_nb = models.CharField(max_length=64, blank=True, null=True, verbose_name='Navn Norsk') diff --git a/backend/samfundet/urls.py b/backend/samfundet/urls.py index 940ac346f..f74838408 100644 --- a/backend/samfundet/urls.py +++ b/backend/samfundet/urls.py @@ -74,6 +74,7 @@ path('home/', views.HomePageView().as_view(), name='home'), path('assign_group/', views.AssignGroupView.as_view(), name='assign_group'), path('webhook/', views.WebhookView.as_view(), name='webhook'), + path('gangtypes//', views.GangTypeOrganizationView.as_view(), name='gangsorganized'), ########## Lyche ########## path('check-reservation/', views.ReservationCheckAvailabilityView.as_view(), name='check_reservation'), ########## Recruitment ########## diff --git a/backend/samfundet/views.py b/backend/samfundet/views.py index 59666f8aa..d2bd3dfc8 100644 --- a/backend/samfundet/views.py +++ b/backend/samfundet/views.py @@ -307,6 +307,15 @@ class GangTypeView(ModelViewSet): queryset = GangType.objects.all() +class GangTypeOrganizationView(APIView): + permission_classes = [AllowAny] + serializer_class = GangTypeSerializer + + def get(self, request: Request, organization: int) -> Response: + data = GangType.objects.filter(organization=organization) + return Response(data=self.serializer_class(data, many=True).data, status=status.HTTP_200_OK) + + class InformationPageView(ModelViewSet): permission_classes = (DjangoModelPermissionsOrAnonReadOnly,) serializer_class = InformationPageSerializer diff --git a/frontend/src/routes/backend.ts b/frontend/src/routes/backend.ts index 85145b038..67e00787b 100644 --- a/frontend/src/routes/backend.ts +++ b/frontend/src/routes/backend.ts @@ -563,7 +563,6 @@ export const ROUTES_BACKEND = { samfundet__recruitment_applications_for_position_detail: '/api/recruitment-applications-for-position/:pk/', samfundet__interview_list: '/api/interview/', samfundet__interview_detail: '/api/interview/:pk/', - samfundet__api_root: '/api/', samfundet__schema: '/schema/', samfundet__swagger_ui: '/schema/swagger-ui/', samfundet__redoc: '/schema/redoc/', @@ -582,6 +581,7 @@ export const ROUTES_BACKEND = { samfundet__home: '/home/', samfundet__assign_group: '/assign_group/', samfundet__webhook: '/webhook/', + samfundet__gangsorganized: '/gangtypes/:organization/', samfundet__check_reservation: '/check-reservation/', samfundet__active_recruitments: '/active-recruitments/', samfundet__recruitment_positions: '/recruitment-positions/', @@ -611,4 +611,4 @@ export const ROUTES_BACKEND = { samfundet__gang_application_stats: '/recruitment/:recruitmentId/gang/:gangId/stats/', static__path: '/static/:path', media__path: '/media/:path', -} as const; \ No newline at end of file +} as const;