From f209f91bc5d23d797525a6d906d18723384c3912 Mon Sep 17 00:00:00 2001 From: divyanshsharma2280 <142323854+divyanshsharma2280@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:48:13 +0530 Subject: [PATCH] EVENT SPECIFIC TEAM SIZE --- udyam/views.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/udyam/views.py b/udyam/views.py index 071527f..c6a5203 100644 --- a/udyam/views.py +++ b/udyam/views.py @@ -129,8 +129,12 @@ def post(self, request): if self.user_is_part_of_team(member, event): return Response({"error": "User is already part of a team for this event."},status=status.HTTP_400_BAD_REQUEST) - if team.member1 != None and team.member2 != None: - return Response({"Error" : "Team is full"}, status=status.HTTP_400_BAD_REQUEST) + if event.name in ['digisim', 'ichip', 'commnet', 'xiota']: + if team.member1 is not None: + return Response({"Error": "Team is full"}, status=status.HTTP_400_BAD_REQUEST) + + if team.member1 is not None and team.member2 is not None: + return Response({"Error": "Team is full"}, status=status.HTTP_400_BAD_REQUEST) # generating email link and sending the email link = self.generate_link(team_name, event_name, member_email) @@ -138,7 +142,7 @@ def post(self, request): from_email = settings.EMAIL_HOST_USER send_mail("Team Invite", f"Here is the {link} to join {team_name} for the event {event_name}", from_email, (member_email,)) - return Response({'message': 'Email sent for verification.'}, status=status.HTTP_200_OK) + return Response({'message': 'Email sent for Invitation.'}, status=status.HTTP_200_OK) def get_user_instance_by_email(self, email): @@ -210,14 +214,21 @@ def get(self, request): return Response({"error": "User is already part of a team for this event."},status=status.HTTP_400_BAD_REQUEST) # checking if the team is full - if team.member1 == None: - team.member1 = member - team.save() - elif team.member2 == None: - team.member2 = member - team.save() + if event.name in ['digisim', 'ichip', 'commnet', 'xiota']: + if team.member1 is not None: + return Response({"Error": "Team is full"}, status=status.HTTP_400_BAD_REQUEST) + else: + team.member1 = member + else: - return Response({"Error": "Team is full"}, status=status.HTTP_400_BAD_REQUEST) + if team.member1 is None: + team.member1 = member + elif team.member2 is None: + team.member2 = member + else: + return Response({"Error":"Team is full"}) + + team.save() return Response({"Message" : f"{member_email} successfully joined team"})