-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
51 lines (36 loc) · 1.6 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import datetime
from enum import Enum
from dataclasses import dataclass
from prompt_toolkit.validation import Validator, ValidationError
@dataclass
class ElectivesCategory:
class ElectivePlanType(Enum):
INCLUDED_IN_EDUCATION_PLAN_CURRENT = 'radioIncludedInEducationPlan'
INCLUDED_IN_EDUCATION_PLAN_OTHERS = 'radioIncludedInEducationPlanRest'
NOT_INCLUDED = 'radioNotIncludedInEducationPlan'
class ElectiveType(Enum):
ELECTIVE = 'radioElective'
FACULTATIVE = 'radioFacultative'
class Semester(Enum):
WINTER = '1'
SUMMER = '2'
discipline_type: ElectiveType
plan_type: ElectivePlanType
semester: Semester
year: int
class DateValidator(Validator):
def validate(self, document):
text = document.text
try:
test = datetime.datetime.strptime(text, '%Y-%m-%d')
except ValueError:
raise ValidationError(message='Грешен формат на датата', cursor_position=len(text))
if test < datetime.datetime.now():
raise ValidationError(message='Дата не може да бъде в миналото', cursor_position=len(text))
class YearValidator(Validator):
def validate(self, document):
text = document.text
if not text.isdigit():
raise ValidationError(message='Годината трябва да бъде число!', cursor_position=len(text))
if len(text) != 4:
raise ValidationError(message='Годината трябва да бъде четирицифрено число!', cursor_position=len(text))