From 01534f626d996cc3c62d1cb036b62f3fbaa339a6 Mon Sep 17 00:00:00 2001 From: muhammedr7025 Date: Thu, 9 Nov 2023 17:39:24 +0530 Subject: [PATCH 1/4] task type crud --- api/dashboard/task/dash_task_serializer.py | 42 +++++++++++++- api/dashboard/task/dash_task_view.py | 65 +++++++++++++++++++++- api/dashboard/task/urls.py | 6 +- mulearnbackend/settings.py | 4 +- 4 files changed, 111 insertions(+), 6 deletions(-) diff --git a/api/dashboard/task/dash_task_serializer.py b/api/dashboard/task/dash_task_serializer.py index a64fc2d5..8905dc1a 100644 --- a/api/dashboard/task/dash_task_serializer.py +++ b/api/dashboard/task/dash_task_serializer.py @@ -1,6 +1,9 @@ +import uuid from rest_framework import serializers -from db.task import TaskList, KarmaActivityLog +from db.task import TaskList, KarmaActivityLog, TaskType +from utils.permission import JWTUtils +from utils.utils import DateTimeUtils class TaskListSerializer(serializers.ModelSerializer): @@ -100,3 +103,40 @@ class Meta: "created_at", "updated_at", ] + +class TasktypeSerializer(serializers.ModelSerializer): + updated_by=serializers.CharField(source='updated_by.fullname') + created_by=serializers.CharField(source='created_by.fullname') + + class Meta: + model = TaskType + fields = ["id", "title","updated_by","updated_at","created_by","created_at"] + +class TaskTypeCreateUpdateSerializer(serializers.ModelSerializer): + + class Meta: + model=TaskType + fields=["title"] + + def create(self, validated_data): + user_id = self.context.get("user_id") + return TaskType.objects.create( + id=uuid.uuid4(), + title=validated_data.get("title"), + updated_by_id=user_id, + updated_at=DateTimeUtils.get_current_utc_time(), + created_by_id=user_id, + created_at=DateTimeUtils.get_current_utc_time(), + ) + def update(self, instance, validated_data): + updated_title = validated_data.get("title") + instance.title = updated_title + user_id = JWTUtils.fetch_user_id(self.context.get("request")) + instance.updated_by_id = user_id + instance.updated_at=DateTimeUtils.get_current_utc_time(), + instance.save() + return instance + + + + diff --git a/api/dashboard/task/dash_task_view.py b/api/dashboard/task/dash_task_view.py index c555355b..93e33e2d 100644 --- a/api/dashboard/task/dash_task_view.py +++ b/api/dashboard/task/dash_task_view.py @@ -12,6 +12,8 @@ TaskImportSerializer, TaskListSerializer, TaskModifySerializer, + TaskTypeCreateUpdateSerializer, + TasktypeSerializer, ) from openpyxl import load_workbook @@ -536,4 +538,65 @@ def get(self, request): with open(tmp.name, 'rb') as f: f.seek(0) new_file_object = f.read() - return FileResponse(BytesIO(new_file_object), as_attachment=True, filename='task_base_template.xlsx') \ No newline at end of file + return FileResponse(BytesIO(new_file_object), as_attachment=True, filename='task_base_template.xlsx') + +class TaskTypeCrudAPI(APIView): + authentication_classes = [CustomizePermission] + @role_required( + [ + RoleType.ADMIN.value, + ] + ) + def get(self,request): + taskType=TaskType.objects.all() + paginated_queryset = CommonUtils.get_paginated_queryset( + taskType, request, [ "title"],{"title":"title","updated_by":"updated_by","created_by":"created_by","updated_at":"updated_at","created_at":"created_at"} + ) + serializer = TasktypeSerializer( + paginated_queryset.get("queryset"), many=True + ) + + return CustomResponse().paginated_response( + data=serializer.data, pagination=paginated_queryset.get("pagination") + ) + + @role_required([RoleType.ADMIN.value]) + def post(self, request): + user_id = JWTUtils.fetch_user_id(request) + serializer = TaskTypeCreateUpdateSerializer( + data=request.data, context={"user_id": user_id} + ) + if serializer.is_valid(): + serializer.save() + return CustomResponse( + general_message="Task type added successfully" + ).get_success_response() + + return CustomResponse(general_message=serializer.errors).get_failure_response() + + @role_required([RoleType.ADMIN.value]) + def delete(self, request, task_type_id): + taskType = TaskType.objects.filter(id=task_type_id).first() + if taskType is None: + return CustomResponse( + general_message="task type doesnt exist" + ).get_failure_response() + taskType.delete() + return CustomResponse( + general_message=f"{taskType.title} Deleted Successfully" + ).get_success_response() + + @role_required([RoleType.ADMIN.value]) + def put(self, request, task_type_id): + taskType = TaskType.objects.filter(id=task_type_id).first() + if taskType is None: + return CustomResponse(general_message="task type not found").get_failure_response() + serializer = TaskTypeCreateUpdateSerializer( + taskType, data=request.data, context={"request": request} + ) + if serializer.is_valid(): + serializer.save() + return CustomResponse( + general_message=f"{taskType.title} updated successfully" + ).get_success_response() + return CustomResponse(response=serializer.errors).get_failure_response() diff --git a/api/dashboard/task/urls.py b/api/dashboard/task/urls.py index 5072de8f..fcbb7dfa 100644 --- a/api/dashboard/task/urls.py +++ b/api/dashboard/task/urls.py @@ -8,7 +8,7 @@ path('ig/', dash_task_view.IGDropdownAPI.as_view()), path('organization/', dash_task_view.OrganizationDropdownAPI.as_view()), path('level/', dash_task_view.LevelDropdownAPI.as_view()), - path('task-types/', dash_task_view.TaskTypesDropDownAPI.as_view()), + #path('task-types/', dash_task_view.TaskTypesDropDownAPI.as_view()), path('', dash_task_view.TaskListAPI.as_view()), # list task, create path('csv/', dash_task_view.TaskListCSV.as_view()), # CSV @@ -17,6 +17,8 @@ path('events/', dash_task_view.EventDropDownApi.as_view()), - path('/', dash_task_view.TaskAPI.as_view()), # get task, edit, delete + #path('/', dash_task_view.TaskAPI.as_view()), # get task, edit, delete + path('list-task-type/', dash_task_view.TaskTypeCrudAPI.as_view()), # get tasktype,create tasktype + path('list-task-type/', dash_task_view.TaskTypeCrudAPI.as_view()), #delete,edit ] diff --git a/mulearnbackend/settings.py b/mulearnbackend/settings.py index 39527389..aad17e48 100644 --- a/mulearnbackend/settings.py +++ b/mulearnbackend/settings.py @@ -228,5 +228,5 @@ import socket -hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) -INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2'] +#hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) +#INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2'] From f03b3ebdfa144a1be3fc417b4eeee753d4c68998 Mon Sep 17 00:00:00 2001 From: anirudh-mk Date: Mon, 13 Nov 2023 23:33:51 +0530 Subject: [PATCH 2/4] feat(lc):schedule meetings --- api/dashboard/lc/dash_lc_serializer.py | 2 +- api/dashboard/lc/dash_lc_view.py | 24 +++++++++++++++++++++++- api/dashboard/lc/urls.py | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api/dashboard/lc/dash_lc_serializer.py b/api/dashboard/lc/dash_lc_serializer.py index 125f030f..6da75712 100644 --- a/api/dashboard/lc/dash_lc_serializer.py +++ b/api/dashboard/lc/dash_lc_serializer.py @@ -486,7 +486,7 @@ def update(self, instance, validated_data): return instance -class LearningCircleCreateEditDeleteSerializer(serializers.ModelSerializer): +class ScheduleMeetingSerializer(serializers.ModelSerializer): class Meta: model = LearningCircle fields = [ diff --git a/api/dashboard/lc/dash_lc_view.py b/api/dashboard/lc/dash_lc_view.py index 19edea01..106df27d 100644 --- a/api/dashboard/lc/dash_lc_view.py +++ b/api/dashboard/lc/dash_lc_view.py @@ -14,7 +14,7 @@ from utils.response import CustomResponse from utils.utils import send_template_mail, DateTimeUtils from .dash_lc_serializer import LearningCircleSerializer, LearningCircleCreateSerializer, LearningCircleHomeSerializer, \ - LearningCircleUpdateSerializer, LearningCircleJoinSerializer, LearningCircleCreateEditDeleteSerializer, \ + LearningCircleUpdateSerializer, LearningCircleJoinSerializer, ScheduleMeetingSerializer, \ LearningCircleMainSerializer, LearningCircleNoteSerializer, LearningCircleDataSerializer, \ LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer @@ -666,3 +666,25 @@ def post(self, request, circle_id, muid, status): ).get_failure_response() +class ScheduleMeetAPI(APIView): + def put(self, request, circle_id): + learning_circle = LearningCircle.objects.filter( + id=circle_id + ).first() + + serializer = ScheduleMeetingSerializer( + learning_circle, + data=request.data + ) + if serializer.is_valid(): + data = serializer.save() + + return CustomResponse( + general_message=f"meet scheduled on {data.meet_time}" + ).get_success_response() + + return CustomResponse( + message=serializer.errors + ).get_failure_response() + + diff --git a/api/dashboard/lc/urls.py b/api/dashboard/lc/urls.py index 93b7552b..88d1fb5a 100644 --- a/api/dashboard/lc/urls.py +++ b/api/dashboard/lc/urls.py @@ -9,6 +9,7 @@ path('list-all/', dash_lc_view.TotalLearningCircleListApi.as_view()), path('create/', dash_lc_view.LearningCircleCreateApi.as_view()), path('list-members//', dash_lc_view.LearningCircleListMembersApi.as_view()), + path('schedule-meet//', dash_lc_view.ScheduleMeetAPI.as_view()), # path('invite/', dash_lc_view.LearningCircleInviteLeadAPI.as_view()), path('list-all//', dash_lc_view.TotalLearningCircleListApi.as_view()), path('join//', dash_lc_view.LearningCircleJoinApi.as_view()), From 9c52bb99157840fe8000a4608d35856d03bab148 Mon Sep 17 00:00:00 2001 From: muhammedr7025 Date: Tue, 14 Nov 2023 11:47:14 +0530 Subject: [PATCH 3/4] task type --- api/dashboard/task/urls.py | 7 ++----- mulearnbackend/settings.py | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/api/dashboard/task/urls.py b/api/dashboard/task/urls.py index fcbb7dfa..c3f20b4b 100644 --- a/api/dashboard/task/urls.py +++ b/api/dashboard/task/urls.py @@ -8,16 +8,13 @@ path('ig/', dash_task_view.IGDropdownAPI.as_view()), path('organization/', dash_task_view.OrganizationDropdownAPI.as_view()), path('level/', dash_task_view.LevelDropdownAPI.as_view()), - #path('task-types/', dash_task_view.TaskTypesDropDownAPI.as_view()), - + path('task-types/', dash_task_view.TaskTypesDropDownAPI.as_view()), path('', dash_task_view.TaskListAPI.as_view()), # list task, create path('csv/', dash_task_view.TaskListCSV.as_view()), # CSV path('import/', dash_task_view.ImportTaskListCSV.as_view()), path('base-template/', dash_task_view.TaskBaseTemplateAPI.as_view()), - path('events/', dash_task_view.EventDropDownApi.as_view()), - - #path('/', dash_task_view.TaskAPI.as_view()), # get task, edit, delete + path('/', dash_task_view.TaskAPI.as_view()), # get task, edit, delete path('list-task-type/', dash_task_view.TaskTypeCrudAPI.as_view()), # get tasktype,create tasktype path('list-task-type/', dash_task_view.TaskTypeCrudAPI.as_view()), #delete,edit diff --git a/mulearnbackend/settings.py b/mulearnbackend/settings.py index aad17e48..39527389 100644 --- a/mulearnbackend/settings.py +++ b/mulearnbackend/settings.py @@ -228,5 +228,5 @@ import socket -#hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) -#INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2'] +hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) +INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2'] From 74a25042dbfb46c65fc8f15ea89fc106d544d911 Mon Sep 17 00:00:00 2001 From: SurajSuresh123 Date: Wed, 15 Nov 2023 21:46:02 +0530 Subject: [PATCH 4/4] [FIX] location serializers --- api/dashboard/location/location_serializer.py | 6 +++--- api/dashboard/location/location_views.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/api/dashboard/location/location_serializer.py b/api/dashboard/location/location_serializer.py index 2b541223..e48739ac 100644 --- a/api/dashboard/location/location_serializer.py +++ b/api/dashboard/location/location_serializer.py @@ -59,7 +59,7 @@ class StateCreateEditSerializer(serializers.ModelSerializer): # value = serializers.CharField(source="id") class Meta: model = State - fields = ["label", "created_by", "updated_by"] + fields = ["label", "country", "created_by", "updated_by"] class ZoneRetrievalSerializer(serializers.ModelSerializer): @@ -92,7 +92,7 @@ class ZoneCreateEditSerializer(serializers.ModelSerializer): class Meta: model = Zone - fields = ["label", "created_by", "updated_by"] + fields = ["label", "state", "created_by", "updated_by"] class DistrictRetrievalSerializer(serializers.ModelSerializer): @@ -129,4 +129,4 @@ class DistrictCreateEditSerializer(serializers.ModelSerializer): class Meta: model = District - fields = ["label", "created_by", "updated_by"] + fields = ["label", "zone","created_by", "updated_by"] diff --git a/api/dashboard/location/location_views.py b/api/dashboard/location/location_views.py index 44457a06..35792c9a 100644 --- a/api/dashboard/location/location_views.py +++ b/api/dashboard/location/location_views.py @@ -79,7 +79,9 @@ class StateDataAPI(APIView): @role_required([RoleType.ADMIN.value]) def get(self, request, state_id=None): if state_id: - states = State.objects.filter(pk=state_id).select_related("country", "created_by", "updated_by") + states = State.objects.filter(pk=state_id).select_related( + "country", "created_by", "updated_by" + ) else: states = State.objects.all().select_related( "country", "created_by", "updated_by" @@ -129,9 +131,7 @@ def patch(self, request, state_id): return CustomResponse(response=serializer.data).get_success_response() - return CustomResponse( - general_message="State edited successfully" - ).get_failure_response() + return CustomResponse(general_message=serializer.errors).get_failure_response() @role_required([RoleType.ADMIN.value]) def delete(self, request, state_id): @@ -217,7 +217,7 @@ class DistrictDataAPI(APIView): def get(self, request, district_id=None): if district_id: districts = District.objects.filter(pk=district_id) - + else: districts = District.objects.all().select_related( "zone", @@ -254,9 +254,7 @@ def post(self, request): return CustomResponse(response=serializer.data).get_success_response() - return CustomResponse( - general_message="Zone created successfully" - ).get_failure_response() + return CustomResponse(general_message=serializer.errors).get_failure_response() @role_required([RoleType.ADMIN.value]) def patch(self, request, district_id):