From 29effe076e1013ea831a7d38a984ff7337d7bb00 Mon Sep 17 00:00:00 2001 From: anirudh-mk Date: Tue, 28 Nov 2023 20:37:41 +0530 Subject: [PATCH 1/3] optim(lc meet-record)code optimized --- api/dashboard/lc/dash_lc_serializer.py | 39 +++++++++++++++++- api/dashboard/lc/dash_lc_view.py | 56 +++++++------------------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/api/dashboard/lc/dash_lc_serializer.py b/api/dashboard/lc/dash_lc_serializer.py index 694b31b4..c2b032e6 100644 --- a/api/dashboard/lc/dash_lc_serializer.py +++ b/api/dashboard/lc/dash_lc_serializer.py @@ -1,12 +1,14 @@ import uuid -from django.db.models import Sum, Count +from django.db.models import Sum, Count, Value, CharField +from django.db.models.functions import Concat from rest_framework import serializers from db.learning_circle import LearningCircle, UserCircleLink, InterestGroup, CircleMeetingLog from db.task import TaskList, UserIgLink from db.organization import UserOrganizationLink from db.task import KarmaActivityLog +from db.user import User from utils.types import OrganizationType from utils.utils import DateTimeUtils from utils.types import Lc @@ -505,17 +507,42 @@ def update(self, instance, validated_data): class MeetRecordsCreateEditDeleteSerializer(serializers.ModelSerializer): + attendees_details = serializers.SerializerMethodField() + meet_created_by = serializers.CharField(source='created_by.fullname', required=False) + meet_created_at = serializers.CharField(source='created_at', required=False) + meet_id = serializers.CharField(source='id', required=False) class Meta: model = CircleMeetingLog fields = [ + "meet_id", "meet_time", "meet_place", "day", "attendees", "agenda", + "attendees_details", + "meet_created_by", + "meet_created_at" ] + def get_attendees_details(self, obj): + attendees_list = obj.attendees.split(',') + + attendees_details_list = User.objects.filter( + id__in=attendees_list + ).values( + 'profile_pic', + fullname=Concat( + 'first_name', + Value(' '), + 'last_name', + output_field=CharField() + ), + ) + + return attendees_details_list + def create(self, validated_data): validated_data['id'] = uuid.uuid4() validated_data['circle_id'] = self.context.get('circle_id') @@ -550,6 +577,16 @@ def validate_attendees(self, attendees): return attendees +class ListAllMeetRecordsSerializer(serializers.ModelSerializer): + class Meta: + model = CircleMeetingLog + fields = [ + "id", + "meet_time", + "day", + ] + + class IgTaskDetailsSerializer(serializers.ModelSerializer): task = serializers.CharField(source='title') is_completed = serializers.SerializerMethodField() diff --git a/api/dashboard/lc/dash_lc_view.py b/api/dashboard/lc/dash_lc_view.py index 41f572b9..aa25b091 100644 --- a/api/dashboard/lc/dash_lc_view.py +++ b/api/dashboard/lc/dash_lc_view.py @@ -18,7 +18,8 @@ from .dash_lc_serializer import LearningCircleSerializer, LearningCircleCreateSerializer, LearningCircleHomeSerializer, \ LearningCircleUpdateSerializer, LearningCircleJoinSerializer, \ LearningCircleMainSerializer, LearningCircleNoteSerializer, LearningCircleDataSerializer, \ - LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer, IgTaskDetailsSerializer, ScheduleMeetingSerializer + LearningCircleMemberListSerializer, MeetRecordsCreateEditDeleteSerializer, IgTaskDetailsSerializer, \ + ScheduleMeetingSerializer, ListAllMeetRecordsSerializer domain = config("FR_DOMAIN_NAME") from_mail = config("FROM_MAIL") @@ -396,53 +397,24 @@ def delete(self, request, circle_id): class MeetRecordsGetPostPatchDeleteAPI(APIView): - def get(self, request, circle_id=None, meet_id=None): - + def get(self, request, meet_id=None, circle_id=None): if meet_id: - circle_meeting_log = CircleMeetingLog.objects.filter( - id=meet_id - ).values( - "id", - "meet_time", - "meet_place", - "day", - "attendees", - "agenda", - meet_created_by=F("created_by__first_name"), - meet_created_at=F("created_at"), - meet_updated_by=F("updated_by__first_name"), - meet_updated_at=F("updated_at"), - ) - for meeting in circle_meeting_log: - - attendees = meeting.get('attendees', '') - attendees_list = attendees.split(',') - - attendees_first_names = User.objects.filter( - id__in=attendees_list - ).values( - 'profile_pic', - fullname=Concat( - 'first_name', - Value(' '), - 'last_name', - output_field=CharField() - ), - ) + circle_meeting_log = CircleMeetingLog.objects.get(id=meet_id) - meeting['attendees'] = list(attendees_first_names) + serializer = MeetRecordsCreateEditDeleteSerializer( + circle_meeting_log, + many=False + ).data if circle_id: - circle_meeting_log = CircleMeetingLog.objects.filter( - circle_id=circle_id - ).values( - "id", - "meet_time", - "day" - ) + circle_meeting_log = CircleMeetingLog.objects.filter(circle_id=circle_id) + serializer = ListAllMeetRecordsSerializer( + circle_meeting_log, + many=True + ).data return CustomResponse( - response=circle_meeting_log + response=serializer ).get_success_response() def post(self, request, circle_id): From afb951b11f881042a6f8516a4e1f3a80daa0f4c1 Mon Sep 17 00:00:00 2001 From: Adnan Kattekaden Date: Tue, 28 Nov 2023 21:59:58 +0530 Subject: [PATCH 2/3] campusdeatils api response graduation year and department added --- api/dashboard/campus/serializers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/dashboard/campus/serializers.py b/api/dashboard/campus/serializers.py index 6bef9550..6c291589 100644 --- a/api/dashboard/campus/serializers.py +++ b/api/dashboard/campus/serializers.py @@ -23,6 +23,7 @@ class CampusDetailsSerializer(serializers.ModelSerializer): rank = serializers.SerializerMethodField() lead = serializers.SerializerMethodField() + department = serializers.CharField(source="department.title") class Meta: model = UserOrganizationLink @@ -37,6 +38,8 @@ class Meta: "active_members", "rank", "lead", + "graduation_year", + "department" ] def get_lead(self, obj): From 46dd05233bf31727d9942ff85ba3711120fdff98 Mon Sep 17 00:00:00 2001 From: Adnan Kattekaden Date: Tue, 28 Nov 2023 23:03:57 +0530 Subject: [PATCH 3/3] campusdeatils api response graduation year and department added --- api/dashboard/campus/campus_views.py | 2 ++ api/dashboard/campus/serializers.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/dashboard/campus/campus_views.py b/api/dashboard/campus/campus_views.py index 9496ad38..f64102aa 100644 --- a/api/dashboard/campus/campus_views.py +++ b/api/dashboard/campus/campus_views.py @@ -121,6 +121,8 @@ def get(self, request): karma=F("wallet_user__karma"), level=F("user_lvl_link_user__level__name"), join_date=F("created_at"), + department=F('user_organization_link_user__department__title'), + graduation_year=F("user_organization_link_user__graduation_year") )) paginated_queryset = CommonUtils.get_paginated_queryset( diff --git a/api/dashboard/campus/serializers.py b/api/dashboard/campus/serializers.py index 6c291589..b35db335 100644 --- a/api/dashboard/campus/serializers.py +++ b/api/dashboard/campus/serializers.py @@ -23,7 +23,6 @@ class CampusDetailsSerializer(serializers.ModelSerializer): rank = serializers.SerializerMethodField() lead = serializers.SerializerMethodField() - department = serializers.CharField(source="department.title") class Meta: model = UserOrganizationLink @@ -38,8 +37,6 @@ class Meta: "active_members", "rank", "lead", - "graduation_year", - "department" ] def get_lead(self, obj): @@ -124,6 +121,8 @@ class CampusStudentDetailsSerializer(serializers.Serializer): join_date = serializers.CharField() email = serializers.CharField() mobile = serializers.CharField() + graduation_year = serializers.CharField() + department = serializers.CharField() class Meta: fields = ("user_id", "email", "mobile", "fullname", "karma", "muid", "rank", "level", "join_date")