コード例 #1
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
	def to_native(self, obj):
		if obj is not None:
			serializers = {}
			checkin = 0
			if obj.status == 'I':
				checkin = 1
			book_partner = obj.book_partner.all()[0]
			customer_name = book_partner.customer.name
			customer_phone = book_partner.customer.phone_number
			customer_email = book_partner.customer.email
			player_count = obj.player_count if checkin == 0 else obj.player_checkin_count
			serializers.update({
				'id': obj.id,
				'created' : round(obj.created.timestamp() * 1000),
				'teetime_date' : datetime.datetime.combine(obj.teetime.date, datetime.datetime.min.time()).timestamp() * 1000,
				'teetime_time' : datetime.timedelta(hours=obj.teetime.time.hour,minutes=obj.teetime.time.minute).total_seconds() * 1000,
				'customer_name': customer_name,
				'customer_phone': customer_phone,
				'customer_email': customer_email,
				'golfcourse_name': obj.golfcourse.name,
				'teetime_id' : obj.teetime.id,
				'player_count': player_count,
				'checkin': checkin,
				'hole': obj.hole,
				'discount': obj.discount
			})
			return serializers
コード例 #2
0
ファイル: serializers.py プロジェクト: minhdo6487/sunsip
 def to_native(self, obj):
     if obj:
         serializers = super(GroupMemberSerializer, self).to_native(obj)
         user = UserDisplaySerializer(obj.user)
         serializers.update(user.data)
         serializers.update({'date_joined': obj.date_joined})
         return serializers
コード例 #3
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj:
         serializers = super(GolfCourseEventHotelInfoSerializer, self).to_native(obj)
         if obj.hotel:
             serializers.update({'hotel_name': obj.hotel.name,
                                 'hotel_address': obj.hotel.address})
         return serializers
コード例 #4
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
    def to_native(self, obj):
        if obj:
            serializers = super(AdvertiseEventSerializer, self).to_native(obj)
            date = obj.date_start
            delta = date - TODAY
            night_no = obj.date_end - obj.date_start
            serializers.update({
                'day': int(date.strftime('%d')),
                'month': date.strftime('%b'),
                'time': date.strftime('%A , %B %d %Y'),
                'day_left': delta.days,
                'night': night_no.days})
            ctype = ContentType.objects.get_for_model(GolfCourseEvent)
            try:
                view = View.objects.only('count').get(content_type=ctype, object_id=obj.id)
                view_count = view.count
            except Exception:
                view_count = 0
            like_count = Like.objects.filter(content_type=ctype, object_id=obj.id).aggregate(Sum('count'))['count__sum']
            if not like_count:
                like_count = 0
            join_count = EventMember.objects.filter(event=obj, customer__isnull=True).count()
            comment_count = Comment.objects.filter(content_type=EVENT_CTYPE, object_id=obj.id).count()

            serializers.update({
                'like_count': like_count,
                'view_count': view_count,
                'join_count': join_count,
                'comment_count': comment_count,
                'discount_pay_later': 5,
                'discount_pay_now': 10
            })
            return serializers
コード例 #5
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(GolfCourseReviewSerializer,
                             self).to_native(obj)
         user_seri = UserDisplaySerializer(obj.user)
         gc_review_ctype = ContentType.objects.get_for_model(
             GolfCourseReview)
         like_count = Like.objects.filter(content_type=gc_review_ctype,
                                          object_id=obj.id).aggregate(
                                              Sum('count'))['count__sum']
         if not like_count:
             like_count = 0
         (count, uread) = get_from_xmpp('', obj.id)
         golfcourse_review_count = GolfCourseReview.objects.filter(
             golfcourse=obj.golfcourse).count()
         golfcourse_rating = obj.golfcourse.rating
         serializers.update({
             'user_info': user_seri.data,
             'like_count': like_count,
             'comment_count': count,
             'golfcourse_review_count': golfcourse_review_count,
             'golfcourse_rating': golfcourse_rating,
             'golfcourse_name': obj.golfcourse.name
         })
         return serializers
