Browse Source

feat(user): add saved_location field to UserProfileSerializer

- Introduced a new SerializerMethodField `saved_location` to retrieve the user's last known location from their location history.
- Updated the fields and read_only_fields in UserProfileSerializer to include `saved_location` for enhanced user profile data.
- Adjusted permission classes in CalendarList and AdjustmentConfigView to AllowAny for broader access.
master
mortezaei 7 months ago
parent
commit
733c6c7f8b
  1. 19
      apps/account/serializers/user.py
  2. 6
      apps/dobodbi_calendar/views.py

19
apps/account/serializers/user.py

@ -20,11 +20,26 @@ class UserProfileSerializer(serializers.ModelSerializer):
help_text="Select the user's gender."
)
fcm = serializers.CharField(required=False, help_text="Firebase Cloud Messaging token.")
saved_location = serializers.SerializerMethodField()
class Meta:
model = User
fields = ['id', 'device_id', 'fcm', 'fullname', 'slug', 'avatar', 'email', 'phone_number', 'password', 'info', 'skill', 'city', 'country', 'birthdate', 'gender']
read_only_fields = ['email', 'info', 'skill', 'device_id', 'slug']
fields = ['id', 'device_id', 'fcm', 'fullname', 'slug', 'avatar', 'email', 'phone_number', 'password', 'info', 'skill', 'city', 'country', 'birthdate', 'gender', 'saved_location']
read_only_fields = ['email', 'info', 'skill', 'device_id', 'slug', 'saved_location']
def get_saved_location(self, obj):
last_location = obj.location_history.order_by('-at_time').first()
if last_location:
return {
'lat': last_location.lat,
'lon': last_location.lon,
'city': last_location.city,
'country': last_location.country,
'timezone': last_location.timezone,
'selected_manually': last_location.selected_manually,
'at_time': last_location.at_time,
}
return None
# def validate_email(self, value):
# if User.objects.filter(email=value).exists():

6
apps/dobodbi_calendar/views.py

@ -8,7 +8,7 @@ from django.db.models import Q
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView, status
@ -22,7 +22,7 @@ class CalendarList(ListAPIView):
serializer_class = CalendarSerializer
pagination_class = None
permission_classes = (IsAuthenticated,)
permission_classes = (AllowAny,)
# @method_decorator(cache_page(60 * 15)) # Cache for 1 Hour
# def dispatch(self, *args, **kwargs):
@ -59,6 +59,8 @@ class CalendarList(ListAPIView):
class AdjustmentConfigView(APIView):
permission_classes = (AllowAny,)
def get(self, request):
adjustment_config = get_config('calendar__Adjustment')
return Response(json.loads(adjustment_config))
Loading…
Cancel
Save