Update app.py
Browse files71 unmodified lines727374757677787980811 unmodified line838485868788899091929371 unmodified linesreturn gr.update(value="", visible=False), df, gr.update(choices=choices, value=None)def hapus_pesanan(selected_idx):if not os.path.isfile(file_path):return pd.DataFrame(), gr.update(value="File pesanan tidak ditemukan!", visible=True), gr.update(choices=[], value=None)df = pd.read_csv(file_path)if not selected_idx: # Kalau kosong/Nonechoices = [(str(i), f"{i+1}. {row['Nama']} | {row['Kontak']} | {row['Tanggal Kirim']} | {row['Pesanan']} | Total: Rp{row['Total']:,}")for i, row in df.iterrows()1 unmodified linereturn df, gr.update(value="Pilih pesanan yang ingin dihapus!", visible=True), gr.update(choices=choices, value=None)try:idx = int(selected_idx)except Exception:choices = [(str(i), f"{i+1}. {row['Nama']} | {row['Kontak']} | {row['Tanggal Kirim']} | {row['Pesanan']} | Total: Rp{row['Total']:,}")for i, row in df.iterrows()]return df, gr.update(value="Pilihan salah!", visible=True), gr.update(choices=choices, value=None)if 0 <= idx < len(df):df = df.drop(idx).reset_index(drop=True)71 unmodified lines727374757677787980818283841 unmodified line86878889909192939495969771 unmodified linesreturn gr.update(value="", visible=False), df, gr.update(choices=choices, value=None)def hapus_pesanan(selected_idx):import sysprint("DEBUG selected_idx:", selected_idx, file=sys.stderr)if not os.path.isfile(file_path):return pd.DataFrame(), gr.update(value="File pesanan tidak ditemukan!", visible=True), gr.update(choices=[], value=None)df = pd.read_csv(file_path)if selected_idx is None or selected_idx == "" or selected_idx == []:# Belum dipilih sama sekalichoices = [(str(i), f"{i+1}. {row['Nama']} | {row['Kontak']} | {row['Tanggal Kirim']} | {row['Pesanan']} | Total: Rp{row['Total']:,}")for i, row in df.iterrows()1 unmodified linereturn df, gr.update(value="Pilih pesanan yang ingin dihapus!", visible=True), gr.update(choices=choices, value=None)try:idx = int(selected_idx)except Exception as e:choices = [(str(i), f"{i+1}. {row['Nama']} | {row['Kontak']} | {row['Tanggal Kirim']} | {row['Pesanan']} | Total: Rp{row['Total']:,}")for i, row in df.iterrows()]print("ERROR casting index:", selected_idx, e, file=sys.stderr)return df, gr.update(value="Pilihan salah!", visible=True), gr.update(choices=choices, value=None)if 0 <= idx < len(df):df = df.drop(idx).reset_index(drop=True)
app.py+6-2