コード例 #6
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
コード例 #7
0
	def to_native(self, obj):
		if obj is not None:
			serializers = super(MyBookingSerializer_v2, self).to_native(obj)
			golfcourse_name = obj.golfcourse.name

			cus_id = BookedPartner.objects.filter(bookedteetime_id = int(obj.id) ).values('customer_id')  
			
			event_member_id = list(EventMember.objects.filter(customer_id__exact = cus_id).values('id'))
			
			booked_gc_event_info = []
			if event_member_id != []:
				key =  (event_member_id[0]['id'])
				booked = BookedGolfcourseEvent.objects.filter(member_id__exact = key)
				res = GC_Booking_Detail_Serializer(booked)
				booked_gc_event_info = res.data 


			serializers.update({
				'golfcourse_name': golfcourse_name,
				'teetime_date' : obj.teetime.date,
				'teetime_time' : obj.teetime.time,
				'booked_gc_event_info': booked_gc_event_info

			})
			return serializers
コード例 #8
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     serializers = super(PackageAdditionalFeeSerializer, self).to_native(obj)
     service = ServiceSerializer(obj.service)
     serializers.update({'service_info': service.data})
     serializers['price'] = int(serializers['price'])
     del serializers['gc_price']
     del serializers['package_service']
     return serializers
コード例 #9
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj:
         serializers = super(FullGolfCourseSerializer, self).to_native(obj)
         subgolfcourse = obj.subgolfcourse.all()
         subgolfcourse_serializer = SubGolfCourseSerializer(subgolfcourse)
         serializers.update(
             {'subgolfcourse': subgolfcourse_serializer.data})
         return serializers
コード例 #10
0
 def to_native(self, obj):
     if obj is not None:
         serializers = super(HoleTeeSerializer, self).to_native(obj)
         tt = TeeType.objects.only('color').get(id=obj.tee_type_id)
         serializers.update({
             'color': tt.color
         })
         return serializers
コード例 #11
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
	def to_native(self, obj):
		if obj is not None:
			serializers = super(BookingClubSetSerializer, self).to_native(obj)
			name = obj.clubset.clubset.name
			serializers.update({
				'name': name
			})
			return serializers
コード例 #12
0
    def get_models(self, apis):
        """
        Builds a list of Swagger 'models'. These represent
        DRF serializers and their fields
        """
        serializers = self._get_serializer_set(apis)
        serializers.update(self.explicit_serializers)
        serializers.update(
            self._find_field_serializers(serializers)
        )

        models = {}

        for serializer in serializers:
            data = self._get_serializer_fields(serializer)

            # Register 2 models with different subset of properties suitable
            # for data reading and writing.
            # i.e. rest framework does not output write_only fields in response
            # or require read_only fields in complex input.

            serializer_name = IntrospectorHelper.get_serializer_name(serializer)
            # Writing
            # no readonly fields
            w_name = "Write{serializer}".format(serializer=serializer_name)

            w_properties = OrderedDict((k, v) for k, v in data['fields'].items()
                                       if k not in data['read_only'])

            models[w_name] = {
                'id': w_name,
                'required': [i for i in data['required'] if i in w_properties.keys()],
                'properties': w_properties,
            }

            # Reading
            # no write_only fields
            r_name = serializer_name

            r_properties = OrderedDict((k, v) for k, v in data['fields'].items()
                                       if k not in data['write_only'])

            models[r_name] = {
                'id': r_name,
                'required': [i for i in r_properties.keys()],
                'properties': r_properties,
            }

            # Enable original model for testing purposes
            # models[serializer_name] = {
            #     'id': serializer_name,
            #     'required': data['required'],
            #     'properties': data['fields'],
            # }

        models.update(self.explicit_response_types)
        models.update(self.fields_serializers)
        return models
コード例 #13
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     serializers = super(PackageTourReviewSerializer, self).to_native(obj)
     name = serializers['name']
     pic = None
     if obj.user:
         name = obj.user.user_profile.display_name
         pic = obj.user.user_profile.profile_picture
     serializers.update({'name': name, 'pic': pic})
     return serializers
コード例 #14
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(PackageGolfcourseFeeSerializer, self).to_native(obj)
         serializers.update({'golfcourse_info': PlayStayGolfCourseSerializer(obj.package_golfcourse.golfcourse).data,
                             'package_golfcourse_info': PackageGolfCourseSerializer(obj.package_golfcourse).data})
         serializers['price'] = int(serializers['price'])
         del serializers['package_service']
         del serializers['gc_price']
         return serializers
