Skip to content

Commit

Permalink
Merge pull request #2113 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
Dev server
  • Loading branch information
jelanmathewjames authored Jun 24, 2024
2 parents 4ed715b + 4a895c5 commit 585de90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 48 deletions.
35 changes: 0 additions & 35 deletions alter-scripts/alter-1.50.py

This file was deleted.

18 changes: 9 additions & 9 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from rest_framework.views import APIView

from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer, \
from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer, LaunchpadUserListSerializer,\
CollegeDataSerializer, LaunchpadUserSerializer, UserProfileUpdateSerializer, LaunchpadUpdateUserSerializer
from utils.response import CustomResponse
from utils.utils import CommonUtils, ImportCSV
Expand Down Expand Up @@ -101,7 +101,7 @@ def get(self, request):
district_name=F("user_organization_link_user__org__district__name"),
state=F("user_organization_link_user__org__district__zone__state__name"),
level=F("user_role_link_user__role__title"),
time_=Max("karma_activity_log_user__created_at")
time_=Max("karma_activity_log_user__created_at"),
).filter(
Q(level__in=allowed_levels) | Q(level__isnull=True)
).distinct()
Expand Down Expand Up @@ -231,7 +231,7 @@ def post(self, request):
if not serializer.is_valid():
return CustomResponse(message=serializer.errors).get_failure_response()

colleges = data.get('college')
colleges = data.get('colleges')
errors = {}
error = False
not_found_colleges = []
Expand Down Expand Up @@ -267,7 +267,7 @@ def get(self, request):
["full_name", "phone_number", "email", "role", "district", "zone"]
)

serializer = LaunchpadUserSerializer(
serializer = LaunchpadUserListSerializer(
paginated_queryset.get("queryset"), many=True
)
return CustomResponse().paginated_response(
Expand Down Expand Up @@ -297,7 +297,7 @@ def get(self, request, email):
user = LaunchPadUsers.objects.get(email=email)
except LaunchPadUsers.DoesNotExist:
return CustomResponse(general_message="User not found").get_failure_response()
serializer = LaunchpadUserSerializer(user)
serializer = LaunchpadUserListSerializer(user)
return CustomResponse(response=serializer.data).get_success_response()


Expand All @@ -308,7 +308,7 @@ def get(self, request):
if not LaunchPadUsers.objects.filter(email=auth_mail).exists():
return CustomResponse(general_message="Unauthorized").get_failure_response()
user = LaunchPadUsers.objects.get(email=auth_mail)
serializer = LaunchpadUserSerializer(user)
serializer = LaunchpadUserListSerializer(user)
return CustomResponse(data=serializer.data).get_success_response()

def put(self, request):
Expand Down Expand Up @@ -406,14 +406,14 @@ def post(self, request):

for data in excel_data[1:]:
not_found_colleges = []
data['college'] = data['college'].split(",") if data.get('college') else []
data['colleges'] = data['colleges'].split(",") if data.get('colleges') else []
serializer = LaunchpadUserSerializer(data=data)
if not serializer.is_valid():
continue
user = serializer.save()
if data.get('college') is None:
if data.get('colleges') is None:
continue
for college in data.get('college'):
for college in data.get('colleges'):
if not (org := Organization.objects.filter(title=college, org_type="College").first()):
error = True
not_found_colleges.append(college)
Expand Down
17 changes: 13 additions & 4 deletions api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CollegeDataSerializer(serializers.ModelSerializer):
class Meta:
model = Organization
fields = (
"id",
"title",
"district_name",
"state",
Expand All @@ -104,15 +105,15 @@ class Meta:
class LaunchpadUserSerializer(serializers.ModelSerializer):
id = serializers.CharField(max_length=36, read_only=True)
role = serializers.ChoiceField(choices=LaunchPadRoles.get_all_values())
college = serializers.ListField(child=serializers.CharField(), allow_empty=True, write_only=True)
colleges = serializers.SerializerMethodField()
colleges = serializers.ListField(child=serializers.CharField(), allow_empty=True, write_only=True)


class Meta:
model = LaunchPadUsers
fields = ("id", "full_name", "email", "phone_number", "role", "college", "district", "zone", "colleges")
fields = ("id", "full_name", "email", "phone_number", "role", "district", "zone", "colleges")

def create(self, validated_data):
validated_data.pop("college")
validated_data.pop("colleges")

validated_data["id"] = uuid.uuid4()
validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
Expand All @@ -121,6 +122,14 @@ def create(self, validated_data):

return user


class LaunchpadUserListSerializer(serializers.ModelSerializer):
colleges = serializers.SerializerMethodField()

class Meta:
model = LaunchPadUsers
fields = ("id", "full_name", "email", "phone_number", "role", "district", "zone", "colleges")

def get_colleges(self, obj):
return LaunchPadUserCollegeLink.objects.filter(user=obj).values_list("college_id", "college__title")

Expand Down

0 comments on commit 585de90

Please sign in to comment.