Spaces:
Sleeping
Sleeping
Commit
·
5e815bc
1
Parent(s):
9159c1e
Update 2026-01-30 09:45:40
Browse files
app.py
CHANGED
|
@@ -46,7 +46,7 @@ def add_item(category, section, title, content):
|
|
| 46 |
return "✅ Added!", load_table("", "", "")
|
| 47 |
|
| 48 |
def load_table(category_filter, section_filter, title_filter):
|
| 49 |
-
"""Load and filter table data"""
|
| 50 |
conn = sqlite3.connect(DB_PATH)
|
| 51 |
|
| 52 |
query = """
|
|
@@ -73,6 +73,10 @@ def load_table(category_filter, section_filter, title_filter):
|
|
| 73 |
df = pd.read_sql_query(query, conn, params=params)
|
| 74 |
conn.close()
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
return df
|
| 77 |
|
| 78 |
def update_item(item_id, category, section, title, content):
|
|
@@ -108,12 +112,23 @@ def delete_item(item_id):
|
|
| 108 |
return "✅ Deleted!", load_table("", "", "")
|
| 109 |
|
| 110 |
def load_for_edit(df, evt: gr.SelectData):
|
| 111 |
-
"""Load selected row for editing"""
|
| 112 |
if df is None or df.empty:
|
| 113 |
return None, "", "", "", ""
|
| 114 |
|
| 115 |
row = df.iloc[evt.index[0]]
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
def get_char_count(text):
|
| 119 |
"""Count characters"""
|
|
@@ -177,7 +192,6 @@ with gr.Blocks(title="Text Archive") as app:
|
|
| 177 |
value=load_table("", "", ""),
|
| 178 |
label="",
|
| 179 |
interactive=False,
|
| 180 |
-
wrap=True,
|
| 181 |
column_widths=["5%", "12%", "12%", "20%", "40%", "11%"]
|
| 182 |
)
|
| 183 |
|
|
|
|
| 46 |
return "✅ Added!", load_table("", "", "")
|
| 47 |
|
| 48 |
def load_table(category_filter, section_filter, title_filter):
|
| 49 |
+
"""Load and filter table data with truncated content preview"""
|
| 50 |
conn = sqlite3.connect(DB_PATH)
|
| 51 |
|
| 52 |
query = """
|
|
|
|
| 73 |
df = pd.read_sql_query(query, conn, params=params)
|
| 74 |
conn.close()
|
| 75 |
|
| 76 |
+
# Truncate content for display (show first 100 chars)
|
| 77 |
+
if not df.empty:
|
| 78 |
+
df['content'] = df['content'].apply(lambda x: (x[:100] + '...') if len(x) > 100 else x)
|
| 79 |
+
|
| 80 |
return df
|
| 81 |
|
| 82 |
def update_item(item_id, category, section, title, content):
|
|
|
|
| 112 |
return "✅ Deleted!", load_table("", "", "")
|
| 113 |
|
| 114 |
def load_for_edit(df, evt: gr.SelectData):
|
| 115 |
+
"""Load selected row for editing - fetch full content from database"""
|
| 116 |
if df is None or df.empty:
|
| 117 |
return None, "", "", "", ""
|
| 118 |
|
| 119 |
row = df.iloc[evt.index[0]]
|
| 120 |
+
item_id = row['id']
|
| 121 |
+
|
| 122 |
+
# Get full content from database
|
| 123 |
+
conn = sqlite3.connect(DB_PATH)
|
| 124 |
+
cursor = conn.cursor()
|
| 125 |
+
cursor.execute("SELECT category, section, title, content FROM items WHERE id=?", (item_id,))
|
| 126 |
+
result = cursor.fetchone()
|
| 127 |
+
conn.close()
|
| 128 |
+
|
| 129 |
+
if result:
|
| 130 |
+
return item_id, result[0], result[1], result[2], result[3]
|
| 131 |
+
return None, "", "", "", ""
|
| 132 |
|
| 133 |
def get_char_count(text):
|
| 134 |
"""Count characters"""
|
|
|
|
| 192 |
value=load_table("", "", ""),
|
| 193 |
label="",
|
| 194 |
interactive=False,
|
|
|
|
| 195 |
column_widths=["5%", "12%", "12%", "20%", "40%", "11%"]
|
| 196 |
)
|
| 197 |
|