Merge branch 'api-info-json' into web_ui
This commit is contained in:
commit
076a21ca97
14
admin.py
14
admin.py
@ -532,16 +532,13 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
username_labels["admin"] = ui.markdown("Administrator:")
|
||||
# Textarea für Admin
|
||||
note_labels["admin"] = ui.textarea()
|
||||
del_buttons["admin"] = ui.button(icon='remove', on_click=lambda user="admin": del_note_entry(user))
|
||||
|
||||
for name, text in notes.items():
|
||||
if name != "admin":
|
||||
noteuser = "user"
|
||||
username_labels[noteuser] = ui.markdown(current_user.fullname)
|
||||
note_labels[noteuser] = ui.markdown(text)
|
||||
else:
|
||||
noteuser = "admin"
|
||||
note_labels[noteuser].set_value(text)
|
||||
del_buttons[noteuser] = ui.button(icon='remove', on_click=lambda user=noteuser: del_note_entry(user))
|
||||
username_labels["user"] = ui.markdown(current_user.fullname)
|
||||
note_labels["user"] = ui.markdown(text)
|
||||
del_buttons["user"] = ui.button(icon='remove', on_click=lambda user="user": del_note_entry(user))
|
||||
|
||||
with ui.row():
|
||||
ui.button("OK", on_click=save_notes)
|
||||
@ -554,6 +551,9 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
menu_item = ui.menu_item("Zeiteintrag hinzufügen", lambda day=day: add_entry(day))
|
||||
if archive_status:
|
||||
menu_item.disable()
|
||||
if datetime.datetime.now().day < day:
|
||||
menu_item.disable()
|
||||
menu_item.tooltip("Kann keine Zeiteinträge für die Zukunft vornehmen.")
|
||||
ui.separator()
|
||||
menu_item = ui.menu_item("Notizen bearbeiten", lambda day=day: edit_notes(day))
|
||||
if archive_status:
|
||||
|
79
api.py
79
api.py
@ -81,9 +81,8 @@ def page_overview_month(username: str, year: int, month: int):
|
||||
color_day = color_weekend
|
||||
|
||||
current_day_date = f"{datetime(year, month, day).strftime('%a')}, {day}.{month}.{year}"
|
||||
with ui.link_target(day):
|
||||
ui.markdown(current_day_date).classes(f'border px-{pad_x} py-{pad_y} bg-{color_day}')
|
||||
|
||||
with ui.link_target(day).classes(f'border px-{pad_x} py-{pad_y} bg-{color_day}'):
|
||||
ui.markdown(current_day_date)
|
||||
|
||||
# Abwesenheitseinträge
|
||||
booking_color = "inherit"
|
||||
@ -108,6 +107,20 @@ def page_overview_month(username: str, year: int, month: int):
|
||||
if len(timestamps_dict[day]) % 2 != 0:
|
||||
booking_text += datetime.fromtimestamp(int(timestamps_dict[day][i])).strftime('%H:%M') + " - ***Buchung fehlt!***"
|
||||
|
||||
day_notes = current_user.get_day_notes(year, month, day)
|
||||
just_once = True
|
||||
if len(day_notes) > 0:
|
||||
if len(timestamps_dict[day]) > 0 or day in list(map(int, list(user_absent))):
|
||||
booking_text += "<hr>"
|
||||
for user_key, notes in day_notes.items():
|
||||
if user_key == "admin":
|
||||
booking_text += f"Administrator:<br>{notes}"
|
||||
else:
|
||||
booking_text += f"{current_user.fullname}:<br>{notes}"
|
||||
if len(day_notes) > 1 and just_once:
|
||||
booking_text += "<hr>"
|
||||
just_once = False
|
||||
|
||||
booking_text_element = ui.markdown(booking_text).classes(f'border px-{pad_x} py-{pad_y} bg-{booking_color} text-{booking_text_color}')
|
||||
|
||||
# Ist-Zeiten berechnen
|
||||
@ -222,9 +235,9 @@ def page_overview_month(username: str, year: int, month: int):
|
||||
if total_absence_days > 0:
|
||||
ui.markdown("###Abwesenheitstage diesen Monat:")
|
||||
|
||||
with ui.grid(columns='auto 20%').classes(f'gap-0 border px-0 py-0'):
|
||||
with ui.grid(columns='auto 25%').classes(f'gap-0 border px-0 py-0'):
|
||||
|
||||
for key,value in absence_dict.items():
|
||||
for key, value in absence_dict.items():
|
||||
if value > 0:
|
||||
ui.markdown(absence_entries[key]['name']).classes(f"border px-{pad_x} py-{pad_y}")
|
||||
ui.markdown(str(value)).classes(f'border px-{pad_x} py-{pad_y} text-center')
|
||||
@ -434,3 +447,59 @@ def page_api_stamp(api_key: str):
|
||||
|
||||
if found_key == False:
|
||||
ui.label("Keinen passenden Benutzer gefunden")
|
||||
|
||||
@app.get("/api/json/{api_key}")
|
||||
def json_info(api_key: str):
|
||||
userlist = list_users()
|
||||
user_dict = {}
|
||||
# Dictionary mit Usernamen befüllen
|
||||
for i in userlist:
|
||||
user_dict[i] = ""
|
||||
for entry in list(user_dict):
|
||||
try:
|
||||
temp_user = user(entry)
|
||||
user_dict[entry] = temp_user.api_key
|
||||
except:
|
||||
pass
|
||||
|
||||
found_key = False
|
||||
|
||||
for user_key, api_value in user_dict.items():
|
||||
if api_key == api_value:
|
||||
current_user = user(user_key)
|
||||
now_dt = datetime.now()
|
||||
year = now_dt.year
|
||||
month = now_dt.month
|
||||
day = now_dt.day
|
||||
|
||||
found_key = True
|
||||
data = { }
|
||||
data["user"] = current_user.username
|
||||
if current_user.stamp_status() == status_in:
|
||||
data["status"] = 1
|
||||
else:
|
||||
data["status"] = 0
|
||||
absences = current_user.get_absence(now_dt.year, now_dt.month)
|
||||
data["absence"] = 0
|
||||
if str(now_dt.day) in list(absences):
|
||||
data["absence"] = absences[str(now_dt.day)]
|
||||
data["time"] = { }
|
||||
data["time"]["today"] = current_user.get_worked_time(now_dt.year, now_dt.month, now_dt.day)[0]
|
||||
|
||||
# Arbeitszeit berechnen
|
||||
months_time_sum = 0
|
||||
for checkday in range(1, day + 1):
|
||||
months_time_sum += (int(current_user.get_worked_time(year, month, checkday)[0]) - int(current_user.get_day_workhours(year, month, checkday))*3600)
|
||||
|
||||
time_saldo = months_time_sum + current_user.get_last_months_overtime(year, month)
|
||||
|
||||
data["time"]["overall"] = time_saldo
|
||||
data["vacation"] = { }
|
||||
data["vacation"]["claim"] = current_user.get_vacation_claim(now_dt.year, now_dt.month, now_dt.day)
|
||||
data["vacation"]["used"] = current_user.count_vacation_days(now_dt.year)
|
||||
data["vacation"]["remaining"] = data["vacation"]["claim"] - data["vacation"]["used"]
|
||||
return data
|
||||
break
|
||||
|
||||
if not found_key:
|
||||
return { "data": "none"}
|
21
users.py
21
users.py
@ -243,6 +243,7 @@ class user:
|
||||
return days_with_errors
|
||||
except:
|
||||
return [ ]
|
||||
|
||||
def archive_hours(self, year, month, overtime: int):
|
||||
|
||||
filename = f"{self.userfolder}/{year}-{month}.json"
|
||||
@ -259,6 +260,7 @@ class user:
|
||||
os.chmod(filename, S_IREAD)
|
||||
filename_txt = f"{self.userfolder}/{year}-{month}.txt"
|
||||
os.chmod(filename_txt, S_IREAD)
|
||||
|
||||
def get_last_months_overtime(self, year, month):
|
||||
try:
|
||||
if int(month) == 1:
|
||||
@ -301,6 +303,8 @@ class user:
|
||||
if len(note_dict) == 1:
|
||||
json_data["notes"][str(day)] = { }
|
||||
json_data["notes"][str(day)]["user"] = note_dict["user"]
|
||||
if json_data["notes"][str(day)]["user"] == "":
|
||||
del json_data["notes"][str(day)]["user"]
|
||||
else:
|
||||
json_data["notes"][str(day)] = note_dict
|
||||
|
||||
@ -340,7 +344,7 @@ class user:
|
||||
json_file.write(json_dict)
|
||||
|
||||
def get_day_workhours(self, year, month, day):
|
||||
global hours_to_work
|
||||
#global hours_to_work
|
||||
workhour_entries = list(self.workhours)
|
||||
workhour_entries.sort()
|
||||
day_to_check = datetime.datetime(int(year), int(month), int(day))
|
||||
@ -394,7 +398,20 @@ class user:
|
||||
claim = self.workhours[entry]["vacation"]
|
||||
break
|
||||
|
||||
return claim
|
||||
return int(claim)
|
||||
|
||||
def count_vacation_days(self, year):
|
||||
vacation_used = 0
|
||||
for month in range(0, 13):
|
||||
try:
|
||||
absence_dict = self.get_absence(year, month)
|
||||
for entry, absence_type in absence_dict.items():
|
||||
if absence_type == "U":
|
||||
vacation_used += 1
|
||||
|
||||
except:
|
||||
pass
|
||||
return vacation_used
|
||||
|
||||
def delete_photo(self):
|
||||
os.remove(self.photofile)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"archived": 1,
|
||||
"overtime": -877154,
|
||||
"overtime": -348226,
|
||||
"absence": {
|
||||
"7": "U",
|
||||
"8": "K",
|
||||
|
@ -2,7 +2,13 @@
|
||||
"archived": 0,
|
||||
"overtime": 0,
|
||||
"absence": {
|
||||
"2": "SO"
|
||||
"2": "SO",
|
||||
"8": "U",
|
||||
"9": "U",
|
||||
"10": "U",
|
||||
"11": "U",
|
||||
"12": "U",
|
||||
"13": "U"
|
||||
},
|
||||
"notes": {
|
||||
"5": {
|
||||
@ -20,6 +26,7 @@
|
||||
},
|
||||
"12": {
|
||||
"user": "Testtext"
|
||||
}
|
||||
},
|
||||
"14": {}
|
||||
}
|
||||
}
|
@ -8,4 +8,7 @@
|
||||
1746609037
|
||||
1747206908
|
||||
1747207022
|
||||
1747813500
|
||||
1747213977
|
||||
1747214813
|
||||
1747216800
|
||||
1747220619
|
||||
|
Loading…
x
Reference in New Issue
Block a user