Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -72,13 +72,19 @@ def toggle_modal(n1, n2, is_open):
|
|
72 |
Output('add-url-feedback', 'children'),
|
73 |
Output('add-url-status', 'data')],
|
74 |
[Input('add-url-button', 'n_clicks'),
|
75 |
-
Input('add-url-status', 'data')
|
|
|
76 |
[State('new-url-name', 'value'),
|
77 |
State('new-url-link', 'value')]
|
78 |
)
|
79 |
-
def update_url_list(
|
80 |
ctx = dash.callback_context
|
81 |
-
if ctx.
|
|
|
|
|
|
|
|
|
|
|
82 |
try:
|
83 |
conn = get_db_connection()
|
84 |
c = conn.cursor()
|
@@ -92,6 +98,15 @@ def update_url_list(n_clicks, status, new_name, new_link):
|
|
92 |
print(f"Error adding URL: {e}")
|
93 |
feedback = html.Div("Error adding URL. Please try again.", style={'color': 'red'})
|
94 |
status = 'error'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
else:
|
96 |
feedback = None
|
97 |
status = ''
|
@@ -146,25 +161,6 @@ def update_iframe(n_clicks):
|
|
146 |
return result['url']
|
147 |
return dash.no_update
|
148 |
|
149 |
-
@callback(
|
150 |
-
Output('url-list', 'children', allow_duplicate=True),
|
151 |
-
Input({'type': 'delete-button', 'index': dash.ALL}, 'n_clicks'),
|
152 |
-
prevent_initial_call=True
|
153 |
-
)
|
154 |
-
def delete_url(n_clicks):
|
155 |
-
ctx = dash.callback_context
|
156 |
-
if not ctx.triggered:
|
157 |
-
return dash.no_update
|
158 |
-
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
159 |
-
delete_id = eval(button_id)['index']
|
160 |
-
conn = get_db_connection()
|
161 |
-
c = conn.cursor()
|
162 |
-
c.execute("DELETE FROM links WHERE id = ?", (delete_id,))
|
163 |
-
conn.commit()
|
164 |
-
conn.close()
|
165 |
-
# Fix: Pass all required arguments to update_url_list
|
166 |
-
return update_url_list(None, '', None, None)
|
167 |
-
|
168 |
if __name__ == '__main__':
|
169 |
print("Starting the Dash application...")
|
170 |
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
72 |
Output('add-url-feedback', 'children'),
|
73 |
Output('add-url-status', 'data')],
|
74 |
[Input('add-url-button', 'n_clicks'),
|
75 |
+
Input('add-url-status', 'data'),
|
76 |
+
Input({'type': 'delete-button', 'index': dash.ALL}, 'n_clicks')],
|
77 |
[State('new-url-name', 'value'),
|
78 |
State('new-url-link', 'value')]
|
79 |
)
|
80 |
+
def update_url_list(add_clicks, status, delete_clicks, new_name, new_link):
|
81 |
ctx = dash.callback_context
|
82 |
+
if not ctx.triggered:
|
83 |
+
raise dash.exceptions.PreventUpdate
|
84 |
+
|
85 |
+
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
86 |
+
|
87 |
+
if triggered_id == 'add-url-button' and new_name and new_link:
|
88 |
try:
|
89 |
conn = get_db_connection()
|
90 |
c = conn.cursor()
|
|
|
98 |
print(f"Error adding URL: {e}")
|
99 |
feedback = html.Div("Error adding URL. Please try again.", style={'color': 'red'})
|
100 |
status = 'error'
|
101 |
+
elif 'delete-button' in triggered_id:
|
102 |
+
delete_id = eval(triggered_id)['index']
|
103 |
+
conn = get_db_connection()
|
104 |
+
c = conn.cursor()
|
105 |
+
c.execute("DELETE FROM links WHERE id = ?", (delete_id,))
|
106 |
+
conn.commit()
|
107 |
+
conn.close()
|
108 |
+
feedback = html.Div("URL deleted successfully!", style={'color': 'green'})
|
109 |
+
status = 'deleted'
|
110 |
else:
|
111 |
feedback = None
|
112 |
status = ''
|
|
|
161 |
return result['url']
|
162 |
return dash.no_update
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
if __name__ == '__main__':
|
165 |
print("Starting the Dash application...")
|
166 |
app.run(debug=True, host='0.0.0.0', port=7860)
|