-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
2243 lines (2075 loc) · 115 KB
/
main.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import flet as ft
from urllib.parse import urlparse
import queue
import sqlite3
APP_NAME = "STACKS DATABASE"
landingPageRoute = "/"
selectStudentClassRoute = "/selectClass"
addStudentPageRoute = "/addStudent"
studentsListViewPageRoute = "/studentsList"
studentProfileViewPageRoute = "/studentProfilePage"
editStudentPageViewRoute = "/editStudentPage"
mallama_Azumi = "Mallama Azumi"
mallama_Rabi = "Mallama Rabi"
mallam_Musah = "Mallam Musah"
mallam_Awal = "Mallam Awal"
mallam_Sahnun = "Mallam Sahnun"
mallam_Umar = "Mallam Umar"
mallam_Haadi = "Mallam Haadi"
metaData = "MetaData"
listOfClassNames = [
mallama_Azumi,
mallama_Rabi,
mallam_Musah,
mallam_Awal,
mallam_Sahnun,
mallam_Umar,
mallam_Haadi,
]
# parent container infos
containerBgColor: ft.colors = ft.colors.BLUE_100
borderRadiusForEverything = 35
containerBorderColor: ft.colors = ft.colors.BLACK
containerBorderWidth = 3
EXCEL_FILE_NAME = "NIGHT MAKARANTA STUDENTS DATA.xlsx"
mallama_Azumi_max_id_cell_id = "B2"
mallama_Rabi_max_id_cell_id = "B3"
mallam_Musah_max_id_cell_id = "B4"
mallam_Awal_max_id_cell_id = "B5"
mallam_Sahnun_max_id_cell_id = "B6"
mallam_Umar_max_id_cell_id = "B7"
mallam_Haadi_max_id_cell_id = "B8"
addUserTileIcon = "add user tile icon.svg"
removeUserTileIcon = "delete user.svg"
editStudentTileIcon = "edit user tile icon.svg"
showStudentProfileTileIcon = "student profile.svg"
listUsersTileIcon = "lsit students.svg"
userTribeIconLocation = "tribe.svg"
userLocationIconLocation = "location.svg"
userIdImageLocation = "user_id.svg"
userGenderIconLocation = "gender.svg"
userIdIconLocation = "user_id.svg"
userClassIconLoaction = "class.svg"
userBirthDayIconLocation = "Birthday.svg"
usersFathersIcon = "Father.svg"
usersMotherIcon = "Mother.svg"
boyAvatar = "boy.png"
girAvatar = "girl.png"
assestsDir = "/home/mr-robot/Documents/PROGRAMS/flet/nightMakaranta_gui/assets"
mafiaFont = "/fonts/Mafia.ttf"
classMaxCellIdMap = {
mallama_Azumi: mallama_Azumi_max_id_cell_id,
mallama_Rabi: mallama_Rabi_max_id_cell_id,
mallam_Musah: mallam_Musah_max_id_cell_id,
mallam_Awal: mallam_Awal_max_id_cell_id,
mallam_Sahnun: mallam_Sahnun_max_id_cell_id,
mallam_Umar: mallam_Umar_max_id_cell_id,
mallam_Haadi: mallam_Haadi_max_id_cell_id,
}
months_of_the_yr = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
]
monthsToNumbersDicts = {
"January": 1,
"February": 2,
"March": 3,
"April": 4,
"May": 5,
"June": 6,
"July": 7,
"August": 8,
"September": 9,
"October": 10,
"November": 11,
"December": 12
}
delAction:str = "Delete Operation"
editAction:str = "Edit Operation"
showProfileAction:str = "Students Profile"
listStudentsAction:str = "List Students"
tableName = "Daarul_Quran_Students"
dataBaseName = "stacks.db"
def addStudentPage(page: ft.Page, paramsFrmPrevPage:str ="None", editMode:bool=False,) -> ft.View:
LENGTH_ERROR = "LENGTH"
MIXED_TYPE_ERROR = "MIXED"
LEGIT = "LEGIT"
if editMode:
idOfStudentToEdit, previousPage, selectedAction = paramsFrmPrevPage.split("-")[0], paramsFrmPrevPage.split("-")[1], paramsFrmPrevPage.split("-")[2],
dObj = DarulQuranDb(connection = sqlite3.connect(dataBaseName, isolation_level=None))
theStudentsData = dObj.getSpecificStudentsFullData(id=idOfStudentToEdit)[0]
page.title = f"Edit {theStudentsData[1]} {theStudentsData[2]}'s data - {APP_NAME}"
if not editMode:
page.title = f"Add data - {APP_NAME}"
stdentNamefeildWith = 250
parentsField = 400
dropDownFieldWidth = 150
dobColumnsWidth = 80
fieldsBorderRadiusValue = 12
fontSize = 18
cursorRadiusValue = 50
fieldBorderWidth = 3
cursorWidthValue, cursorHeightValue = 12, 30
classDropDownFieldHintText = "Select Student class"
genderDropDownFieldHintText = "Gender"
backButton: ft.Control = ft.ElevatedButton(
color=ft.colors.BLUE_300,
text="back",
icon=ft.icons.ARROW_BACK_SHARP,
on_click=lambda _: onBackutonClicked(),
)
students_first_name = ft.TextField(
autofocus=True, label="Student's first name",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=stdentNamefeildWith,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth, color=ft.colors.BLACK,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
students_middle_name = ft.TextField(
label="Student's middle name",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=stdentNamefeildWith,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue, border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
students_last_name = ft.TextField(
label="Student's last name",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=stdentNamefeildWith,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
fathers_name = ft.TextField(label="Father's full name",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=parentsField,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
mothers_name = ft.TextField(label="Mother's full name",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=parentsField,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
fathers_telephone = ft.TextField(
max_lines=1, max_length=10, label="Father's telephone",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=stdentNamefeildWith,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
mothers_telephone = ft.TextField(
max_lines=1, max_length=10, label="mother's telephone",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=stdentNamefeildWith,
border_radius=fieldsBorderRadiusValue, cursor_width=cursorWidthValue,
cursor_radius=cursorRadiusValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
student_location = ft.TextField(
label="Student's location",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=parentsField,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
students_tribe = ft.TextField(label="Student's tribe",
label_style=ft.TextStyle(size=fontSize - 5,
weight=ft.FontWeight.NORMAL,
font_family="Ubuntu",
color=ft.colors.BLACK),
bgcolor=ft.colors.WHITE,
width=parentsField,
border_radius=fieldsBorderRadiusValue, cursor_radius=cursorRadiusValue,
cursor_width=cursorWidthValue, cursor_height=cursorHeightValue,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK),
)
class_drop_down_field = ft.Dropdown(
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK,
),
width=dropDownFieldWidth + 55,
label="Class",
hint_text=classDropDownFieldHintText,
options=[
ft.dropdown.Option(mallama_Azumi),
ft.dropdown.Option(mallama_Rabi),
ft.dropdown.Option(mallam_Musah),
ft.dropdown.Option(mallam_Awal),
ft.dropdown.Option(mallam_Sahnun),
ft.dropdown.Option(mallam_Umar),
ft.dropdown.Option(mallam_Haadi),
],
border_radius=fieldsBorderRadiusValue,
)
gender_dropdown_field = ft.Dropdown(
color=ft.colors.BLACK,
bgcolor=ft.colors.WHITE,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK,
),
width=dropDownFieldWidth,
label="Gender",
hint_text=genderDropDownFieldHintText,
options=[
ft.dropdown.Option("Male"),
ft.dropdown.Option("Female"),
],
border_radius=fieldsBorderRadiusValue,
)
dob_day_drp_dwn_field = ft.Dropdown(
color=ft.colors.BLACK,
bgcolor=ft.colors.WHITE,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK,
),
width=dobColumnsWidth,
label="Day",
hint_text="DD",
border_radius=fieldsBorderRadiusValue,
options=[ft.dropdown.Option(str(number)) for number in range(1, 32)],
)
dob_month_drp_dwn_field = ft.Dropdown(
color=ft.colors.BLACK,
bgcolor=ft.colors.WHITE,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK,
),
width=dobColumnsWidth+40,
label="Month",
hint_text="MM",
border_radius=fieldsBorderRadiusValue,
options=[ft.dropdown.Option(month)
for month in months_of_the_yr],
)
dob_year_drp_dwn_field = ft.Dropdown(
color=ft.colors.BLACK,
bgcolor=ft.colors.WHITE,
border_width=fieldBorderWidth,
border_color=ft.colors.BLACK,
text_style=ft.TextStyle(size=fontSize,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
color=ft.colors.BLACK,
),
width=dobColumnsWidth,
label="Year",
hint_text="YYYY",
border_radius=fieldsBorderRadiusValue,
options=[ft.dropdown.Option(str(year)) for year in range(2000, 2023)],
)
dob_intro_text = ft.Text(value="Date of birth:",
color=ft.colors.BLACK, size=fontSize - 3,
weight=ft.FontWeight.BOLD,
font_family="Ubuntu",
selectable=True,)
def onBackutonClicked():
'''
You can come to the edit page in three ways\n
1- ListView page student tile is clicked when selected action for the listView page is Edit Action or\n
2- ListView page using the edit button when the selection action for the listView is not Edit Action and\n
2- Profile page's edit button.
So to go back to the previous page we need to check what was the previous page:\n
if the previous page was the PROFILE PAGE, then it came from the student listView where selected action is Edit Action\n
\tWe should go back to profile page whiles providing id of student so that the data about the student can displayed and \n
\talso class of the student so that the listView page can show students of a specific class, incase the user goes back\n
\tto the student listView page from the profile page.\n
\tSo we go back to the profile page without providing Action context because you can come to the student profile page\n
\tWITH ONLY ONE ACTION CONTEXT and that is the View Profile Action context so we don't need to specify which action context\n
\tthe list view gave the profile page becuase there can be only one action context and no confusion will occur\n
\twhen going back to the list view from the profile page.\n
elif the previous page was STUDENT'S LISTVIEW then:\n
\tWe should go back to the listView whiles providing it with the id along with the action selected for it,\n
\tso as to not break the context, the listView should always have an Action Context.\n
else if it was not from list View or profile page then it not edit mode but add student mode:\n
\tthat only comes from the landing page so we go back to the landing page\n
'''
if editMode:
dbObj = DarulQuranDb(connection=sqlite3.connect(dataBaseName))
className = dbObj.getStudentClassNameUsingId(id=idOfStudentToEdit)
# print(f"TEST_EDIT_DATA-Here is previous page {previousPage} can it go to {showProfileAction}? : {previousPage == showProfileAction}")
# print(f"TEST_EDIT_DATA-can go to {previousPage}? : {previousPage == listStudentsAction}")
if previousPage == listStudentsAction:
# print(f'TEST_EDIT_DATA-GO back to student listVIew page with className as {className} and selected action as :{selectedAction}')
page.go(f"{studentsListViewPageRoute}/{className}-{selectedAction}")
elif previousPage == showProfileAction:
# gonig back to student profile page route with className and id of student
page.go(f"{studentProfileViewPageRoute}/{className}-{idOfStudentToEdit}")
else:
page.go(landingPageRoute)
def pumpUserDataIntoEntryField(idOfStudentToEdit:int):
students_first_name.value = theStudentsData[1]
students_middle_name.value = theStudentsData[2]
students_last_name.value = theStudentsData[3]
gender_dropdown_field.value = theStudentsData[4]
dob = theStudentsData[5].split("-")
dob_day_drp_dwn_field.value = dob[0]
dob_month_drp_dwn_field.value = [key for key,value in monthsToNumbersDicts.items() if value==int(dob[1])][0]
dob_year_drp_dwn_field.value = dob[2]
class_drop_down_field.value = theStudentsData[6]
fathers_name.value = theStudentsData[7]
mothers_name.value = theStudentsData[8]
fathers_telephone.value = f"0{theStudentsData[9]}"
mothers_telephone.value = f"0{theStudentsData[10]}"
students_tribe.value = theStudentsData[11]
student_location.value = theStudentsData[12]
if editMode == True:
pumpUserDataIntoEntryField(idOfStudentToEdit=idOfStudentToEdit)
def isPhoneNumberOk(e) -> str:
# print(
# f"Here is the phone Number {len(fathers_telephone.value)} and length {len({mothers_telephone.value})}")
if len(f"{fathers_telephone.value}{mothers_telephone.value}") == 10 or len(f"{fathers_telephone.value}{mothers_telephone.value}") == 20:
for number, character in enumerate(f"{fathers_telephone.value}{mothers_telephone.value}", start=1):
if not character.isalpha():
# print(LEGIT)
pass
else:
# print(f"Here is the letter:{character} number{number}")
# print(MIXED_TYPE_ERROR)
return MIXED_TYPE_ERROR
else:
return LEGIT
else:
val = f"{fathers_telephone.value}{mothers_telephone.value}"
# print(
# f"Here is the val: {val} and her is the length of the characters {len(val)}")
# print(LENGTH_ERROR)
return LENGTH_ERROR
def onBttonClicked(e):
student_first_name_value = students_first_name.value
student_middle_name_value = students_middle_name.value
student_last_name_value = students_last_name.value
fathers_name_value = fathers_name.value
mothers_name_value = mothers_name.value
fathers_telephone_value = fathers_telephone.value
mothers_telephone_value = mothers_telephone.value
studens_tribe_value = students_tribe.value
students_location_value = student_location.value
students_gender = gender_dropdown_field.value
students_class_value = class_drop_down_field.value
dob_day_value = dob_day_drp_dwn_field.value
dob_month_value = dob_month_drp_dwn_field.value
dob_year_drp_year_value = dob_year_drp_dwn_field.value
# FUNCTIONS TO USE
def clearFields(e):
students_first_name.value = ""
students_middle_name.value = ""
students_last_name.value = ""
fathers_name.value = ""
mothers_name.value = ""
fathers_telephone.value = ""
mothers_telephone.value = ""
students_tribe.value = ""
student_location.value = ""
class_drop_down_field.value = genderDropDownFieldHintText
gender_dropdown_field.value = genderDropDownFieldHintText
dob_day_drp_dwn_field.value = "DD"
dob_month_drp_dwn_field.value = "MM"
dob_year_drp_dwn_field.value = "YYYY"
students_first_name.update()
students_middle_name.update()
students_last_name.update()
fathers_name.update()
mothers_name.update()
fathers_telephone.update()
mothers_telephone.update()
students_tribe.update()
student_location.update()
class_drop_down_field.update()
gender_dropdown_field.update()
dob_day_drp_dwn_field.update()
dob_month_drp_dwn_field.update()
dob_year_drp_dwn_field.update()
def showErrorDialouges(message:str):
alrtDialogue = ft.AlertDialog(
title=ft.Text("Empty fields", size=15, text_align=ft.TextAlign.LEFT),
content = ft.Text(message, size=13, text_align=ft.TextAlign.LEFT),
actions_alignment=ft.MainAxisAlignment.CENTER,
)
page.dialog = alrtDialogue
alrtDialogue.open = True
page.update()
#CHECK WHETHER THE NOT NULL FIELDS ARE NULL SO AN ALERT DIALOGUE CAN BE SHOWN
# ELSE IF ITS LENGHT ISSUE SHOW ALERT FOR THAT
if isPhoneNumberOk(f"{fathers_telephone}{mothers_telephone}") == LENGTH_ERROR:
checkPhoneNumberLength = ft.AlertDialog(
title=ft.Text("Please, check the phone number length."), on_dismiss=lambda e: print("Dialog dismissed!")
)
page.dialog = checkPhoneNumberLength
checkPhoneNumberLength.open = True
page.update()
# ELSE IF IT INVALID CHARACTER ISSUE SHOW ALERT FOR THAT
elif isPhoneNumberOk(f"{fathers_telephone}{mothers_telephone}") == MIXED_TYPE_ERROR:
ckeckPhoneNumberCharacters = ft.AlertDialog(
title=ft.Text("Please, check phone the number, phone numbers cannot containt alphabets."),
on_dismiss=lambda e: print("Dialog dismissed!")
)
page.dialog = ckeckPhoneNumberCharacters
ckeckPhoneNumberCharacters.open = True
page.update()
elif students_first_name.value == "" or students_first_name == None:
# errorMessages.append("Student first name cannot be empty")
showErrorDialouges("Student first name cannot be empty")
elif students_last_name.value == "" or students_last_name.value == None:
showErrorDialouges("Student last name cannot be empty")
# errorMessages.append("Student last name cannot be empty")
elif dob_day_drp_dwn_field.value == "" or dob_day_drp_dwn_field.value == None:
showErrorDialouges("Day of birth has not been chosen.")
# errorMessages.append("Day of birth has not been chosen.")
elif dob_month_drp_dwn_field.value == "" or dob_month_drp_dwn_field.value == None:
showErrorDialouges("Month of birth has not been chosen")
# errorMessages.append("Month of birth has not been chosen")
elif dob_year_drp_dwn_field.value == "" or dob_year_drp_dwn_field.value == None:
showErrorDialouges("Year of birth has not been chosen")
# errorMessages.append("Year of birth has not been chosen")
elif class_drop_down_field.value == "" or class_drop_down_field.value == None:
showErrorDialouges("Student's class has not been chosen")
# errorMessages.append("Student's class has not been chosen")
elif gender_dropdown_field.value == "" or gender_dropdown_field.value == None:
showErrorDialouges("Student's gender has not been chosen")
# errorMessages.append("Student's gender has not been chosen")
elif fathers_name.value == "" or fathers_name.value == None:
showErrorDialouges("Father's name cannot be empty")
# errorMessages.append("Father's name cannot be empty")
elif mothers_name.value == "" or mothers_name.value == None:
showErrorDialouges("Mother's name cannot be empty")
# errorMessages.append("Mother's name cannot be empty")
# CHECK WHETHER PHONE NUMBER IS OK
elif student_location.value == "" or student_location.value == None:
showErrorDialouges("Student location cannot be empty")
elif fathers_telephone.value == "0000000000":
showErrorDialouges("Phone number cannot be only zeros.")
elif list(fathers_telephone.value)[0] != "0" or list(mothers_telephone.value)[0] != "0":
print(f"the first char show {list(mothers_telephone.value)[0]}")
showErrorDialouges("Phone number should start with a zero.")
elif isPhoneNumberOk(f"{fathers_telephone}{mothers_telephone}") == LEGIT:
action = "edit" if editMode else "write"
# ASK USER TO CONFIRM WRITE IF CONFIRMED
alrtDialogue = ft.AlertDialog(
title=ft.Column(
alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.START,
controls=[
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Are you sure you want to {action} this data to the database", size=15),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student first name: {students_first_name.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student middle name: {students_middle_name.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student last name: {students_last_name.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student gender: { gender_dropdown_field.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"student class: {class_drop_down_field.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Father's full name: {fathers_name.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Mother's full name: { mothers_name.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Father's tele: {fathers_telephone.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Mother's tele: {mothers_telephone.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student's tribe: {students_tribe.value}", size=10),
ft.Text(text_align=ft.TextAlign.LEFT,
value=f"Student's location: {student_location.value}", size=10)
]
),
actions=[
ft.ElevatedButton(
"Yes", on_click=lambda e: hasConsentedToWrite(e),
icon=ft.icons.THUMB_UP, color=ft.colors.BLUE_600,
bgcolor=ft.colors.WHITE, elevation=10),
ft.ElevatedButton("No", on_click=lambda e: hasNotConsented(
e), icon=ft.icons.THUMB_DOWN, color=ft.colors.BLUE_600,
bgcolor=ft.colors.WHITE, elevation=10),
],
actions_alignment=ft.MainAxisAlignment.SPACE_AROUND,
on_dismiss=lambda: print("Dialog dismissed!")
)
# SHOW THE ALERT DIALOGUE
page.dialog = alrtDialogue
alrtDialogue.open = True
page.update()
# FUNCTIONS FOR BUTTON
def hasConsentedToWrite(e):
# ASSIGN A NEW ID TO THE CURRENT STUDENT
addOrEditDbObj = DarulQuranDb(connection = sqlite3.connect(dataBaseName, isolation_level=None))
if editMode == False:
addOrEditDbObj.addStudentToDB(
student_first_nameVal=student_first_name_value,
student_middle_nameVal=student_middle_name_value,
student_last_nameVal=student_last_name_value,
students_genderVal=students_gender,
d_o_bVal=f"{dob_day_value}-{monthsToNumbersDicts[dob_month_value]}-{dob_year_drp_year_value}",
students_classVal=students_class_value,
fathers_nameVal=fathers_name_value,
mothers_nameVal=mothers_name_value,
fathers_telephoneVal=fathers_telephone_value,
mothers_telephoneVal=mothers_telephone_value,
studens_tribeVal=studens_tribe_value,
students_locationVal=students_location_value
)
else:
addOrEditDbObj.editStudentData(
idVal=idOfStudentToEdit,
student_first_nameVal=student_first_name_value,
student_middle_nameVal=student_middle_name_value,
student_last_nameVal=student_last_name_value,
students_genderVal=students_gender,
d_o_bVal=f"{dob_day_value}-{monthsToNumbersDicts[dob_month_value]}-{dob_year_drp_year_value}",
students_classVal=students_class_value,
fathers_nameVal=fathers_name_value,
mothers_nameVal=mothers_name_value,
fathers_telephoneVal=fathers_telephone_value,
mothers_telephoneVal=mothers_telephone_value,
studens_tribeVal=studens_tribe_value,
students_locationVal=students_location_value
)
# CLOSE CONFIRM WRITE DIALOGUE
alrtDialogue.open = False
page.update()
# CLEAR THE FILEDS
if not editMode:
clearFields(e)
def hasNotConsented(e):
ft.AlertDialog(title=ft.Text("Ok, Cancelling..."))
# CLOSE CONFIRM WRITE DIALOGUE
alrtDialogue.open = False
page.update()
# ELSE DO NOT WRITE DATA
addStudentPageView: ft.View = ft.View(
route=addStudentPageRoute,
controls=[
ft.Column(
controls=[
ft.Row(controls=[
backButton,
],),
ft.Container(
border=ft.border.all(
width=containerBorderWidth, color=containerBorderColor),
margin=ft.Margin(
left=10, right=10,
top=30, bottom=10,
),
gradient=ft.LinearGradient(
begin=ft.alignment.top_center,
end=ft.alignment.bottom_center,
stops=[0.3, 1.0],
colors=[ft.colors.BLUE_100,
ft.colors.CYAN],
),
content=ft.Column(
controls=[
ft.ResponsiveRow(controls=[
ft.Container(students_first_name, col={
"sm": 6, "md": 4, "xl": 4}, margin=10),
ft.Container(students_middle_name, col={
"sm": 6, "md": 4, "xl": 4}, margin=10),
ft.Container(students_last_name, col={
"sm": 6, "md": 4, "xl": 4}, margin=10),
],
),
ft.ResponsiveRow(
controls=[
ft.Container(dob_intro_text, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
ft.Container(dob_day_drp_dwn_field, col={
"sm": 2, "md": 2, "xl": 2}, margin=10),
ft.Container(dob_month_drp_dwn_field, col={
"sm": 4, "md": 3, "xl": 3}, margin=10),
ft.Container(dob_year_drp_dwn_field, col={
"sm": 4, "md": 3, "xl": 3}, margin=10),
],
),
ft.ResponsiveRow(
[
ft.Container(class_drop_down_field, col={
"sm": 3.8, "md": 3.8, "xl": 3.8}, margin=10),
ft.Container(gender_dropdown_field, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
]
),
ft.Column(controls=[
ft.Container(fathers_name, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
ft.Container(mothers_name, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
ft.ResponsiveRow(
[
ft.Container(fathers_telephone, col={
"sm": 4, "md": 4, "xl": 4}, margin=10),
ft.Container(mothers_telephone, col={
"sm": 4, "md": 4, "xl": 4}, margin=10),
]
),
ft.Container(student_location, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
ft.Container(students_tribe, col={
"sm": 3, "md": 3, "xl": 3}, margin=10),
],),
],
),
width=800,
bgcolor=ft.colors.WHITE30,
border_radius=20,
padding=20,
alignment=ft.alignment.center,
),
ft.Column(controls=[
ft.Container(
margin=15,
content=ft.ElevatedButton(
content=ft.Row(
controls=[
ft.Icon(
name=ft.icons.DONE_OUTLINE_OUTLINED, color="pink"),
ft.Text(
value=" Done", size=20),
],
vertical_alignment="center"),
width=175, height=50,
icon_color="green400",
on_click=onBttonClicked),
),
],
width=800,
horizontal_alignment="center",)
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
alignment=ft.MainAxisAlignment.CENTER,
)
]
)
addStudentPageView.bgcolor = ft.colors.WHITE
addStudentPageView.scroll = ft.ScrollMode.ADAPTIVE
return addStudentPageView
def landingPage(page=ft.Page) -> ft.View:
page.title = APP_NAME
page.theme_mode = ft.ThemeMode.LIGHT
ft.AnimatedSwitcher(
transition=ft.AnimatedSwitcherTransition.SCALE,
duration=500,
reverse_duration=100,
switch_in_curve=ft.AnimationCurve.BOUNCE_OUT,
switch_out_curve=ft.AnimationCurve.BOUNCE_IN,
)
def onTileHover(e:ft.HoverEvent):
if e.data == "true":
e.control.width = containerWidth + 15
e.control.height = containerHeight + 15
e.control.bgcolor = ft.colors.WHITE
e.control.update()
else:
addStudentsCard.width = containerWidth
addStudentsCard.height = containerHeight
e.control.width = containerWidth
e.control.height = containerHeight
e.control.bgcolor = ft.colors.WHITE
e.control.update()
containerWidth, containerHeight = 150, 150
theBarHeight = 22
theBarWidth = 1400
containerShadowSpread = 30
cardMargin = 20
tileAnimationDuration = 1000
theBar: ft.Container = ft.Container(content=ft.Text(
value="Student database operations", size=15, weight=ft.FontWeight.BOLD,
color=ft.colors.BLACK, font_family="Mafia"
),
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
padding=ft.Padding(
top=0, left=10,
right=0, bottom=0
),
border_radius=ft.BorderRadius(bottomLeft=10,
bottomRight=10,
topLeft=0,
topRight=0
),
bgcolor=ft.colors.WHITE,
width=theBarWidth,
height=theBarHeight,
)
addStudentTile: ft.Container = ft.Container(
animate = ft.animation.Animation(tileAnimationDuration, "bounceOut"),
on_hover=lambda hoverEvent: onTileHover(e=hoverEvent),
on_click=lambda _: page.go(addStudentPageRoute),
width=containerWidth, height=containerHeight,
ink=True,
padding=15,
border_radius=14,
content=ft.Image(src=addUserTileIcon),
bgcolor=ft.colors.WHITE,
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
)
removeStudentTile: ft.Container = ft.Container(
on_hover=lambda hoverEvent: onTileHover(e=hoverEvent),
animate=ft.animation.Animation(tileAnimationDuration, "bounceOut"),
on_click=lambda _: page.go(f"{selectStudentClassRoute}/{delAction}"),
width=containerWidth, height=containerHeight,
ink=True,
padding=15,
border_radius=14,
content=ft.Image(src=removeUserTileIcon),
bgcolor=ft.colors.WHITE,
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
)
editStudentTile: ft.Container = ft.Container(
animate=ft.animation.Animation(tileAnimationDuration, "bounceOut"),
on_hover=lambda hoverEvent: onTileHover(e=hoverEvent),
on_click=lambda _: page.go(f"{selectStudentClassRoute}/{editAction}"),
width=containerWidth, height=containerHeight,
ink=True,
padding=15,
border_radius=14,
content=ft.Image(src=editStudentTileIcon),
bgcolor=ft.colors.WHITE,
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
)
showStudentProfileTile: ft.Container = ft.Container(
on_hover=lambda hoverEvent: onTileHover(e=hoverEvent),
animate=ft.animation.Animation(tileAnimationDuration, "bounceOut"),
on_click=lambda _: page.go(f"{selectStudentClassRoute}/{showProfileAction}"),
width=containerWidth, height=containerHeight,
ink=True,
padding=15,
border_radius=14,
content=ft.Image(src=showStudentProfileTileIcon),
bgcolor=ft.colors.WHITE,
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
)
listStudentsTile: ft.Container = ft.Container(
on_hover=lambda hoverEvent: onTileHover(e=hoverEvent),
animate=ft.animation.Animation(tileAnimationDuration, "bounceOut"),
on_click=lambda _: page.go(f"{selectStudentClassRoute}/{listStudentsAction}"),
width=containerWidth, height=containerHeight,
ink=True,
padding=15,
border_radius=14,
content=ft.Image(src=listUsersTileIcon),
bgcolor=ft.colors.WHITE,
margin=ft.Margin(
top=0, left=0,
right=0, bottom=0
),
)
addStudentsCard = ft.Card(content=addStudentTile,
elevation=containerShadowSpread,
margin=cardMargin
)
removeStudentCard = ft.Card(content=removeStudentTile,
elevation=containerShadowSpread,
margin=cardMargin
)
editStudentCard = ft.Card(content=editStudentTile,
elevation=containerShadowSpread,
margin=cardMargin
)
showStudentProfileCard = ft.Card(content=showStudentProfileTile,
elevation=containerShadowSpread,
margin=cardMargin
)
listStudentsProfileCard = ft.Card(content=listStudentsTile,
elevation=containerShadowSpread,
margin=cardMargin
)
landingPageView: ft.View = ft.View(
route=landingPageRoute,
controls=[
# page.add(
ft.Column(
# width=theBarWidth,
# height=containerHeight + 50,
controls=[
ft.Card(content=theBar, elevation=20,
height=theBarHeight + 15, ),
ft.ResponsiveRow(
alignment=ft.MainAxisAlignment.SPACE_EVENLY,
vertical_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.Container(
col={"sm": 6, "md": 4, "xl": 2},
margin=ft.Margin(
top=20, bottom=0, left=0, right=0),
content=ft.Column(