Skip to content

Commit

Permalink
feat: refactor gangtype with organization
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Dec 9, 2024
1 parent c5a9ca8 commit aac28c1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/root/management/commands/seed_scripts/gangs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions backend/root/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
25 changes: 25 additions & 0 deletions backend/samfundet/migrations/0011_gangtype_organization.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
15 changes: 15 additions & 0 deletions backend/samfundet/models/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,28 @@ 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'

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')
Expand Down
1 change: 1 addition & 0 deletions backend/samfundet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:organization>/', views.GangTypeOrganizationView.as_view(), name='gangsorganized'),
########## Lyche ##########
path('check-reservation/', views.ReservationCheckAvailabilityView.as_view(), name='check_reservation'),
########## Recruitment ##########
Expand Down
9 changes: 9 additions & 0 deletions backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand All @@ -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/',
Expand Down Expand Up @@ -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;
} as const;

0 comments on commit aac28c1

Please sign in to comment.