-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
73 lines (55 loc) · 2.06 KB
/
test.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
import flet as ft
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from database.database import StudentDatabase, StudentAsyncDatabase
from database.database import async_engine
from user_controls.student_subject_tasks_card import create_student_subject_tasks_card
from utils.exceptions import DontHaveGrades
from utils.lazy_db import LazyDatabase
async_session = async_sessionmaker(
bind=async_engine, class_=AsyncSession, expire_on_commit=False, future=True
)
async def TasksView(page: ft.Page) -> ft.Column:
USER_ID = page.session.get('user_id')
USERNAME = page.session.get('username')
if len(page.views) > 1:
page.views.pop()
db = LazyDatabase(StudentDatabase)
async_db = StudentAsyncDatabase()
content = ft.Column()
dont_have_tasks = ft.Row(
alignment=ft.MainAxisAlignment.CENTER,
visible=False,
controls=[ft.Text('Нет заданий', size=20, text_align=ft.TextAlign.CENTER, color=ft.colors.SURFACE_TINT)]
)
# region: FilePicker
file_piker = ft.FilePicker()
page.overlay.append(file_piker)
page.update()
# endregion
try:
subjects = await async_db.get_student_subjects(user_id=USER_ID)
for subject in subjects:
content.controls.append(
await create_student_subject_tasks_card(
USER_ID, subject[2],
subject[4].subject_id,
page=page,
file_picker=file_piker,
theory_url=subject[4].subject_theory.theory_data if subject[4].subject_theory else None
)
)
except DontHaveGrades as error:
dont_have_tasks.visible = True
page.update()
except Exception as err:
print(err)
return dont_have_tasks
async def create_text_field(label):
return ft.Column([ft.TextField(label=label)])
async def main(page: ft.Page):
text_field = await create_text_field('skdfj')
tt = await TasksView(page)
page.add(tt)
page.update()
if __name__ == '__main__':
ft.app(main)