From 38055bcd23527a36d77468ce2dfd0b4766e7fc00 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 23 Jul 2019 12:26:38 +0400 Subject: =?UTF-8?q?=D0=91=D1=8D=D0=BA=D0=B5=D0=BD=D0=B4:=20=D0=94=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B,=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=85=20=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8F=D1=85=20=D1=81?= =?UTF-8?q?=D1=85=D0=B5=D0=BC=20=D0=B1=D0=B0=D0=B7=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Фронтенд: Добавлен компонент для показа всплывающих сообщений. --- day9/task5_vue/backend/database/validators.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'day9/task5_vue/backend/database/validators.py') diff --git a/day9/task5_vue/backend/database/validators.py b/day9/task5_vue/backend/database/validators.py index e4b7310..112af2b 100644 --- a/day9/task5_vue/backend/database/validators.py +++ b/day9/task5_vue/backend/database/validators.py @@ -32,8 +32,12 @@ class ValidateType(Validator): class ValidateLength(Validator): @staticmethod def validate(value, field_object): + if hasattr(field_object, 'is_variable_length') and not field_object.is_variable_length: + if len(str(value)) < field_object.max_length: + raise ValidationError('Value has too few characters') + if len(str(value)) > field_object.max_length: - raise ValidationError('Value has too many digits') + raise ValidationError('Value has too many characters') class ValidateTime(Validator): @@ -65,14 +69,14 @@ class ValidateDate(Validator): if year < 0: raise ValidationError('Wrong year value') - if month not in range(1, 12): + if month not in range(1, 12 + 1): raise ValidationError('Wrong month value') if month == 2: if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - febr_range = range(1, 29) + febr_range = range(1, 29 + 1) else: - febr_range = range(1, 28) + febr_range = range(1, 28 + 1) if day not in febr_range: raise ValidationError('Wrong day value') else: @@ -81,7 +85,7 @@ class ValidateDate(Validator): 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }.get(month) - if day not in range(1, days_count): + if day not in range(1, days_count + 1): raise ValidationError('Wrong day value') @@ -93,4 +97,4 @@ class ValidateDatetime(Validator): raise ValidationError('Wrong datetime format') else: ValidateDate.validate(datetime[0], {}) - ValidateTime.validate(datetime[1], {}) \ No newline at end of file + ValidateTime.validate(datetime[1], {}) -- cgit v1.2.3