Skip to content

Commit 04c5130

Browse files
committed
Allow limiting the number of events to edit at once
1 parent 8c66133 commit 04c5130

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

outlook/indico_outlook/plugin.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from collections import defaultdict
99
from datetime import timedelta
10+
from itertools import islice
1011

1112
from flask import g
1213
from sqlalchemy.orm import subqueryload
@@ -57,6 +58,11 @@ class SettingsForm(IndicoForm):
5758
timeout = FloatField(_('Request timeout'), [NumberRange(min=0.25)], description=_('Request timeout in seconds'))
5859
max_event_duration = TimeDeltaField(_('Maximum Duration'), [DataRequired()], units=('days',),
5960
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.'))
6066

6167

6268
class OutlookUserPreferences(ExtraUserPreferences):
@@ -172,7 +178,8 @@ class OutlookPlugin(IndicoPlugin):
172178
'reminder_minutes': 15,
173179
'id_prefix': 'indico_',
174180
'timeout': 3,
175-
'max_event_duration': timedelta(days=30)
181+
'max_event_duration': timedelta(days=30),
182+
'max_category_events': -1,
176183
}
177184
settings_converters = {
178185
'max_event_duration': TimedeltaConverter
@@ -229,6 +236,12 @@ def _user_tracks_favorite_categories(self, user):
229236
return OutlookPlugin.user_settings.get(user, 'favorite_categories',
230237
OutlookPlugin.default_user_settings['favorite_categories'])
231238

239+
def _event_limit(self):
240+
limit = OutlookPlugin.settings.get('max_category_events')
241+
if limit == -1:
242+
return None
243+
return limit
244+
232245
def favorite_event_added(self, user, event, **kwargs):
233246
if not self._user_tracks_favorite_events(user):
234247
return
@@ -251,7 +264,7 @@ def favorite_category_added(self, user, category, **kwargs):
251264
~Event.is_deleted)
252265
.options(subqueryload('acl_entries'))
253266
.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())
255268
for event in events:
256269
self._record_change(event, user, OutlookAction.add)
257270
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):
268281
~Event.is_deleted)
269282
.options(subqueryload('acl_entries'))
270283
.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())
272285
for event in events:
273286
self._record_change(event, user, OutlookAction.remove)
274287
self.logger.info('Favorite category added: user %s added event %r', user, event)

0 commit comments

Comments
 (0)