Adminübersicht Timestamps

Lesefunktion für Timestamps und Erzeugung von Buttons in der Übersicht
This commit is contained in:
Alexander Malzkuhn 2025-04-22 17:43:46 +02:00
parent 348c8e2f7f
commit ca610d4381
2 changed files with 57 additions and 34 deletions

View File

@ -132,6 +132,12 @@ class user:
available_months.append(entry[5:-4])
return available_months
def get_timestamps(self, year, month):
with open(f"{self.userfolder}/{year}-{month}.txt", "r") as file:
timestamps = file.readlines()
timestamps.sort()
return timestamps
# Benutzer auflisten
def list_users():
users = [d for d in os.listdir(userfolder) if os.path.isdir(os.path.join(userfolder, d))]

View File

@ -89,7 +89,7 @@ def page_admin():
users = ui.tab('Benutzer')
settings = ui.tab('Einstellungen')
with ui.tab_panels(tabs, value=time_overview):
with (ui.tab_panels(tabs, value=time_overview)):
with ui.tab_panel(time_overview):
ui.markdown("##Übersichten")
@ -109,30 +109,7 @@ def page_admin():
# Tabelle konstruieren
with ui.card():
with ui.row():
def update_month_and_year():
try:
calendar_card.clear()
except:
pass
with ui.card() as calendar_card:
with ui.grid(columns=6):
ui.markdown("Datum")
ui.markdown("Buchungen")
ui.markdown("Soll")
ui.markdown("Ist")
ui.markdown("+/-")
ui.space()
for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1):
ui.markdown(f"{day}. {calendar.month_name[int(select_month.value)]}")
# ---> Hier die Schleife für die Buchungen
ui.markdown('BUCHUNGEN')
ui.markdown("Soll")
ui.markdown("Ist")
ui.markdown("+/-")
ui.button("Bearbeiten")
with ui.row() as timetable_header:
def update_months():
current_user = user(time_user.value)
@ -158,25 +135,65 @@ def page_admin():
select_month = ui.select(options=available_months_dict)
try:
select_month.value = str(current_month)
except:
pass
select_year = ui.select(options=available_years, on_change=update_months)
try:
select_year.value = str(current_year)
except:
pass
try:
select_month.value = str(current_month)
except:
select_month.value = str(available_months[0])
ui.button("Aktualisieren", on_click=update_month_and_year)
ui.markdown(f"###Buchungen für {calendar.month_name[current_month]} {current_year}")
month_header = ui.markdown(f"###Buchungen für {calendar.month_name[int(select_month.value)]} {select_year.value}")
# Tabelle aufbauen
with ui.card() as calendar_card:
def update_month_and_year():
with ui.grid(columns=6) as table_grid:
ui.markdown("Datum")
ui.markdown("Buchungen")
ui.markdown("Soll")
ui.markdown("Ist")
ui.markdown("Saldo")
ui.space()
current_user = user(time_user.value)
timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value)
for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1):
ui.markdown(f"{day}. {calendar.month_name[int(select_month.value)]}")
# ---> Hier die Schleife für die Buchungen
#ui.markdown('BUCHUNGEN')
with ui.row():
counter = 0
for i in timestamps:
actual_timestamp = datetime.datetime.fromtimestamp(int(i))
timestamp_day = actual_timestamp.strftime('%-d')
if int(timestamp_day) == int(day):
counter += 1
current_button = ui.button(actual_timestamp.strftime('%H:%m'))
if counter % 2 == 0:
current_button.props('color=red')
else:
current_button.props('color=green')
ui.markdown("Soll")
ui.markdown("Ist")
ui.markdown("+/-")
ui.button("Eintrag hinzufügen")
table_grid.move(calendar_card)
update_month_and_year()
def clear_card():
calendar_card.clear()
update_month_and_year()
month_header.set_content(f"###Buchungen für {calendar.month_name[int(select_month.value)]} {select_year.value}")
button_update = ui.button("Aktualisieren", on_click=clear_card)
button_update.move(timetable_header)
with ui.tab_panel(admin_user):