You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
from rest_framework import serializers
|
|
|
|
from apps.dobodbi_calendar.models import CalendarOccasions
|
|
|
|
|
|
class CalendarSerializer(serializers.ModelSerializer):
|
|
type = serializers.CharField(source='occasion_type')
|
|
dates = serializers.SerializerMethodField()
|
|
title = serializers.SerializerMethodField()
|
|
|
|
def get_title(self, obj):
|
|
request = self.context.get('request')
|
|
from apps.hadis.serializers.category import get_localized_text
|
|
return get_localized_text(obj.title, request=request)
|
|
|
|
|
|
# def get_countries(self, obj):
|
|
# if not obj.countries or obj.countries[0] == 'ALL':
|
|
# return ["All"]
|
|
|
|
# return [country.name or country.code for country in obj.countries]
|
|
|
|
# def get_holiday_in_countries(self, obj):
|
|
# return [country.name or country.code for country in obj.holiday_in_countries]
|
|
|
|
def get_dates(self, obj):
|
|
dates = []
|
|
for date in obj.dates:
|
|
dates.append({
|
|
'day': str(date['day']),
|
|
'month': str(date['month']),
|
|
'year': str(date.get('year', '')),
|
|
})
|
|
return dates
|
|
|
|
|
|
class Meta:
|
|
model = CalendarOccasions
|
|
fields = ('id', 'title', 'type', 'event_type', 'dates', 'is_yearly',)
|