Skip to content

Commit 39e75d4

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

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

outlook/indico_outlook/plugin.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class SettingsForm(IndicoForm):
5757
timeout = FloatField(_('Request timeout'), [NumberRange(min=0.25)], description=_('Request timeout in seconds'))
5858
max_event_duration = TimeDeltaField(_('Maximum Duration'), [DataRequired()], units=('days',),
5959
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.'))
6065

6166

6267
class OutlookUserPreferences(ExtraUserPreferences):
@@ -172,7 +177,8 @@ class OutlookPlugin(IndicoPlugin):
172177
'reminder_minutes': 15,
173178
'id_prefix': 'indico_',
174179
'timeout': 3,
175-
'max_event_duration': timedelta(days=30)
180+
'max_event_duration': timedelta(days=30),
181+
'max_category_events': -1,
176182
}
177183
settings_converters = {
178184
'max_event_duration': TimedeltaConverter
@@ -229,6 +235,12 @@ def _user_tracks_favorite_categories(self, user):
229235
return OutlookPlugin.user_settings.get(user, 'favorite_categories',
230236
OutlookPlugin.default_user_settings['favorite_categories'])
231237

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+
232244
def favorite_event_added(self, user, event, **kwargs):
233245
if not self._user_tracks_favorite_events(user):
234246
return
@@ -252,7 +264,7 @@ def favorite_category_added(self, user, category, **kwargs):
252264
.options(subqueryload('acl_entries'))
253265
.order_by(Event.start_dt, Event.id))
254266
events = [e for e in query if e.can_access(user)]
255-
for event in events:
267+
for event in self._event_limit(events):
256268
self._record_change(event, user, OutlookAction.add)
257269
self.logger.info('Favorite category added: user %s added event %r', user, event)
258270

@@ -269,7 +281,7 @@ def favorite_category_removed(self, user, category, **kwargs):
269281
.options(subqueryload('acl_entries'))
270282
.order_by(Event.start_dt, Event.id))
271283
events = [e for e in query if e.can_access(user)]
272-
for event in events:
284+
for event in self._event_limit(events):
273285
self._record_change(event, user, OutlookAction.remove)
274286
self.logger.info('Favorite category added: user %s added event %r', user, event)
275287

0 commit comments

Comments
 (0)