コード例 #1
0
class TenantGroupCreateSerializer(serializers.ModelSerializer):
    created_at = DateTimeFieldTZ('%d %B, %Y %I:%M %p', read_only=True)
    modified_at = DateTimeFieldTZ('%d %B, %Y %I:%M %p', read_only=True)

    class Meta:
        model = TenantGroup
        exclude = ('owner', )
コード例 #2
0
class TenantCurrentBookingSerializer(serializers.ModelSerializer):
    space = SpaceSerializer()
    license_start_date = DateTimeFieldTZ(format='%d %b, %Y')
    license_end_date = DateTimeFieldTZ(format='%d %b, %Y')

    class Meta:
        model = Booking
        fields = '__all__'
コード例 #3
0
ファイル: serializers.py プロジェクト: HalanxDev/Halanx-homes
class HouseVisitListSerializer(serializers.ModelSerializer):
    house = HouseBasicSerializer()
    customer = CustomerBasicSerializer()
    scheduled_visit_time = DateTimeFieldTZ()
    actual_visit_time = DateTimeFieldTZ()

    class Meta:
        model = HouseVisit
        fields = '__all__'
コード例 #4
0
class HouseVisitListSerializer(serializers.ModelSerializer):
    house = HouseBasicSerializer()
    customer = CustomerBasicSerializer()
    area_manager = AreaManagerSerializer()
    scheduled_visit_time = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')
    actual_visit_time = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')

    class Meta:
        model = HouseVisit
        fields = '__all__'
コード例 #5
0
class TenantPaymentSerializer(serializers.ModelSerializer):
    category = PaymentCategorySerializer()
    paid_on = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')
    due_date = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')
    transaction = CustomerTransactionSerializer(read_only=True)
    hcash = serializers.SerializerMethodField()

    class Meta:
        model = TenantPayment
        fields = '__all__'

    @staticmethod
    def get_hcash(obj):
        return obj.available_hcash
コード例 #6
0
class NewScoutTaskNotificationSerializer(serializers.ModelSerializer):
    scheduled_at = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT)
    category = ScoutTaskCategorySerializer()

    class Meta:
        model = ScoutTask
        fields = ('id', 'category', 'scheduled_at')
コード例 #7
0
class OwnerPaymentSerializer(serializers.ModelSerializer):
    category = PaymentCategorySerializer()
    paid_on = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')

    class Meta:
        model = OwnerPayment
        fields = ('id', 'category', 'type', 'paid_on', 'amount', 'description')
コード例 #8
0
class TenantSerializer(serializers.ModelSerializer):
    permanent_address = TenantPermanentAddressDetailSerializer()
    company_address = TenantCompanyAddressDetailSerializer()
    company_joining_date = DateTimeFieldTZ(format='%d %b, %Y',
                                           input_formats=['%d-%m-%Y'])
    company_leaving_date = DateTimeFieldTZ(format='%d %b, %Y',
                                           input_formats=['%d-%m-%Y'])
    bank_detail = TenantBankDetailSerializer()
    current_stay = serializers.CharField()
    current_booking = serializers.SerializerMethodField()
    dob = serializers.SerializerMethodField()

    class Meta:
        model = Tenant
        fields = '__all__'

    @staticmethod
    def get_dob(obj):
        return obj.customer.dob

    def update(self, instance: Tenant, validated_data):
        permanent_address_data = validated_data.pop('permanent_address', None)
        company_address_data = validated_data.pop('company_address', None)
        bank_detail_data = validated_data.pop('bank_detail', None)
        super(self.__class__, self).update(instance, validated_data)
        if permanent_address_data:
            permanent_address_serializer = TenantPermanentAddressDetailSerializer(
            )
            super(TenantPermanentAddressDetailSerializer, permanent_address_serializer) \
                .update(instance.permanent_address, permanent_address_data)
        if company_address_data:
            company_address_serializer = TenantCompanyAddressDetailSerializer()
            super(TenantCompanyAddressDetailSerializer, company_address_serializer) \
                .update(instance.company_address, company_address_data)
        if bank_detail_data:
            bank_detail_serializer = TenantBankDetailSerializer()
            super(TenantBankDetailSerializer,
                  bank_detail_serializer).update(instance.bank_detail,
                                                 bank_detail_data)
        return instance

    @staticmethod
    def get_current_booking(obj):
        booking = obj.current_booking
        if booking:
            return TenantCurrentBookingSerializer(booking).data
コード例 #9
0
class OwnerHouseDetailSerializer(OwnerHouseListSerializer):
    accomodation_allowed_str = serializers.ReadOnlyField()
    agreement_commencement_date = DateTimeFieldTZ(format='%d %b, %Y')

    class Meta:
        model = House
        fields = ('id', 'name', 'visible', 'cover_pic_url',
                  'accomodation_allowed_str', 'agreement_commencement_date')
