def test_no_source_on_child(self): with pytest.raises(AssertionError) as exc_info: DateTimeRangeField(child=serializers.IntegerField(source='other')) assert str(exc_info.value) == ( "The `source` argument is not meaningful when applied to a `child=` field. " "Remove `source=` from the field declaration.")
class TestDateTimeRangeField(TestCase, FieldValues): """ Values for `ListField` with CharField as child. """ serializer_class = DateTimeRangeSerializer if compat.DateTimeTZRange is not None: valid_inputs = [ ({'lower': '2001-01-01T13:00:00Z', 'upper': '2001-02-02T13:00:00Z', 'bounds': '[)'}, compat.DateTimeTZRange( **{'lower': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=pytz.utc), 'upper': datetime.datetime(2001, 2, 2, 13, 00, tzinfo=pytz.utc), 'bounds': '[)'})), ({'upper': '2001-02-02T13:00:00Z', 'bounds': '[)'}, compat.DateTimeTZRange( **{'upper': datetime.datetime(2001, 2, 2, 13, 00, tzinfo=pytz.utc), 'bounds': '[)'})), ({'lower': '2001-01-01T13:00:00Z', 'bounds': '[)'}, compat.DateTimeTZRange( **{'lower': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=pytz.utc), 'bounds': '[)'})), ({'empty': True}, compat.DateTimeTZRange(**{'empty': True})), ({}, compat.DateTimeTZRange()), ] invalid_inputs = [ ({'lower': 'a'}, ['Datetime has wrong format. Use one of these' ' formats instead: ' 'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].']), ('not a dict', ['Expected a dictionary of items but got type "str".']), ] outputs = [ (compat.DateTimeTZRange( **{'lower': datetime.datetime(2001, 1, 1, 13, 00, tzinfo=pytz.utc), 'upper': datetime.datetime(2001, 2, 2, 13, 00, tzinfo=pytz.utc)}), {'lower': '2001-01-01T13:00:00Z', 'upper': '2001-02-02T13:00:00Z', 'bounds': '[)'}), (compat.DateTimeTZRange(**{'empty': True}), {'empty': True}), (compat.DateTimeTZRange(), {'bounds': '[)', 'lower': None, 'upper': None}), ] field = DateTimeRangeField() def test_no_source_on_child(self): with pytest.raises(AssertionError) as exc_info: DateTimeRangeField(child=serializers.IntegerField(source='other')) assert str(exc_info.value) == ( "The `source` argument is not meaningful when applied to a `child=` field. " "Remove `source=` from the field declaration." )
class AppointmentScheduleSerializer(serializers.ModelSerializer): class Meta: model = AppointmentSchedule fields = ('appointment', 'doctor', 'duration', 'adjust_30_min', ) doctor = DoctorSerializer() adjust_30_min = serializers.SerializerMethodField() appointment = AppointmentSerializer() duration = DateTimeRangeField() def get_adjust_30_min(self, obj): return obj.appointment.adjust_30_min
class ReserveAndHistorySerializer(serializers.ModelSerializer): customer_name = serializers.SerializerMethodField() stylist_name = serializers.SerializerMethodField() menu_name = serializers.SerializerMethodField() time = DateTimeRangeField() class Meta: model = ReserveAndHistory fields = ( 'id', 'customer', 'stylist', 'time', 'menu', 'rating', 'customer_name', 'stylist_name', 'menu_name', ) read_only_fields = ( 'id', 'customer_name', 'stylist_name', 'menu_name', ) extra_kwargs = { 'customer': { 'write_only': True }, 'stylist': { 'write_only': True }, 'menu': { 'write_only': True }, } def get_customer_name(self, instance): return instance.customer.customer.last_name + ' ' + instance.customer.customer.first_name def get_stylist_name(self, instance): return instance.stylist.stylist.last_name + ' ' + instance.stylist.stylist.first_name def get_menu_name(self, instance): return instance.menu.menu_name
class LogsReserveAndHistorySerializer(serializers.HyperlinkedModelSerializer): api = serializers.HyperlinkedIdentityField( view_name='reserve_and_history-detail') stylist_name = serializers.SerializerMethodField() stylist_info = serializers.SerializerMethodField() menu_info = serializers.SerializerMethodField() time = DateTimeRangeField() class Meta: model = ReserveAndHistory fields = ( 'stylist_name', 'rating', 'stylist_info', 'menu_info', 'time', 'api', ) def get_stylist_name(self, instance): return instance.stylist.stylist.last_name + ' ' + instance.stylist.stylist.first_name def get_stylist_info(self, instance): try: stylist_info = LogsStylistProfileSerializer( stylist_models.StylistProfile.objects.get( stylist=instance.stylist)).data return stylist_info except: stylist_info = None return stylist_info def get_menu_info(self, instance): try: menu_info = LogsMenuSerializer( stylist_models.Menu.objects.get(id=instance.menu.id)).data return menu_info except: menu_info = None return menu_info
class AccessRecordListSerializer(serializers.Serializer): token = serializers.CharField(required=True) date_ranges = DateTimeRangeField(required=True) location_list = serializers.ListField(child=serializers.CharField(max_length=200),required=False) labels = serializers.ListField(required=False,child=serializers.IntegerField(min_value=0)) distance_ranges = FloatRangeField(required=False)
class DateTimeRangeSerializer(serializers.Serializer): range = DateTimeRangeField()
class VoucherSerializer(serializers.ModelSerializer): during = DateTimeRangeField() class Meta: model = Voucher fields = ('code', 'value', 'during', 'created')
class RangeSerializer(serializers.ModelSerializer): time = DateTimeRangeField() class Meta: model = ReserveAndHistory fields = ('time', )