/
filter_commands.py
186 lines (152 loc) · 7.43 KB
/
filter_commands.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import re
from config import extract_topic_abbr, is_empty, zusatzthemen_beschreibung
from tinydb import Query
from sort_items import order_gesammeltedateien
from json.decoder import JSONDecodeError
from standard_dialog_windows import critical_window
from refresh_ddb import refresh_ddb
def get_filter_string(self, list_mode):
if self.chosen_program == "cria":
if list_mode == "sage":
# string_0 = self.comboBox_klassen.currentText()
string_1 = self.comboBox_kapitel.currentText()
string_2 = self.comboBox_unterkapitel.currentText()
elif list_mode == "feedback":
# string_0 = self.comboBox_klassen_fb_cria.currentText()
string_1 = self.comboBox_kapitel_fb_cria.currentText()
string_2 = self.comboBox_unterkapitel_fb_cria.currentText()
filter_string = ""
# if not is_empty(string_0):
# filter_string = "k" + string_0[0] + "."
if not is_empty(string_1):
filter_string = extract_topic_abbr(string_1)
if not is_empty(string_2):
filter_string = (
filter_string + "." +extract_topic_abbr(string_2)
)
return filter_string
if self.chosen_program == "lama":
if list_mode == "sage":
# if self.comboBox_gk.currentText() == 'Zusatzthemen':
# string_0 = ""
# else:
string_0 = self.comboBox_gk.currentText()
topic = extract_topic_abbr(self.comboBox_gk_num.currentText())
if topic != None:
string_1 = topic
else:
string_1 = self.comboBox_gk_num.currentText()
elif list_mode == "feedback":
string_0 = self.comboBox_fb.currentText()
topic = extract_topic_abbr(self.comboBox_fb_num.currentText())
if topic != None:
string_1 = topic
else:
string_1 = self.comboBox_fb_num.currentText()
if not is_empty(string_0):
if string_0 == 'Zusatzthemen':
filter_string = "zusatz_"+string_1.upper()
else:
filter_string = string_0
if not is_empty(string_1):
filter_string = filter_string + " " + string_1
return filter_string
else:
return ""
def filter_number(value, line_entry):
if line_entry.startswith('l'):
number = value.split(" - ")[-1].replace("i.","")
elif line_entry.startswith('i'):
number = value.split(" - ")[-1].replace("l.","")
else:
number = value.split(" - ")[-1].replace("l.","").replace("i.","")
if number.startswith(line_entry):
return True
else:
return False
def filter_items(self, table_lama, typ, list_mode, filter_string, line_entry, klasse=None):
_file_ = Query()
if typ == "lama_1" or typ == "lama_2":
def string_included_lama(value):
if "zusatz_" in filter_string:
string = filter_string.replace("zusatz_","")
if is_empty(string):
for all in zusatzthemen_beschreibung.keys():
if value.startswith(all.upper()) and (filter_number(value, line_entry)==True):
return True
return False
else:
string = filter_string
if (value.replace("-L","").startswith(string)) and (filter_number(value, line_entry)==True):
return True
else:
return False
try:
filtered_items = table_lama.search(_file_.name.test(string_included_lama))
except TypeError as e:
filtered_items = []
except JSONDecodeError as e:
refresh_ddb(self, auto_update=True)
try:
filtered_items = table_lama.search(_file_.name.test(string_included_lama))
except JSONDecodeError as e:
critical_window("Es ist ein Fehler bei der Aufgabensuche aufgetreten. Es können daher nicht alle Aufgaben angezeigt werden. Bitte starten Sie die Suche erneut.",
"Sollte der Fehler weiterhin bestehen, melden Sie sich bitte unter lama.helpme@gmail.com",
detailed_text=f'Error:{e}: File "filter_commands.py" in filter_items\n\nError occured in table:\n{table_lama}')
filtered_items = []
elif typ == "cria":
# if list_mode != "creator":
klasse = self.get_klasse(list_mode)
# print(klasse)
string_included_cria = lambda s: s.split(".")[-1].startswith(line_entry)
def themen_included_cria(value):
for all in value:
return True if filter_string in all else False
if klasse == None:
try:
filtered_items = table_lama.search(
(_file_.themen.test(themen_included_cria))
& (_file_.name.test(string_included_cria))
)
except TypeError as e:
filtered_items = []
except JSONDecodeError as e:
refresh_ddb(self, auto_update=True)
try:
filtered_items = table_lama.search(
(_file_.themen.test(themen_included_cria))
& (_file_.name.test(string_included_cria))
)
except JSONDecodeError as e:
critical_window("Es ist ein Fehler bei der Aufgabensuche aufgetreten. Es können daher nicht alle Aufgaben angezeigt werden. Bitte starten Sie die Suche erneut.",
"Sollte der Fehler weiterhin bestehen, melden Sie sich bitte unter lama.helpme@gmail.com",
detailed_text=f'Error:{e}: File "filter_commands.py" in filter_items\n\nError occured in table:\n{table_lama}')
filtered_items = []
else:
try:
filtered_items = table_lama.search(
(_file_.klasse == klasse)
& (_file_.themen.test(themen_included_cria))
& (_file_.name.test(string_included_cria))
)
except TypeError as e:
filtered_items = []
except JSONDecodeError as e:
refresh_ddb(self, auto_update=True)
try:
filtered_items = table_lama.search(
(_file_.klasse == klasse)
& (_file_.themen.test(themen_included_cria))
& (_file_.name.test(string_included_cria))
)
except JSONDecodeError as e:
critical_window("Es ist ein Fehler bei der Aufgabensuche aufgetreten. Es können daher nicht alle Aufgaben angezeigt werden. Bitte starten Sie die Suche erneut.",
"Sollte der Fehler weiterhin bestehen, melden Sie sich bitte unter lama.helpme@gmail.com",
detailed_text=f'Error:{e}: File "filter_commands.py" in filter_items\n\nError occured in table:\n{table_lama}')
filtered_items = []
filtered_items.sort(key=lambda text: order_gesammeltedateien(text, typ, cria_plain_number_order=True))
#print(filter_items)
return filtered_items
def get_drafts(table_lama):
_file_ = Query()
return table_lama.search(_file_.draft == True)