3
3
from loguru import logger
4
4
from functools import wraps
5
5
6
+ from changedetectionio .blueprint .ui .ajax import constuct_ui_ajax_blueprint
6
7
from changedetectionio .store import ChangeDetectionStore
7
8
from changedetectionio .blueprint .ui .edit import construct_blueprint as construct_edit_blueprint
8
9
from changedetectionio .blueprint .ui .notification import construct_blueprint as construct_notification_blueprint
9
10
from changedetectionio .blueprint .ui .views import construct_blueprint as construct_views_blueprint
10
11
11
- def construct_blueprint (datastore : ChangeDetectionStore , update_q , running_update_threads , queuedWatchMetaData ):
12
+ def construct_blueprint (datastore : ChangeDetectionStore , update_q , running_update_threads , queuedWatchMetaData , watch_check_update ):
12
13
ui_blueprint = Blueprint ('ui' , __name__ , template_folder = "templates" )
13
14
14
15
# Register the edit blueprint
@@ -20,9 +21,12 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, running_updat
20
21
ui_blueprint .register_blueprint (notification_blueprint )
21
22
22
23
# Register the views blueprint
23
- views_blueprint = construct_views_blueprint (datastore , update_q , queuedWatchMetaData )
24
+ views_blueprint = construct_views_blueprint (datastore , update_q , queuedWatchMetaData , watch_check_update )
24
25
ui_blueprint .register_blueprint (views_blueprint )
25
-
26
+
27
+ ui_ajax_blueprint = constuct_ui_ajax_blueprint (datastore , update_q , running_update_threads , queuedWatchMetaData , watch_check_update )
28
+ ui_blueprint .register_blueprint (ui_ajax_blueprint )
29
+
26
30
# Import the login decorator
27
31
from changedetectionio .auth_decorator import login_optionally_required
28
32
@@ -35,7 +39,6 @@ def clear_watch_history(uuid):
35
39
flash ('Watch not found' , 'error' )
36
40
else :
37
41
flash ("Cleared snapshot history for watch {}" .format (uuid ))
38
-
39
42
return redirect (url_for ('watchlist.index' ))
40
43
41
44
@ui_blueprint .route ("/clear_history" , methods = ['GET' , 'POST' ])
@@ -47,7 +50,6 @@ def clear_all_history():
47
50
if confirmtext == 'clear' :
48
51
for uuid in datastore .data ['watching' ].keys ():
49
52
datastore .clear_watch_history (uuid )
50
-
51
53
flash ("Cleared snapshot history for all watches" )
52
54
else :
53
55
flash ('Incorrect confirmation text.' , 'error' )
@@ -153,68 +155,59 @@ def form_watch_checknow():
153
155
@login_optionally_required
154
156
def form_watch_list_checkbox_operations ():
155
157
op = request .form ['op' ]
156
- uuids = request .form .getlist ('uuids' )
158
+ uuids = [ u . strip () for u in request .form .getlist ('uuids' ) if u ]
157
159
158
160
if (op == 'delete' ):
159
161
for uuid in uuids :
160
- uuid = uuid .strip ()
161
162
if datastore .data ['watching' ].get (uuid ):
162
- datastore .delete (uuid . strip () )
163
+ datastore .delete (uuid )
163
164
flash ("{} watches deleted" .format (len (uuids )))
164
165
165
166
elif (op == 'pause' ):
166
167
for uuid in uuids :
167
- uuid = uuid .strip ()
168
168
if datastore .data ['watching' ].get (uuid ):
169
- datastore .data ['watching' ][uuid . strip () ]['paused' ] = True
169
+ datastore .data ['watching' ][uuid ]['paused' ] = True
170
170
flash ("{} watches paused" .format (len (uuids )))
171
171
172
172
elif (op == 'unpause' ):
173
173
for uuid in uuids :
174
- uuid = uuid .strip ()
175
174
if datastore .data ['watching' ].get (uuid ):
176
175
datastore .data ['watching' ][uuid .strip ()]['paused' ] = False
177
176
flash ("{} watches unpaused" .format (len (uuids )))
178
177
179
178
elif (op == 'mark-viewed' ):
180
179
for uuid in uuids :
181
- uuid = uuid .strip ()
182
180
if datastore .data ['watching' ].get (uuid ):
183
181
datastore .set_last_viewed (uuid , int (time .time ()))
184
182
flash ("{} watches updated" .format (len (uuids )))
185
183
186
184
elif (op == 'mute' ):
187
185
for uuid in uuids :
188
- uuid = uuid .strip ()
189
186
if datastore .data ['watching' ].get (uuid ):
190
- datastore .data ['watching' ][uuid . strip () ]['notification_muted' ] = True
187
+ datastore .data ['watching' ][uuid ]['notification_muted' ] = True
191
188
flash ("{} watches muted" .format (len (uuids )))
192
189
193
190
elif (op == 'unmute' ):
194
191
for uuid in uuids :
195
- uuid = uuid .strip ()
196
192
if datastore .data ['watching' ].get (uuid ):
197
- datastore .data ['watching' ][uuid . strip () ]['notification_muted' ] = False
193
+ datastore .data ['watching' ][uuid ]['notification_muted' ] = False
198
194
flash ("{} watches un-muted" .format (len (uuids )))
199
195
200
196
elif (op == 'recheck' ):
201
197
for uuid in uuids :
202
- uuid = uuid .strip ()
203
198
if datastore .data ['watching' ].get (uuid ):
204
199
# Recheck and require a full reprocessing
205
200
update_q .put (queuedWatchMetaData .PrioritizedItem (priority = 1 , item = {'uuid' : uuid }))
206
201
flash ("{} watches queued for rechecking" .format (len (uuids )))
207
202
208
203
elif (op == 'clear-errors' ):
209
204
for uuid in uuids :
210
- uuid = uuid .strip ()
211
205
if datastore .data ['watching' ].get (uuid ):
212
206
datastore .data ['watching' ][uuid ]["last_error" ] = False
213
207
flash (f"{ len (uuids )} watches errors cleared" )
214
208
215
209
elif (op == 'clear-history' ):
216
210
for uuid in uuids :
217
- uuid = uuid .strip ()
218
211
if datastore .data ['watching' ].get (uuid ):
219
212
datastore .clear_watch_history (uuid )
220
213
flash ("{} watches cleared/reset." .format (len (uuids )))
@@ -224,12 +217,11 @@ def form_watch_list_checkbox_operations():
224
217
default_notification_format_for_watch
225
218
)
226
219
for uuid in uuids :
227
- uuid = uuid .strip ()
228
220
if datastore .data ['watching' ].get (uuid ):
229
- datastore .data ['watching' ][uuid . strip () ]['notification_title' ] = None
230
- datastore .data ['watching' ][uuid . strip () ]['notification_body' ] = None
231
- datastore .data ['watching' ][uuid . strip () ]['notification_urls' ] = []
232
- datastore .data ['watching' ][uuid . strip () ]['notification_format' ] = default_notification_format_for_watch
221
+ datastore .data ['watching' ][uuid ]['notification_title' ] = None
222
+ datastore .data ['watching' ][uuid ]['notification_body' ] = None
223
+ datastore .data ['watching' ][uuid ]['notification_urls' ] = []
224
+ datastore .data ['watching' ][uuid ]['notification_format' ] = default_notification_format_for_watch
233
225
flash ("{} watches set to use default notification settings" .format (len (uuids )))
234
226
235
227
elif (op == 'assign-tag' ):
@@ -238,7 +230,6 @@ def form_watch_list_checkbox_operations():
238
230
tag_uuid = datastore .add_tag (title = op_extradata )
239
231
if op_extradata and tag_uuid :
240
232
for uuid in uuids :
241
- uuid = uuid .strip ()
242
233
if datastore .data ['watching' ].get (uuid ):
243
234
# Bug in old versions caused by bad edit page/tag handler
244
235
if isinstance (datastore .data ['watching' ][uuid ]['tags' ], str ):
@@ -248,6 +239,11 @@ def form_watch_list_checkbox_operations():
248
239
249
240
flash (f"{ len (uuids )} watches were tagged" )
250
241
242
+ if uuids :
243
+ for uuid in uuids :
244
+ # with app.app_context():
245
+ watch_check_update .send (watch_uuid = uuid )
246
+
251
247
return redirect (url_for ('watchlist.index' ))
252
248
253
249
0 commit comments