Skip to content

Commit 12d8deb

Browse files
committed
fix:groups maps
1 parent 524f530 commit 12d8deb

File tree

7 files changed

+84
-33
lines changed

7 files changed

+84
-33
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.2.10 on 2026-02-02 16:10
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("accounts", "0004_peoplegrouplocation_peoplegroup_location"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="peoplegroup",
16+
name="location",
17+
field=models.OneToOneField(
18+
blank=True,
19+
null=True,
20+
on_delete=django.db.models.deletion.SET_NULL,
21+
related_name="people_group",
22+
to="accounts.peoplegrouplocation",
23+
),
24+
),
25+
]

apps/accounts/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ class PublicationStatus(models.TextChoices):
153153
permissions_up_to_date = models.BooleanField(default=False)
154154

155155
tags = models.ManyToManyField("skills.Tag", related_name="people_groups")
156-
location = models.ForeignKey(
156+
location = models.OneToOneField(
157157
PeopleGroupLocation,
158158
on_delete=models.SET_NULL,
159159
null=True,
160160
blank=True,
161-
related_name="people_groups",
161+
related_name="people_group",
162162
)
163163
# links
164164

apps/accounts/serializers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from django.shortcuts import get_object_or_404
77
from drf_spectacular.utils import extend_schema_serializer
88
from rest_framework import serializers
9-
from services.crisalid.serializers import ResearcherSerializerLight
10-
from services.translator.serializers import AutoTranslatedModelSerializer
119

1210
from apps.commons.fields import (
1311
HiddenPrimaryKeyRelatedField,
@@ -30,6 +28,8 @@
3028
from apps.projects.models import Project
3129
from apps.skills.models import Skill
3230
from apps.skills.serializers import SkillLightSerializer, TagRelatedField
31+
from services.crisalid.serializers import ResearcherSerializerLight
32+
from services.translator.serializers import AutoTranslatedModelSerializer
3333

3434
from .exceptions import (
3535
FeaturedProjectPermissionDeniedError,
@@ -248,7 +248,7 @@ class PeopleGroupSuperLightSerializer(
248248

249249
class Meta:
250250
model = PeopleGroup
251-
read_only_fields = ["id", "slug", "name", "organization"]
251+
read_only_fields = ["id", "slug", "name", "short_description", "organization"]
252252
fields = read_only_fields
253253

254254

@@ -590,6 +590,16 @@ class Meta:
590590
]
591591

592592

593+
class LocationPeopleGroupSerializer(
594+
AutoTranslatedModelSerializer, serializers.ModelSerializer
595+
):
596+
group = PeopleGroupSuperLightSerializer(source="people_group", read_only=True)
597+
598+
class Meta:
599+
model = PeopleGroupLocation
600+
fields = "__all__"
601+
602+
593603
@extend_schema_serializer(exclude_fields=("roles",))
594604
class UserSerializer(
595605
StringsImagesSerializer, AutoTranslatedModelSerializer, serializers.ModelSerializer

apps/accounts/views.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,15 @@
2525
from rest_framework.decorators import action
2626
from rest_framework.filters import OrderingFilter
2727
from rest_framework.parsers import JSONParser
28-
from rest_framework.permissions import (
29-
IsAuthenticated,
30-
IsAuthenticatedOrReadOnly,
31-
)
28+
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly
3229
from rest_framework.response import Response
3330
from rest_framework.serializers import BooleanField
3431
from rest_framework.views import APIView
35-
from services.google.models import GoogleAccount, GoogleGroup
36-
from services.google.tasks import (
37-
create_google_account,
38-
create_google_group,
39-
suspend_google_account,
40-
update_google_account,
41-
update_google_group,
42-
)
43-
from services.keycloak.exceptions import KeycloakAccountNotFound
44-
from services.keycloak.interface import KeycloakService
4532

4633
from apps.commons.filters import UnaccentSearchFilter
4734
from apps.commons.models import GroupData
4835
from apps.commons.permissions import IsOwner, ReadOnly, WillBeOwner
49-
from apps.commons.serializers import (
50-
EmailAddressSerializer,
51-
RetrieveUpdateModelViewSet,
52-
)
36+
from apps.commons.serializers import EmailAddressSerializer, RetrieveUpdateModelViewSet
5337
from apps.commons.utils import map_action_to_permission
5438
from apps.commons.views import DetailOnlyViewsetMixin, MultipleIDViewsetMixin
5539
from apps.files.models import Image
@@ -58,6 +42,16 @@
5842
from apps.organizations.permissions import HasOrganizationPermission
5943
from apps.projects.serializers import LocationSerializer, ProjectLightSerializer
6044
from apps.skills.models import Skill
45+
from services.google.models import GoogleAccount, GoogleGroup
46+
from services.google.tasks import (
47+
create_google_account,
48+
create_google_group,
49+
suspend_google_account,
50+
update_google_account,
51+
update_google_group,
52+
)
53+
from services.keycloak.exceptions import KeycloakAccountNotFound
54+
from services.keycloak.interface import KeycloakService
6155

6256
from .exceptions import EmailTypeMissingError, PermissionNotFoundError
6357
from .filters import PeopleGroupFilter, UserFilter

apps/modules/group.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from apps.accounts.models import PeopleGroup, ProjectUser
66
from apps.modules.base import AbstractModules, register_module
7-
from apps.projects.models import Project
7+
from apps.projects.models import Location, Project
88
from apps.skills.models import Skill
99
from services.crisalid.models import Document, DocumentTypeCentralized
1010

@@ -67,6 +67,9 @@ def similars(self) -> QuerySet[PeopleGroup]:
6767
def subgroups(self) -> QuerySet[PeopleGroup]:
6868
return self.instance.children.all()
6969

70+
def locations(self) -> QuerySet[Location]:
71+
return Location.objects.filter(project__in=self.featured_projects())
72+
7073
@cached_property
7174
def _is_structure(self):
7275
try:

apps/projects/urls.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from rest_framework.routers import DefaultRouter
22

33
from apps.announcements.views import AnnouncementViewSet
4-
from apps.commons.urls import project_router_register
4+
from apps.commons.urls import organization_router_register, project_router_register
55
from apps.feedbacks.views import (
66
CommentImagesView,
77
CommentViewSet,
@@ -12,6 +12,7 @@
1212
from .views import (
1313
BlogEntryImagesView,
1414
BlogEntryViewSet,
15+
GeneralLocationView,
1516
GoalViewSet,
1617
HistoricalProjectViewSet,
1718
LinkedProjectViewSet,
@@ -25,11 +26,13 @@
2526
ProjectTabItemViewset,
2627
ProjectTabViewset,
2728
ProjectViewSet,
28-
ReadLocationViewSet,
2929
)
3030

3131
router = DefaultRouter()
32-
router.register(r"location", ReadLocationViewSet, basename="Read-location")
32+
33+
organization_router_register(
34+
router, r"location", GeneralLocationView, basename="General-location"
35+
)
3336
router.register(r"project", ProjectViewSet, basename="Project")
3437

3538
project_router_register(

apps/projects/views.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from rest_framework.response import Response
1818
from simple_history.utils import update_change_reason
1919

20+
from apps.accounts.models import PeopleGroupLocation
2021
from apps.accounts.permissions import HasBasePermission
22+
from apps.accounts.serializers import LocationPeopleGroupSerializer
2123
from apps.analytics.models import Stat
2224
from apps.commons.cache import clear_cache_with_key, redis_cache_view
2325
from apps.commons.permissions import IsOwner, ReadOnly
@@ -43,7 +45,7 @@
4345
)
4446
from services.mistral.models import ProjectEmbedding
4547

46-
from .filters import LocationFilter, ProjectFilter
48+
from .filters import ProjectFilter
4749
from .models import (
4850
BlogEntry,
4951
Goal,
@@ -612,11 +614,6 @@ def dispatch(self, request, *args, **kwargs):
612614
return super(LocationViewSet, self).dispatch(request, *args, **kwargs)
613615

614616

615-
class ReadLocationViewSet(LocationViewSet):
616-
http_method_names = ["get", "list"]
617-
filterset_class = LocationFilter
618-
619-
620617
class HistoricalProjectViewSet(MultipleIDViewsetMixin, viewsets.ReadOnlyModelViewSet):
621618
lookup_field = "pk"
622619
permission_classes = [ReadOnly]
@@ -1004,3 +1001,22 @@ def add_image_to_model(self, image, *args, **kwargs):
10041001
tab_item.save()
10051002
return f"/v1/project/{self.kwargs['project_id']}/tab/{self.kwargs['tab_id']}/item-image/{image.id}"
10061003
return None
1004+
1005+
1006+
class GeneralLocationView(viewsets.GenericViewSet):
1007+
http_method_names = ["get", "list"]
1008+
1009+
def list(self, request, *args, **kwargs):
1010+
qs_project = self.request.user.get_project_related_queryset(
1011+
Location.objects
1012+
).select_related("project")
1013+
1014+
qs_group = self.request.user.get_people_group_related_queryset(
1015+
PeopleGroupLocation.objects
1016+
).select_related("people_group")
1017+
1018+
data = {
1019+
"groups": LocationPeopleGroupSerializer(qs_group, many=True).data,
1020+
"projects": LocationSerializer(qs_project, many=True).data,
1021+
}
1022+
return Response(data, status=status.HTTP_200_OK)

0 commit comments

Comments
 (0)