コード例 #15
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
	def to_native(self, obj):
		if obj is not None:
			serializers = super(MyBookingSerializer, self).to_native(obj)
			golfcourse_name = obj.golfcourse.name
			serializers.update({
				'golfcourse_name': golfcourse_name,
				'teetime_date' : obj.teetime.date,
				'teetime_time' : obj.teetime.time
			})
			return serializers
コード例 #16
0
 def to_native(self, obj):
     if obj is not None:
         serializers = super(TeeTypeSerializer, self).to_native(obj)
         try:
             hole = Hole.objects.get(subgolfcourse=obj.subgolfcourse, holeNumber=1)
             holetee = HoleTee.objects.get(hole=hole, tee_type=obj)
             serializers.update({'yard': holetee.yard})
         except:
             serializers.update({'yard': 0})
         return serializers
コード例 #17
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
    def to_native(self, obj):
        serializers = super(PackageHotelRoomFeeSerializer, self).to_native(obj)
        room_info = HotelRoomSerializer(obj.hotel_room)
        serializers['price'] = int(serializers['price'])
        del room_info.data['id']
        del serializers['package_service']
        del serializers['gc_price']
        serializers.update({'room_info': room_info.data, 'upgrades': []})

        return serializers
コード例 #18
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(GroupOfEventSerializer, self).to_native(obj)
         is_delete = True
         if EventMember.objects.filter(group=obj).exists():
             is_delete = False
         serializers.update({
             'delete': is_delete
         })
         return serializers
コード例 #19
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(PlayStayGolfCourseSerializer,
                             self).to_native(obj)
         ctype = ContentType.objects.get_by_natural_key(
             'golfcourse', 'golfcourse')
         picture = Gallery.objects.filter(content_type=ctype.id,
                                          object_id=obj.id)
         serializers.update(
             {'pictures': GolfCourseGallerySerializer(picture).data})
         return serializers
コード例 #20
0
	def to_native(self, obj):
		if obj:
			serializers = super(GC_Booking_Serializer, self).to_native(obj)
			name = obj.member.customer.name
			email = obj.member.customer.email
			phone_number = obj.member.customer.phone_number
			serializers.update({
					'member': name,
					'email': email,
					'phone_number': phone_number
				})
			return serializers
コード例 #21
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(AdvertiseGolfCourse, self).to_native(obj)
         ctype = ContentType.objects.get_by_natural_key(
             'golfcourse', 'golfcourse')
         picture = Gallery.objects.filter(content_type=ctype.id,
                                          object_id=obj.id)
         if picture:
             pic_seri = GolfCourseGallerySerializer(picture[0])
             serializers.update({'picture': pic_seri.data['picture']})
         else:
             serializers.update({'picture': ''})
         return serializers
コード例 #22
0
 def to_native(self, obj):
     if obj:
         serializers = super(GameSerializer, self).to_native(obj)
         if serializers['score']:
             putts = [x['putt'] for x in serializers['score'] if x['putt']]
             sum_putt = sum(putts)
             serializers.update({'sum_putt': sum_putt})
         del serializers['group_link']
         del serializers['recorder']
         del serializers['content_type']
         del serializers['object_id']
         del serializers['event_member']
         return serializers
コード例 #23
0
 def to_native(self, obj):
     if obj is not None:
         serializers = super(UserChatQuerySerializer, self).to_native(obj)
         user_groupchat = UserGroupChat.objects.filter(
             user=obj.user, groupchat__group_id=obj.room_id).first()
         if user_groupchat:
             serializers.update({
                 'date_joined':
                 "{}Z".format(user_groupchat.date_joined.isoformat('T'))
             })
         serializers.update(
             {'modified_at': "{}Z".format(obj.modified_at.isoformat('T'))})
         return serializers
