Paarweise Buttons für Buchungen
This commit is contained in:
parent
d8609dce2b
commit
a7cf012d41
3
users.py
3
users.py
@ -153,7 +153,8 @@ class user:
|
|||||||
year_now = int(datetime.datetime.now().year)
|
year_now = int(datetime.datetime.now().year)
|
||||||
month_now = int(datetime.datetime.now().month)
|
month_now = int(datetime.datetime.now().month)
|
||||||
|
|
||||||
if start_year == year:
|
if start_year == int(year):
|
||||||
|
print("Start_year is year")
|
||||||
if start_year == year_now:
|
if start_year == year_now:
|
||||||
for i in range(start_month, month_now + 1):
|
for i in range(start_month, month_now + 1):
|
||||||
available_months.append(i)
|
available_months.append(i)
|
||||||
|
4
users/testuser1/2025-4.json
Normal file
4
users/testuser1/2025-4.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"archived": 0,
|
||||||
|
"total_hours": 0
|
||||||
|
}
|
@ -1,13 +1,9 @@
|
|||||||
1743562800
|
|
||||||
1743566400
|
1743566400
|
||||||
1743584340
|
|
||||||
1743606000
|
1743606000
|
||||||
1743652800
|
1743652800
|
||||||
1743660240
|
1743660240
|
||||||
1743667140
|
|
||||||
1743685200
|
|
||||||
1744889948
|
1744889948
|
||||||
1744889966
|
1744890300
|
||||||
1744989797
|
1744989797
|
||||||
1744989827
|
1744989827
|
||||||
1744989830
|
1744989830
|
||||||
@ -22,15 +18,11 @@
|
|||||||
1744991473
|
1744991473
|
||||||
1744991477
|
1744991477
|
||||||
1744991770
|
1744991770
|
||||||
1744991777
|
|
||||||
1745181046
|
1745181046
|
||||||
1745181050
|
1745181050
|
||||||
1745240760
|
1745215200
|
||||||
|
1745229600
|
||||||
1745390818
|
1745390818
|
||||||
1745390894
|
1745390894
|
||||||
1745390894
|
1745390894
|
||||||
1745391029
|
1745391029
|
||||||
1745391037
|
|
||||||
1745391056
|
|
||||||
1745391058
|
|
||||||
1745391059
|
|
||||||
|
216
web_ui.py
216
web_ui.py
@ -133,20 +133,15 @@ def page_admin():
|
|||||||
month_binder = ValueBinder()
|
month_binder = ValueBinder()
|
||||||
|
|
||||||
def update_months():
|
def update_months():
|
||||||
#try:
|
current_user = user(time_user.value)
|
||||||
print('Update Months called')
|
available_months = current_user.get_months(year_binder.value)
|
||||||
current_user = user(time_user.value)
|
available_months_dict = {}
|
||||||
available_months = current_user.get_months(year_binder.value)
|
for element in available_months:
|
||||||
available_months_dict = {}
|
available_months_dict[element] = calendar.month_name[int(element)]
|
||||||
for element in available_months:
|
print(available_months_dict)
|
||||||
available_months_dict[element] = calendar.month_name[int(element)]
|
select_month.clear()
|
||||||
print(available_months_dict)
|
select_month.set_options(available_months_dict)
|
||||||
select_month.clear()
|
select_month.value = list(available_months)[0]
|
||||||
select_month.set_options(available_months_dict)
|
|
||||||
select_month.value = list(available_months)[0]
|
|
||||||
|
|
||||||
#except:
|
|
||||||
# print("select.month existiert noch nicht")
|
|
||||||
|
|
||||||
userlist = list_users()
|
userlist = list_users()
|
||||||
ui.markdown("Benutzer:")
|
ui.markdown("Benutzer:")
|
||||||
@ -162,21 +157,20 @@ def page_admin():
|
|||||||
available_years = current_user.get_years()
|
available_years = current_user.get_years()
|
||||||
available_months = current_user.get_months(current_year)
|
available_months = current_user.get_months(current_year)
|
||||||
available_months_dict = { }
|
available_months_dict = { }
|
||||||
|
|
||||||
for element in available_months:
|
for element in available_months:
|
||||||
available_months_dict[element] = calendar.month_name[int(element)]
|
available_months_dict[element] = calendar.month_name[int(element)]
|
||||||
print('Selektoren konstruiert')
|
|
||||||
print(f" current_month: {current_month} und available_months: {available_months}")
|
|
||||||
if current_month in available_months:
|
if current_month in available_months:
|
||||||
set_month = current_month
|
set_month = current_month
|
||||||
else:
|
else:
|
||||||
set_month = available_months[0]
|
set_month = available_months[0]
|
||||||
print(set_month)
|
|
||||||
print(f" current_year: {current_year} und available_years: {available_years}")
|
|
||||||
if str(current_year) in available_years:
|
if str(current_year) in available_years:
|
||||||
set_year = str(current_year)
|
set_year = str(current_year)
|
||||||
else:
|
else:
|
||||||
set_year = (available_years[0])
|
set_year = (available_years[0])
|
||||||
print(set_year)
|
|
||||||
select_month = ui.select(options=available_months_dict, value=set_month).bind_value_to(month_binder, 'value')
|
select_month = ui.select(options=available_months_dict, value=set_month).bind_value_to(month_binder, 'value')
|
||||||
select_year = ui.select(options=available_years, value=set_year, on_change=update_months).bind_value_to(year_binder, 'value')
|
select_year = ui.select(options=available_years, value=set_year, on_change=update_months).bind_value_to(year_binder, 'value')
|
||||||
|
|
||||||
@ -190,78 +184,137 @@ def page_admin():
|
|||||||
with ui.grid(columns='auto auto 1fr 1fr 1fr 1fr') as table_grid:
|
with ui.grid(columns='auto auto 1fr 1fr 1fr 1fr') as table_grid:
|
||||||
ui.markdown("**Datum**")
|
ui.markdown("**Datum**")
|
||||||
ui.markdown("**Buchungen**")
|
ui.markdown("**Buchungen**")
|
||||||
ui.markdown("**Soll**")
|
|
||||||
ui.markdown("**Ist**")
|
ui.markdown("**Ist**")
|
||||||
|
ui.markdown("**Soll**")
|
||||||
ui.markdown("**Saldo**")
|
ui.markdown("**Saldo**")
|
||||||
ui.space()
|
ui.space()
|
||||||
|
|
||||||
current_user = user(time_user.value)
|
current_user = user(time_user.value)
|
||||||
timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value)
|
timestamps = current_user.get_timestamps(year=select_year.value, month=select_month.value)
|
||||||
|
# Dictionary für sortierte Timestamps
|
||||||
|
timestamps_dict = { }
|
||||||
|
# Dictionary mit zunächst leeren Tageinträgen befüllen
|
||||||
|
for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1):
|
||||||
|
# Jeder Tag bekommt eine leere Liste
|
||||||
|
timestamps_dict[day] = [ ]
|
||||||
|
|
||||||
|
# Alle Timestamps durchgehen und sie den Dictionaryeinträgen zuordnen:
|
||||||
|
for stamp in timestamps:
|
||||||
|
day_of_month_of_timestamp = int(datetime.datetime.fromtimestamp(int(stamp)).strftime("%-d"))
|
||||||
|
timestamps_dict[day_of_month_of_timestamp].append(int(stamp))
|
||||||
|
|
||||||
general_saldo = 0
|
general_saldo = 0
|
||||||
|
|
||||||
for day in range(1, monthrange(int(select_year.value), int(select_month.value))[1] + 1):
|
for day in list(timestamps_dict):
|
||||||
|
# Datum für Tabelle konstruieren
|
||||||
day_in_list = datetime.datetime(int(select_year.value), int(select_month.value), day)
|
day_in_list = datetime.datetime(int(select_year.value), int(select_month.value), day)
|
||||||
|
|
||||||
ui.markdown(f"{day_in_list.strftime('%a')}., {day}. {calendar.month_name[int(select_month.value)]}")
|
ui.markdown(f"{day_in_list.strftime('%a')}., {day}. {calendar.month_name[int(select_month.value)]}")
|
||||||
|
|
||||||
# Buchungen
|
# Buchungen
|
||||||
|
|
||||||
with ui.row():
|
with ui.row():
|
||||||
counter = 0
|
|
||||||
|
|
||||||
for i in timestamps:
|
if len(timestamps_dict[day]) > 0:
|
||||||
actual_timestamp = datetime.datetime.fromtimestamp(int(i))
|
timestamps_dict[day].sort()
|
||||||
timestamp_day = actual_timestamp.strftime('%-d')
|
|
||||||
|
|
||||||
if int(timestamp_day) == int(day):
|
def edit_entry(t_stamp, day):
|
||||||
def edit_entry(t_stamp, day):
|
|
||||||
with ui.dialog() as edit_dialog, ui.card():
|
|
||||||
ui.markdown("###Eintrag bearbeiten")
|
|
||||||
timestamp = datetime.datetime.fromtimestamp(int(t_stamp))
|
|
||||||
input_time = ui.time().classes('w-full justify-center')
|
|
||||||
input_time.value = timestamp.strftime('%H:%M')
|
|
||||||
|
|
||||||
def save_entry(day):
|
with ui.dialog() as edit_dialog, ui.card():
|
||||||
|
ui.markdown("###Eintrag bearbeiten")
|
||||||
|
timestamp = datetime.datetime.fromtimestamp(int(t_stamp))
|
||||||
|
input_time = ui.time().classes('w-full justify-center')
|
||||||
|
|
||||||
position = timestamps.index(t_stamp)
|
input_time.value = timestamp.strftime('%H:%M')
|
||||||
new_time_stamp = datetime.datetime(int(select_year.value), int(select_month.value), day, int(input_time.value[:2]), int(input_time.value[-2:]))
|
|
||||||
timestamps[position] = str(
|
|
||||||
int(new_time_stamp.timestamp())) + "\n"
|
|
||||||
# print(timestamps)
|
|
||||||
current_user = user(time_user.value)
|
|
||||||
current_user.write_edited_timestamps(timestamps, select_year.value, select_month.value)
|
|
||||||
edit_dialog.close()
|
|
||||||
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}")
|
|
||||||
ui.notify("Eintrag gespeichert")
|
|
||||||
|
|
||||||
def del_entry():
|
def save_entry(day):
|
||||||
timestamps.remove(t_stamp)
|
nonlocal t_stamp
|
||||||
timestamps.sort()
|
t_stamp = f"{t_stamp}\n"
|
||||||
current_user = user(time_user.value)
|
position = timestamps.index(t_stamp)
|
||||||
current_user.write_edited_timestamps(timestamps, select_year.value, select_month.value)
|
new_time_stamp = datetime.datetime(int(select_year.value),
|
||||||
edit_dialog.close()
|
int(select_month.value), day,
|
||||||
calendar_card.clear()
|
int(input_time.value[:2]),
|
||||||
update_month_and_year()
|
int(input_time.value[-2:]))
|
||||||
month_header.set_content(f"###Buchungen für {calendar.month_name[int(select_month.value)]} {select_year.value}")
|
timestamps[position] = str(
|
||||||
ui.notify("Eintrag gelöscht")
|
int(new_time_stamp.timestamp())) + "\n"
|
||||||
|
|
||||||
|
current_user = user(time_user.value)
|
||||||
|
current_user.write_edited_timestamps(timestamps,
|
||||||
|
select_year.value,
|
||||||
|
select_month.value)
|
||||||
|
edit_dialog.close()
|
||||||
|
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}")
|
||||||
|
ui.notify("Eintrag gespeichert")
|
||||||
|
|
||||||
|
def del_entry():
|
||||||
|
nonlocal t_stamp
|
||||||
|
t_stamp = f"{t_stamp}\n"
|
||||||
|
timestamps.remove(t_stamp)
|
||||||
|
timestamps.sort()
|
||||||
|
current_user = user(time_user.value)
|
||||||
|
current_user.write_edited_timestamps(timestamps,
|
||||||
|
select_year.value,
|
||||||
|
select_month.value)
|
||||||
|
edit_dialog.close()
|
||||||
|
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}")
|
||||||
|
ui.notify("Eintrag gelöscht")
|
||||||
|
|
||||||
|
with ui.row():
|
||||||
|
ui.button("Speichern",
|
||||||
|
on_click=lambda day=day: save_entry(day))
|
||||||
|
ui.button("Löschen", on_click=del_entry)
|
||||||
|
ui.button("Abbrechen", on_click=edit_dialog.close)
|
||||||
|
|
||||||
|
edit_dialog.open()
|
||||||
|
|
||||||
|
for i in range(len(timestamps_dict[day])):
|
||||||
|
try:
|
||||||
|
temp_pair = [ timestamps_dict[day][i] , timestamps_dict[day][i+1] ]
|
||||||
|
with ui.card():
|
||||||
with ui.row():
|
with ui.row():
|
||||||
ui.button("Speichern",
|
for j in temp_pair:
|
||||||
on_click=lambda day=day: save_entry(day))
|
ui.button(datetime.datetime.fromtimestamp(int(j)).strftime('%H:%M'), on_click=lambda t_stamp=j, day=day: edit_entry(t_stamp, day))
|
||||||
ui.button("Löschen", on_click=del_entry)
|
except:
|
||||||
ui.button("Abbrechen", on_click=edit_dialog.close)
|
if len(timestamps_dict[day]) % 2 != 0:
|
||||||
|
with ui.card():
|
||||||
|
ui.button(datetime.datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M'), on_click=lambda t_stamp=timestamps_dict[day][i], day=day: edit_entry(t_stamp, day))
|
||||||
|
|
||||||
edit_dialog.open()
|
# Arbeitszeit Ist bestimmen
|
||||||
counter += 1
|
timestamps_of_this_day = []
|
||||||
|
|
||||||
ui.button(actual_timestamp.strftime('%H:%M'), on_click=lambda t_stamp=i, day=day: edit_entry(t_stamp, day))
|
# Suche mir alle timestamps für diesen Tag
|
||||||
if counter % 2 != 0:
|
for i in timestamps:
|
||||||
ui.markdown("-")
|
actual_timestamp = datetime.datetime.fromtimestamp(int(i))
|
||||||
else:
|
timestamp_day = actual_timestamp.strftime('%-d')
|
||||||
ui.markdown("|")
|
|
||||||
|
if int(timestamp_day) == int(day):
|
||||||
|
timestamps_of_this_day.append(i)
|
||||||
|
|
||||||
|
timestamps_of_this_day.sort()
|
||||||
|
time_sum = 0
|
||||||
|
if len(timestamps_of_this_day) > 1:
|
||||||
|
|
||||||
|
if len(timestamps_of_this_day) % 2 == 0:
|
||||||
|
for i in range(0, len(timestamps_of_this_day), 2):
|
||||||
|
time_delta = int(
|
||||||
|
timestamps_of_this_day[i + 1]) - int(
|
||||||
|
timestamps_of_this_day[i])
|
||||||
|
time_sum = time_sum + time_delta
|
||||||
|
else:
|
||||||
|
for i in range(0, len(timestamps_of_this_day) - 1, 2):
|
||||||
|
time_delta = int(
|
||||||
|
timestamps_of_this_day[i + 1]) - int(
|
||||||
|
timestamps_of_this_day[i])
|
||||||
|
time_sum = time_sum + time_delta
|
||||||
|
|
||||||
|
ui.markdown(convert_seconds_to_hours(time_sum))
|
||||||
|
else:
|
||||||
|
ui.markdown("Kein")
|
||||||
|
|
||||||
# Arbeitszeitsoll bestimmen
|
# Arbeitszeitsoll bestimmen
|
||||||
workhour_entries = list(current_user.workhours)
|
workhour_entries = list(current_user.workhours)
|
||||||
@ -279,35 +332,6 @@ def page_admin():
|
|||||||
ui.markdown(f"{current_user.workhours[entry][str(weekday_index)]} h")
|
ui.markdown(f"{current_user.workhours[entry][str(weekday_index)]} h")
|
||||||
found_match = True
|
found_match = True
|
||||||
|
|
||||||
# Arbeitszeit Ist bestimmen
|
|
||||||
timestamps_of_this_day = [ ]
|
|
||||||
|
|
||||||
# Suche mir alle timestamps für diesen Tag
|
|
||||||
for i in timestamps:
|
|
||||||
actual_timestamp = datetime.datetime.fromtimestamp(int(i))
|
|
||||||
timestamp_day = actual_timestamp.strftime('%-d')
|
|
||||||
|
|
||||||
if int(timestamp_day) == int(day):
|
|
||||||
timestamps_of_this_day.append(i)
|
|
||||||
|
|
||||||
timestamps_of_this_day.sort()
|
|
||||||
time_sum = 0
|
|
||||||
if len(timestamps_of_this_day) > 1:
|
|
||||||
|
|
||||||
|
|
||||||
if len(timestamps_of_this_day) % 2 == 0:
|
|
||||||
for i in range(0, len(timestamps_of_this_day), 2):
|
|
||||||
time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i])
|
|
||||||
time_sum = time_sum + time_delta
|
|
||||||
else:
|
|
||||||
for i in range(0, len(timestamps_of_this_day) - 1, 2):
|
|
||||||
time_delta = int(timestamps_of_this_day[i+1]) - int(timestamps_of_this_day[i])
|
|
||||||
time_sum = time_sum + time_delta
|
|
||||||
|
|
||||||
ui.markdown(convert_seconds_to_hours(time_sum))
|
|
||||||
else:
|
|
||||||
ui.markdown("Kein")
|
|
||||||
|
|
||||||
# Plus und Minuszeit für den Tag berechnen
|
# Plus und Minuszeit für den Tag berechnen
|
||||||
if time.time() > day_in_list.timestamp():
|
if time.time() > day_in_list.timestamp():
|
||||||
time_duty = int(current_user.workhours[entry][str(weekday_index)]) * 3600
|
time_duty = int(current_user.workhours[entry][str(weekday_index)]) * 3600
|
||||||
|
Loading…
x
Reference in New Issue
Block a user