Skip to content

Commit

Permalink
Merge pull request #1384 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
minor fix
  • Loading branch information
adnankattekaden authored Oct 21, 2023
2 parents fb7352e + e382320 commit f4e7e20
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 37 deletions.
76 changes: 48 additions & 28 deletions api/dashboard/location/location_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ class Meta:
model = Country
fields = ["label"]

def create(self, validated_data):
validated_data['id'] = str(uuid.uuid4())
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)

def update(self, instance, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = self.context.get("user_id")

return super().update(instance, validated_data)

def create(self, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)
def validate_label(self, country):
country_obj = Country.objects.filter(name=country).first()
if country_obj:
raise serializers.ValidationError('Country with this name is already exists')
return country


class StateRetrievalSerializer(serializers.ModelSerializer):
Expand All @@ -55,19 +60,24 @@ class Meta:
model = State
fields = ["label", "country"]

def create(self, validated_data):
validated_data['id'] = str(uuid.uuid4())
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)

def update(self, instance, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = self.context.get("user_id")

return super().update(instance, validated_data)

def create(self, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)
def validate_label(self, state):
state_obj = State.objects.filter(name=state).first()
if state_obj:
raise serializers.ValidationError("State with this name is already exists")
return state


class ZoneRetrievalSerializer(serializers.ModelSerializer):
Expand All @@ -87,19 +97,24 @@ class Meta:
model = Zone
fields = ["label", "state"]

def create(self, validated_data):
validated_data['id'] = str(uuid.uuid4())
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)

def update(self, instance, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = self.context.get("user_id")

return super().update(instance, validated_data)

def create(self, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)
def validate_label(self, zone):
zone_obj = Zone.objects.filter(name=zone).first()
if zone_obj:
raise serializers.ValidationError("Zone with this name is already exists")
return zone


class DistrictRetrievalSerializer(serializers.ModelSerializer):
Expand All @@ -119,16 +134,21 @@ class Meta:
model = District
fields = ["label", "zone"]

def create(self, validated_data):
validated_data['id'] = str(uuid.uuid4())
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)

def update(self, instance, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = self.context.get("user_id")

return super().update(instance, validated_data)

def create(self, validated_data):
validated_data['id'] = uuid.uuid4()
validated_data["updated_at"] = validated_data["created_at"] = DateTimeUtils.get_current_utc_time()
validated_data["updated_by_id"] = validated_data["created_by_id"] = self.context.get("user_id")

return super().create(validated_data)
def validate_label(self, district):
district_obj = District.objects.filter(name=district).first()
if district_obj:
raise serializers.ValidationError("District with this name is already exists")
return district
17 changes: 8 additions & 9 deletions api/dashboard/location/location_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def post(self, request):
"user_id": user_id
}
)

if serializer.is_valid():
serializer.save()
return CustomResponse(
general_message=serializer.data
general_message="Country created Successfully"
).get_success_response()

return CustomResponse(
Expand All @@ -80,7 +79,7 @@ def patch(self, request, country_id):
serializer.save()

return CustomResponse(
general_message=serializer.data
general_message="Country edited successfully"
).get_success_response()

return CustomResponse(
Expand Down Expand Up @@ -148,7 +147,7 @@ def post(self, request):
serializer.save()

return CustomResponse(
general_message=serializer.data
general_message="State created successfully"
).get_success_response()

return CustomResponse(
Expand Down Expand Up @@ -176,7 +175,7 @@ def patch(self, request, state_id):
).get_success_response()

return CustomResponse(
general_message=serializer.errors
general_message="State edited successfully"
).get_failure_response()

@role_required([RoleType.ADMIN.value])
Expand Down Expand Up @@ -241,7 +240,7 @@ def post(self, request):
serializer.save()

return CustomResponse(
general_message=serializer.data
general_message="Zone created successfully"
).get_success_response()

return CustomResponse(
Expand All @@ -265,7 +264,7 @@ def patch(self, request, zone_id):
serializer.save()

return CustomResponse(
general_message=serializer.data
general_message="zone edited successfully"
).get_success_response()

return CustomResponse(
Expand Down Expand Up @@ -338,7 +337,7 @@ def post(self, request):
).get_success_response()

return CustomResponse(
general_message=serializer.errors
general_message="Zone created successfully"
).get_failure_response()

@role_required([RoleType.ADMIN.value])
Expand All @@ -358,7 +357,7 @@ def patch(self, request, district_id):
serializer.save()

return CustomResponse(
general_message=serializer.data
general_message="Zone edited successfully"
).get_success_response()

return CustomResponse(
Expand Down

0 comments on commit f4e7e20

Please sign in to comment.