7
7
8
8
from collections import defaultdict
9
9
from datetime import timedelta
10
+ from itertools import islice
10
11
11
12
from flask import g
12
13
from sqlalchemy .orm import subqueryload
@@ -57,6 +58,11 @@ class SettingsForm(IndicoForm):
57
58
timeout = FloatField (_ ('Request timeout' ), [NumberRange (min = 0.25 )], description = _ ('Request timeout in seconds' ))
58
59
max_event_duration = TimeDeltaField (_ ('Maximum Duration' ), [DataRequired ()], units = ('days' ,),
59
60
description = _ ('Events lasting longer will not be sent to Exchange' ))
61
+ max_category_events = IntegerField (
62
+ _ ('Maximum number events to edit in the calendar at once' ), [NumberRange (min = - 1 )],
63
+ description = _ ('If a user favorites a very large category, there may be too many events to edit in the calendar '
64
+ 'at once. This setting limits the number of upcoming events to edit when a category is '
65
+ 'favorited/unfavorited. If you set this to -1, all events will be added/deleted.' ))
60
66
61
67
62
68
class OutlookUserPreferences (ExtraUserPreferences ):
@@ -172,7 +178,8 @@ class OutlookPlugin(IndicoPlugin):
172
178
'reminder_minutes' : 15 ,
173
179
'id_prefix' : 'indico_' ,
174
180
'timeout' : 3 ,
175
- 'max_event_duration' : timedelta (days = 30 )
181
+ 'max_event_duration' : timedelta (days = 30 ),
182
+ 'max_category_events' : - 1 ,
176
183
}
177
184
settings_converters = {
178
185
'max_event_duration' : TimedeltaConverter
@@ -229,6 +236,12 @@ def _user_tracks_favorite_categories(self, user):
229
236
return OutlookPlugin .user_settings .get (user , 'favorite_categories' ,
230
237
OutlookPlugin .default_user_settings ['favorite_categories' ])
231
238
239
+ def _event_limit (self ):
240
+ limit = OutlookPlugin .settings .get ('max_category_events' )
241
+ if limit == - 1 :
242
+ return None
243
+ return limit
244
+
232
245
def favorite_event_added (self , user , event , ** kwargs ):
233
246
if not self ._user_tracks_favorite_events (user ):
234
247
return
@@ -251,7 +264,7 @@ def favorite_category_added(self, user, category, **kwargs):
251
264
~ Event .is_deleted )
252
265
.options (subqueryload ('acl_entries' ))
253
266
.order_by (Event .start_dt , Event .id ))
254
- events = [ e for e in query if e .can_access (user )]
267
+ events = islice (( e for e in query if e .can_access (user )), self . _event_limit ())
255
268
for event in events :
256
269
self ._record_change (event , user , OutlookAction .add )
257
270
self .logger .info ('Favorite category added: user %s added event %r' , user , event )
@@ -268,7 +281,7 @@ def favorite_category_removed(self, user, category, **kwargs):
268
281
~ Event .is_deleted )
269
282
.options (subqueryload ('acl_entries' ))
270
283
.order_by (Event .start_dt , Event .id ))
271
- events = [ e for e in query if e .can_access (user )]
284
+ events = islice (( e for e in query if e .can_access (user )), self . _event_limit ())
272
285
for event in events :
273
286
self ._record_change (event , user , OutlookAction .remove )
274
287
self .logger .info ('Favorite category added: user %s added event %r' , user , event )
0 commit comments