From f0aee2e65b2a0d597cb7bf68698eb6bd3612cf65 Mon Sep 17 00:00:00 2001 From: tosta Date: Sat, 20 Apr 2024 22:06:36 +0200 Subject: [PATCH 1/2] iso, grouptext and organization_text models added --- backend/content/admin.py | 12 +++++++++++- backend/content/models.py | 4 ++++ backend/entities/models.py | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/backend/content/admin.py b/backend/content/admin.py index d49c9da37..4a18334df 100644 --- a/backend/content/admin.py +++ b/backend/content/admin.py @@ -1,6 +1,15 @@ from django.contrib import admin -from .models import Faq, Image, Resource, ResourceTopic, Task, Topic, TopicFormat +from .models import ( + Faq, + Image, + IsoCodeMap, + Resource, + ResourceTopic, + Task, + Topic, + TopicFormat, +) admin.site.register(Faq) admin.site.register(Image) @@ -9,3 +18,4 @@ admin.site.register(Task) admin.site.register(Topic) admin.site.register(TopicFormat) +admin.site.register(IsoCodeMap) diff --git a/backend/content/models.py b/backend/content/models.py index 5c160dc5e..c35701b1d 100644 --- a/backend/content/models.py +++ b/backend/content/models.py @@ -153,3 +153,7 @@ class Image(models.Model): def __str__(self) -> str: return f"{self.id}" + + +class IsoCodeMap(models.Model): + code = models.CharField(max_length=2) diff --git a/backend/entities/models.py b/backend/entities/models.py index 5c7fc3a15..decd5d3af 100644 --- a/backend/entities/models.py +++ b/backend/entities/models.py @@ -157,6 +157,15 @@ def __str__(self) -> str: return f"{self.id}" +class OrganizationText(models.Model): + org_id = models.ForeignKey(Organization, on_delete=models.CASCADE) + iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE) + primary = models.BooleanField(default=False) + description = models.TextField(max_length=500) + get_involved = models.TextField(max_length=500) + donate = models.TextField(max_length=500) + + class GroupEvent(models.Model): group_id = models.ForeignKey(Group, on_delete=models.CASCADE) event_id = models.ForeignKey("events.Event", on_delete=models.CASCADE) @@ -201,6 +210,14 @@ def __str__(self) -> str: return f"{self.id}" +class GroupText(models.Model): + group_id = models.ForeignKey(Group, on_delete=models.CASCADE) + iso = models.ForeignKey("content.IsoCodeMap", on_delete=models.CASCADE) + primary = models.BooleanField(default=False) + description = models.TextField(max_length=500) + get_involved = models.TextField(max_length=500) + + class Status(models.Model): status_type = models.ForeignKey("StatusEntityType", on_delete=models.CASCADE) org_id = models.ForeignKey( From 884182d9ce4137e87f973002782453cb7bf6836e Mon Sep 17 00:00:00 2001 From: tosta Date: Sun, 21 Apr 2024 12:10:14 +0200 Subject: [PATCH 2/2] added iso code serializer, view and path --- backend/content/serializers.py | 7 +++++++ backend/content/urls.py | 1 + backend/content/views.py | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/backend/content/serializers.py b/backend/content/serializers.py index 1e18a479c..c5e10fed8 100644 --- a/backend/content/serializers.py +++ b/backend/content/serializers.py @@ -15,6 +15,7 @@ DiscussionTag, Faq, Image, + IsoCodeMap, Resource, ResourceTag, ResourceTopic, @@ -165,3 +166,9 @@ def validate(self, data: Dict[str, Union[str, int]]) -> Dict[str, Union[str, int ) return data + + +class IsoCodeMapSerializer(serializers.ModelSerializer[IsoCodeMap]): + class Meta: + model = IsoCodeMap + fields = "__all__" diff --git a/backend/content/urls.py b/backend/content/urls.py index 9c47c51f5..be9aeca5b 100644 --- a/backend/content/urls.py +++ b/backend/content/urls.py @@ -19,4 +19,5 @@ urlpatterns = [ path("", include(router.urls)), + path("iso_codes/", views.IsoCodeMapListAPIView.as_view(), name="iso_codes"), ] diff --git a/backend/content/views.py b/backend/content/views.py index 778a0b18b..5ce0c61b6 100644 --- a/backend/content/views.py +++ b/backend/content/views.py @@ -1,6 +1,7 @@ # mypy: disable-error-code="override" from django.db.models import Q from rest_framework import status, viewsets +from rest_framework.generics import ListAPIView from rest_framework.permissions import IsAuthenticatedOrReadOnly from rest_framework.request import Request from rest_framework.response import Response @@ -13,6 +14,7 @@ DiscussionEntry, Faq, Image, + IsoCodeMap, Resource, ResourceTopic, Task, @@ -24,6 +26,7 @@ DiscussionSerializer, FaqSerializer, ImageSerializer, + IsoCodeMapSerializer, ResourceSerializer, ResourceTopicSerializer, TaskSerializer, @@ -297,3 +300,13 @@ class TopicFormatViewSet(viewsets.ModelViewSet[TopicFormat]): queryset = TopicFormat.objects.all() serializer_class = TopicFormatSerializer pagination_class = CustomPagination + + +class IsoCodeMapListAPIView(ListAPIView[IsoCodeMap]): + queryset = IsoCodeMap.objects.all() + serializer_class = IsoCodeMapSerializer + + def get(self, request: Request) -> Response: + queryset = self.get_queryset() + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data, status=status.HTTP_200_OK)