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