コード例 #24
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(UserDisplaySerializer, self).to_native(obj)
         display_name = obj.user_profile.display_name
         phone = obj.user_profile.mobile
         pic = obj.user_profile.profile_picture
         handicap_us = obj.user_profile.handicap_us
         description = obj.user_profile.description
         game = Game.objects.filter(event_member__user_id=obj.id,
                                    golfcourse__number_of_hole__gte=18,
                                    is_finish=True,
                                    active=True).aggregate(
                                        Avg('gross_score'))
         avg_stroke = 0
         if game['gross_score__avg']:
             avg_stroke = round(game['gross_score__avg'])
         if self.context.get('lat') and self.context.get('lon'):
             user_location = UserLocation.objects.filter(
                 user=obj).order_by('-modified_at').first()
             friend_distance = 'N/A'
             if user_location:
                 friend_distance = round(
                     distance.distance(
                         (user_location.lat, user_location.lon),
                         (self.context['lat'],
                          self.context['lon'])).kilometers, 2)
             serializers.update({'friend_distance': friend_distance})
         is_friend = False
         if self.context.get('user_id') and Friend.objects.filter(
                 from_user_id=self.context['user_id'],
                 to_user_id=obj.id).exists():
             is_friend = True
         is_block = False
         if self.context.get('user_id') and UserPrivacy.objects.filter(
                 user_id=self.context['user_id'], target_id=obj.id,
                 action='D').exists():
             is_block = True
         serializers.update({
             'name': display_name,
             'display_name': display_name,
             'phone_number': phone,
             'pic': pic,
             'handicap_us': handicap_us,
             'avg_stroke': avg_stroke,
             'avg_score': obj.user_profile.avg_score or 0,
             'description': description,
             'is_friend': is_friend,
             'is_block': is_block
         })
         return serializers
コード例 #25
0
    def to_native(self, obj):
        if obj is not None:
            event_ctype = ContentType.objects.get_for_model(GolfCourseEvent)
            serializers = super(NoticeSerializer, self).to_native(obj)
            soup_en = BeautifulSoup(obj.detail_en)
            soup_vi = BeautifulSoup(obj.detail)
            if obj.notice_type == 'I':
                if obj.content_type == event_ctype:
                    serializers.update({
                        'date_play':
                        obj.related_object.date_start,
                    })
                elif obj.related_object.date:
                    serializers.update({
                        'date_play': obj.related_object.date,
                    })

            elif obj.notice_type == 'FR':
                friend = obj.related_object
                user_friend = Friend.objects.filter(
                    from_user=friend.to_user).values_list('to_user', flat=True)
                mutual_friend = Friend.objects.filter(
                    from_user=friend.from_user,
                    to_user_id__in=user_friend).count()
                serializers.update({'mutual_friend': mutual_friend})

            else:
                serializers.update({
                    'plain_text': soup_en.text,
                    'plain_text_vi': soup_vi.text
                })
            if obj.from_user is not None:
                from_user_avatar = obj.from_user.user_profile.profile_picture
            else:
                from_user_avatar = '/assets/images/att04.png'
            serializers.update({
                'username':
                obj.from_user.user_profile.display_name,
                'plain_text':
                soup_en.text.replace(
                    obj.from_user.user_profile.display_name + ' ', ''),
                'plain_text_vi':
                soup_vi.text.replace(
                    obj.from_user.user_profile.display_name + ' ', ''),
                'from_user_avatar':
                from_user_avatar,
                'date_create':
                calendar.timegm(obj.date_create.timetuple())
            })
            return serializers
コード例 #26
0
    def _get_serializer_set(self, apis):
        """
        Returns a set of serializer classes for a provided list
        of APIs
        """
        serializers = set()

        for api in apis:
            serializer = self._get_serializer_class(api['callback'])
            if serializer is not None:
                serializers.add(serializer)
                serializers.update(self._get_nested_serializers(serializer))

        return serializers