コード例 #10
0
class OwnerHouseBookingSerializer(serializers.ModelSerializer):
    tenant_name = serializers.SerializerMethodField()
    monthly_rent = serializers.SerializerMethodField()
    license_start_date = DateTimeFieldTZ(format='%d %b, %Y')
    license_end_date = DateTimeFieldTZ(format='%d %b, %Y')

    class Meta:
        model = Booking
        fields = ('id', 'tenant_name', 'license_start_date',
                  'license_end_date', 'moved_out', 'monthly_rent')

    @staticmethod
    def get_tenant_name(obj):
        return obj.tenant.name

    @staticmethod
    def get_monthly_rent(obj):
        return obj.monthly_rents.last().rent
コード例 #11
0
class TenantRequirementSerializer(serializers.ModelSerializer):
    expected_movein_date = DateTimeFieldTZ(format='%Y-%m-%d',
                                           input_formats=['%d-%m-%Y'],
                                           required=False)

    class Meta:
        model = TenantRequirement
        exclude = (
            'created_at',
            'tenant',
        )
コード例 #12
0
class WithdrawalRequestSerializer(serializers.ModelSerializer):
    created_at = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p', read_only=True)
    status = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = WithdrawalRequest
        fields = '__all__'

    @staticmethod
    def get_status(obj):
        return obj.status
コード例 #13
0
class TenantLateCheckInSerializer(serializers.ModelSerializer):
    tenant = serializers.SerializerMethodField()
    expected_checkin = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')

    class Meta:
        model = TenantLateCheckin
        fields = '__all__'

    @staticmethod
    def get_tenant(obj):
        return TenantDetailSerializer(obj.current_booking.tenant,
                                      display_fields=['id', 'customer']).data
コード例 #14
0
class ScheduledAvailabilitySerializer(serializers.ModelSerializer):
    start_time = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT,
                                 input_formats=[DATETIME_SERIALIZER_FORMAT])
    end_time = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT,
                               input_formats=[DATETIME_SERIALIZER_FORMAT])

    class Meta:
        model = ScheduledAvailability
        exclude = (
            'cancelled',
            'created_at',
            'updated_at',
        )
        read_only_fields = ('scout', )

    def validate(self, data):
        """
        Check the validity of start and end time
        """
        scout = get_object_or_404(Scout, user=self.context['request'].user)

        if data.get('start_time') and data['start_time'] < timezone.now():
            raise serializers.ValidationError(
                {'error': "start time should be greater than current time"})
        elif data.get('end_time') and data['end_time'] < timezone.now():
            raise serializers.ValidationError(
                {'error': "end time should be greater than current time"})
        elif data.get('start_time') and data.get(
                'end_time') and data['start_time'] > data['end_time']:
            raise serializers.ValidationError(
                {'error': "end time must occur after start time"})
        elif scout.scheduled_availabilities.filter(
                cancelled=False,
                start_time__lte=data['start_time'],
                end_time__gte=data['end_time']).count():
            raise serializers.ValidationError(
                "A scheduled availability already exists in given time range")

        return data
コード例 #15
0
class AdvanceBookingDetailSerializer(serializers.ModelSerializer):
    expected_movein_date = serializers.DateField(format="%d %b, %Y",
                                                 input_formats=['%d-%m-%Y'])
    created_at = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')
    modified_at = DateTimeFieldTZ(format='%d %b, %Y %I:%M %p')
    space_subtype = serializers.SerializerMethodField()
    accomodation_for = serializers.SerializerMethodField()

    class Meta:
        model = AdvanceBooking
        fields = '__all__'

    @staticmethod
    def get_space_subtype(obj):
        return obj.space_subtype.name

    @staticmethod
    def get_space_type(obj):
        return obj.get_space_type_display()

    @staticmethod
    def get_accomodation_for(obj):
        return obj.accomodation_for_str
コード例 #16
0
class ScoutNotificationSerializer(serializers.ModelSerializer):
    timestamp = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT)
    category = ScoutNotificationCategorySerializer()
    payload = serializers.SerializerMethodField()

    class Meta:
        model = ScoutNotification
        fields = '__all__'

    @staticmethod
    def get_payload(obj):
        try:
            return json.loads(json.dumps(obj.payload))
        except:
            return obj.payload
コード例 #17
0
class NotificationListSerializer(serializers.ModelSerializer):
    image = serializers.SerializerMethodField()
    timestamp = DateTimeFieldTZ()

    class Meta:
        model = Notification
        fields = ('target', 'category', 'content', 'timestamp', 'image',
                  'payload')

    @staticmethod
    def get_image(obj):
        notif_image = NotificationImage.objects.filter(
            category=obj.category).first()
        return notif_image.image.url if notif_image else None

    @staticmethod
    def get_timestamp(obj):
        return get_natural_datetime(obj.timestamp)
