コード例 #1
0
ファイル: serializers.py プロジェクト: decibyte/drf-haystack
 def multi_serializer_representation(self, instance):
     serializers = self.Meta.serializers
     index = instance.searchindex
     serializer_class = serializers.get(type(index), None)
     if not serializer_class:
         raise ImproperlyConfigured("Could not find serializer for %s in mapping" % index)
     return serializer_class(context=self._context).to_representation(instance)
コード例 #2
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     serializers = super(PackageTourFeeSerializer, self).to_native(obj)
     hotel_info = dict()
     if serializers.get('hotel_rooms'):
         hotel = Hotel.objects.filter(id=serializers['hotel_rooms'][0]['room_info']['hotel']).first()
         hotel_info = HotelSerializer(hotel).data
         hotel_info.update({'price': serializers['hotel_rooms'][0]['price']})
         golfcourse_id = []
         for item in obj.package_golfcourse.all():
             golfcourse_id.append(item.package_golfcourse.golfcourse.id)
         hotel_distance = HotelGolfcourseDistance.objects.filter(hotel=hotel,golfcourse__in=golfcourse_id)
         distances = HotelGolfcourseDistanceSerializer(hotel_distance).data
         hotel_info.update({'distances':distances})
         rooms = dict()
         for i, item in enumerate(serializers['hotel_rooms']):
             room_type = item['room_info']['name'].split()[0]
             if room_type not in rooms:
                 rooms.update({room_type: [item]})
             else:
                 rooms[room_type].append(item)
         hotel_rooms = []
         for k in rooms:
             item = rooms[k][0].copy()
             item['upgrades'] = rooms[k]
             hotel_rooms.append(item)
         serializers['hotel_rooms'] = hotel_rooms
     serializers.update({'hotel': hotel_info})
     return serializers
コード例 #3
0
 def multi_serializer_representation(self, instance):
     serializers = self.Meta.serializers
     index = instance.searchindex
     serializer_class = serializers.get(type(index), None)
     if not serializer_class:
         raise ImproperlyConfigured("Could not find serializer for %s in mapping" % index)
     return serializer_class(context=self._context).to_representation(instance)
コード例 #4
0
 def get_images(self, gallery):
     data = gallery.stream.raw_data
     serializers = get_stream_field_serializers()
     for item in data:
         cls = serializers.get(item['type'])
         assert cls is not None, ('%s serializers is not registered.' %
                                  item['type'])
         yield cls(item['value']).data
コード例 #5
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
    def to_native(self, obj):
        if obj:
            serializers = super(GolfCourseEventSerializer, self).to_native(obj)
            if obj.tee_type:
                serializers.update({'tee_color': obj.tee_type.color,
                                    'subgolfcourse': obj.tee_type.subgolfcourse.id,
                                    'subgolfcourse_name': obj.tee_type.subgolfcourse.name})
            if obj.pass_code:
                serializers.update({'has_pass': True})
            else:
                serializers.update({'has_pass': False})
            user_profile = UserProfile.objects.only('display_name').get(user_id=obj.user_id)
            golfcourse = GolfCourse.objects.only('name').get(id=obj.golfcourse_id)
            serializers.update({'display_name': user_profile.display_name,
                                'golfcourse_name': golfcourse.name})
            del serializers['pass_code']

            ###
            serializers_add = AdvertiseEventSerializer(obj)

            func_time = lambda x: datetime.datetime.strptime(x, "%Y-%m-%d").replace(tzinfo=utc).isoformat()

            if serializers_add.data.get('contact_phone'):
                serializers.update({"register_info": user_profile.display_name + " -- " + serializers_add.data.get('contact_phone')})
            else:
                serializers.update({"register_info": user_profile.display_name})

            serializers.update({
                "event_price_info" : serializers_add.data.get('event_price_info'),
                "contact_email": serializers_add.data.get('contact_email'),
                "contact_phone": serializers_add.data.get('contact_phone'),
                "date_start": func_time(str(serializers.get('date_start'))),
                "date_end": func_time(str(serializers.get('date_end'))),
                "view_count": serializers_add.data.get('view_count'),
                "join_count": serializers_add.data.get('join_count'),
                "like_count": serializers_add.data.get('like_count')
            })

            return serializers
コード例 #6
0
from django.conf import settings
from .utils import import_callable, default_create_token
from rest_framework import serializers
from .ser import (PasswordResetSerializer as DefaultPasswordResetSerializer,
                  PasswordResetConfirmSerializer as
                  DefaultPasswordResetConfirmSerializer,
                  PasswordChangeSerializer as DefaultPasswordChangeSerializer)
serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})
PasswordResetSerializer = import_callable(
    serializers.get('PASSWORD_RESET_SERIALIZER',
                    DefaultPasswordResetSerializer))

PasswordResetConfirmSerializer = import_callable(
    serializers.get('PASSWORD_RESET_CONFIRM_SERIALIZER',
                    DefaultPasswordResetConfirmSerializer))

PasswordChangeSerializer = import_callable(
    serializers.get('PASSWORD_CHANGE_SERIALIZER',
                    DefaultPasswordChangeSerializer))