コード例 #27
0
    def to_native(self, obj):
        if obj:
            if obj.is_hold and obj.hold_expire < datetime.datetime.utcnow().replace(tzinfo=utc):
                obj.is_hold = False
                obj.hold_expire = None
                obj.save()
            serializers = super(ArchivedTeetimeSerializer, self).to_native(obj)
            city = ''
            if obj.golfcourse.city:
                city = obj.golfcourse.city.name
            country = ''
            if obj.golfcourse.country:
                country = obj.golfcourse.country.name
            serializers.update({
                'teetime_id': obj.id,
                'golfcourse_id': obj.golfcourse.id,
                'golfcourse_name': obj.golfcourse.name or "",
                'golfcourse_short_name': obj.golfcourse.short_name or "",
                'golfcourse_address': obj.golfcourse.address or "",
                'golfcourse_country': country or "",
                'golfcourse_website':obj.golfcourse.website or "",
                'golfcourse_contact':obj.golfcourse.contact_info or ""
            })
            gtype = GuestType.objects.get(name='G')
            price = TeeTimePrice.objects.filter(teetime_id = obj.id, guest_type_id = gtype.id)
            ## Check Caddy will be show or not

            serializers['price'] = serializers['price_9'] = serializers['price_18'] = serializers['price_27'] = serializers['price_36'] = 0
            for p in price:
                if p.hole == 18:
                    serializers['price'] = serializers['price_18'] = p.price
                    serializers['discount'] = p.online_discount
                    serializers['discount_online'] = p.cash_discount
                    serializers['gifts'] = p.gifts or ""
                    serializers['food_voucher'] = p.food_voucher
                    serializers['buggy'] = p.buggy
                    serializers['caddy'] = p.caddy
                    serializers['rank'] = 0
                    if not p.teetime.available:
                        serializers['discount'] = p.online_discount
                    if not p.teetime.allow_payonline:
                        serializers['discount_online'] = 0
                elif p.hole == 9:
                    serializers['price_9'] = p.price
                elif p.hole == 27:
                    serializers['price_27'] = p.price
                elif p.hole == 36:
                    serializers['price_36'] = p.price
            return serializers
コード例 #28
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
	def to_native(self, obj):
		if obj is not None:
			serializers = super(BookingGolfcourseSerializer, self).to_native(obj)
			city = ''
			if obj.city:
				city = obj.city.id
			country = ''
			if obj.country:
				country = obj.country.name
			serializers.update({
				'city': city,
				'country' : country,
				'name': obj.short_name
			})
			return serializers
コード例 #29
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(ProfileSerializer, self).to_native(obj)
         # if obj.city:
         # city_name = obj.city.name
         #     serializers.update({'city_name': city_name})
         game = Game.objects.filter(event_member__user_id=obj.user_id,
                                    golfcourse__number_of_hole__gte=18,
                                    is_finish=True,
                                    active=True).aggregate(
                                        Avg('gross_score'))
         avg_stroke = 0
         if game['gross_score__avg']:
             avg_stroke = round(game['gross_score__avg'])
         serializers.update({'avg_stroke': avg_stroke})
         return serializers
コード例 #30
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj is not None:
         serializers = super(MultiCommentSeri, self).to_native(obj)
         ctype = ContentType.objects.get_for_model(obj)
         cmts = Comment.objects.filter(content_type=ctype.id,
                                       object_id=obj.id)
         cmts2 = MultiCommentSeri(cmts, many=True)
         serializers.update({'comment': cmts2.data})
         likes = Like.objects.filter(content_type=ctype, object_id=obj.id)
         likes2 = LikeSerializer(likes, many=True)
         serializers.update({'like_count': likes.count()})
         serializers.update({'likes': likes2.data})
         serializers.update(
             {'full_name': obj.user.user_profile.display_name})
         serializers.update(
             {'picture': obj.user.user_profile.profile_picture})
         return serializers
コード例 #31
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
 def to_native(self, obj):
     if obj:
         serializers = super(UserGameSerializer, self).to_native(obj)
         pic = None
         display_name = None
         if obj.event_member.user_id:
             user_profile = UserProfile.objects.only(
                 'display_name',
                 'profile_picture').get(user_id=obj.event_member.user_id)
             pic = user_profile.profile_picture
             display_name = user_profile.display_name
         elif obj.event_member.customer_id:
             customer = Customer.objects.get(
                 id=obj.event_member.customer_id)
             pic = customer.avatar
             display_name = customer.name
         serializers.update({'display_name': display_name, 'pic': pic})
         return serializers
コード例 #32
0
ファイル: serializers.py プロジェクト: minhdo6487/api-proto
	def to_native(self, obj):
		if obj:
			serializers = super(BookedGolfcourseEventSerializer, self).to_native(obj)
			try:
				name = obj.member.customer.name
				email = obj.member.customer.email
				phone_number = obj.member.customer.phone_number
			except Exception as e:
				name = obj.member.user.user_profile.display_name
				email = obj.member.user.email
				phone_number = obj.member.user.user_profile.mobile

			serializers.update({
					'member': name,
					'email': email,
					'phone_number': phone_number
				})
			return serializers