コード例 #18
0
class TenantMoveOutRequestSerializer(serializers.ModelSerializer):
    timing = DateTimeFieldTZ(format='%d %b, %Y')

    class Meta:
        model = TenantMoveOutRequest
        exclude = ('created_at', )

    @staticmethod
    def validate_timing(timings):
        if timings < timezone.now():
            raise serializers.ValidationError(
                'Requested Move out timings must be in future')
        return timings

    @staticmethod
    def validate_tenant(tenant):
        if not tenant.current_booking:
            raise serializers.ValidationError('You don\'t have any booking')
        return tenant
コード例 #19
0
class MessageSerializer(serializers.ModelSerializer):
    role = serializers.SerializerMethodField()
    created_at = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT,
                                 read_only=True)
    task_id = serializers.SerializerMethodField()
    customer_name = serializers.SerializerMethodField()

    class Meta:
        model = Message
        fields = ('id', 'created_at', 'is_read', 'read_at', 'content', 'role',
                  'conversation', 'task_id', 'customer_name')

    @staticmethod
    def get_task_id(obj):
        try:
            from scouts.api.serializers import ScoutTaskDetailSerializer
            return obj.conversation.task.id
        except Exception as E:
            sentry_debug_logger.error(str(E), exc_info=True)
            return None

    @staticmethod
    def get_customer_name(obj):
        try:
            return obj.conversation.participants.filter(
                type=TYPE_CUSTOMER).first().name
        except:
            return None

    def get_role(self, obj):
        if obj.sender == self.context['requesting_participant']:
            return ROLE_SENDER
        elif obj.sender == obj.conversation.other_participant(
                self.context['requesting_participant']):
            return ROLE_RECEIVER

        elif self.context['requesting_participant'].type == TYPE_SCOUT:
            # multiple scout participants possible. All of them sender if not original sender
            return ROLE_SENDER
        else:
            return ROLE_RECEIVER
コード例 #20
0
class HouseVisitSerializer(serializers.ModelSerializer):
    scheduled_visit_time = DateTimeFieldTZ(format='%d %B %Y %I:%M %p', input_formats=['%d %B %Y %I:%M %p'])

    class Meta:
        model = HouseVisit
        fields = '__all__'
コード例 #21
0
class PictureSerializer(serializers.ModelSerializer):
    timestamp = DateTimeFieldTZ(read_only=True)

    class Meta:
        model = Picture
        exclude = ('is_deleted',)
コード例 #22
0
class ScoutTaskListSerializer(serializers.ModelSerializer):
    scheduled_at = DateTimeFieldTZ(format=DATETIME_SERIALIZER_FORMAT)
    category = ScoutTaskCategorySerializer()
    house = serializers.SerializerMethodField()
    space = serializers.SerializerMethodField()
    customer = serializers.SerializerMethodField()
    scout_data = serializers.SerializerMethodField()
    custom_data = serializers.SerializerMethodField(
    )  # variable json depending on task type

    class Meta:
        model = ScoutTask
        fields = ('id', 'scout', 'category', 'earning', 'scheduled_at',
                  'house', 'space', 'customer', 'conversation', 'scout_data',
                  'custom_data')

    @staticmethod
    def get_scout_data(obj):
        return ScoutDetailSerializer(obj.scout).data

    @staticmethod
    def get_house(obj):
        house = House.objects.using(
            settings.HOMES_DB).filter(id=obj.house_id).first()
        if house:
            return HouseSerializer(house).data

    @staticmethod
    def get_space(obj):
        if obj.booking_id:
            booking = Booking.objects.using(
                settings.HOMES_DB).filter(id=obj.booking_id).first()
            if booking:
                space = booking.space
                return SpaceSerializer(space).data

    @staticmethod
    def get_customer(obj):
        customer = None
        if obj.visit_id:
            visit = HouseVisit.objects.using(
                settings.HOMES_DB).filter(id=obj.visit_id).first()
            if visit:
                customer = visit.customer
        elif obj.booking_id:
            booking = Booking.objects.using(
                settings.HOMES_DB).filter(id=obj.booking_id).first()
            if booking:
                customer = booking.tenant.customer

        if customer:
            return CustomerSerializer(customer).data

    @staticmethod
    def get_custom_data(obj):
        if obj.category.name == PROPERTY_ONBOARDING:
            from scouts.sub_tasks.models import PropertyOnBoardingDetail
            prop_on_board_detail = PropertyOnBoardingDetail.objects.filter(
                id=obj.onboarding_property_details_id).first()
            if prop_on_board_detail:
                return PropertyOnboardingDetailSerializer(
                    prop_on_board_detail).data

        return None