-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.py
122 lines (101 loc) · 3.75 KB
/
Message.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from datetime import datetime
def check_is_number(value) -> bool:
if value.isnumeric():
return True
return False
def check_is_letter(value) -> bool:
if value.isalpha():
return True
return False
def check_is_dot(value) -> bool:
if value == ".":
return True
return False
def check_is_sonder(value) -> bool:
if (value == "-") or (value == ",") or (value == ":") or (value == "%") or (value == "/") or (value == "`") or (
value == " "):
return True
return False
class Message:
hide: bool
comboBox: bool
allow_all_values: bool
def __init__(self, name, typ, default, allowed_values, allowed_character, description, hide, date_format):
self.name = name
self.typ = typ
self.default_values = default
self.allowed_values = allowed_values
if allowed_values[0] == 'all':
self.allow_all_values = True
else:
self.allow_all_values = False
if not self.allow_all_values and self.allowed_values[0] != "":
self.comboBox = True
else:
self.comboBox = False
self.allowed_character = allowed_character
self.description = description
if hide == "False":
self.hide = False
else:
self.hide = True
if not self.allow_all_values and self.allowed_values[0] != "":
self.comboBox = True
else:
self.comboBox = False
self.date_format = date_format
def __str__(self):
return "Name: " + self.name + " Typ: " + self.typ + " defaultvalues: " + str(
self.default_values) + " allowedvalues: " + self.allowed_values + " description: " + self.description
def is_value_allowed(self, value) -> str:
ok = False
if (self.typ == "M") and (value == ""):
return "Darf nicht leer sein."
if self.allow_all_values:
ok = True
else:
for a in self.allowed_values:
if value == a:
ok = True
if ok:
checked = self.check_value(value)
if checked == "Ok":
return "Ok"
else:
return "Unerlaubte Zeichen.\n" + checked
else:
return "Unerlaubter Wert."
def check_value(self, value) -> str:
if value == "":
return "Ok"
else:
if self.allowed_character == "default":
for l in value:
if not (check_is_number(l) or check_is_letter(l) or check_is_dot(l) or check_is_sonder(
l)):
return "Muss erlaubtes Zeichen sein."
return "Ok"
elif self.allowed_character == "date":
try:
if value != datetime.strptime(value, self.date_format).strftime(self.date_format):
raise ValueError
return "Ok"
except ValueError:
return "Muss Datum sein."
elif self.allowed_character == "numbers":
if not (check_is_number(value)):
return "Muss Zahl sein."
return "Ok"
elif self.allowed_character == "letters":
if not (check_is_letter(value.replace(" ", ""))):
print("NOT LETTER")
return "Muss Buchstabe sein."
return "Ok"
elif self.allowed_character == "letters+numbers":
for l in value:
if not (check_is_number(l) or check_is_letter(l)):
return "Muss Zahl oder Buchstabe sein."
return "Ok"
else:
print("unknown")
return "Ok"