From 4c3520fdd91c022dc0dddd76118db8945c64ae49 Mon Sep 17 00:00:00 2001 From: Michal Kolodziejski Date: Thu, 26 Jul 2018 09:53:35 +0200 Subject: [PATCH] Serialize only session timetable when necessary Fixes #3474 --- CHANGES.rst | 2 ++ indico/htdocs/js/indico/modules/sessions/common.js | 3 ++- .../js/indico/modules/timetable/timetable/Draw.js | 4 +++- indico/modules/events/timetable/controllers/legacy.py | 10 ++++++++-- indico/modules/events/timetable/controllers/manage.py | 4 +++- .../timetable/templates/balloons/_balloon_utils.html | 7 +++++-- .../events/timetable/templates/balloons/block.html | 2 +- .../events/timetable/templates/balloons/break.html | 2 +- indico/modules/events/timetable/util.py | 8 +++++--- 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index db220ef6ee5..edd6a8f523f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,8 @@ Bugfixes - Fix massive performance issue on the material package page in big events - Fix error when using the checkin app to mark someone as checked in (:issue:`3473`, thanks :user:`femtobit`) +- Only return timetable entries for the current session when updating a + session through the timetable (:issue:`3474`) Version 2.1.2 ------------- diff --git a/indico/htdocs/js/indico/modules/sessions/common.js b/indico/htdocs/js/indico/modules/sessions/common.js index 42ed7032d90..5727ee56282 100644 --- a/indico/htdocs/js/indico/modules/sessions/common.js +++ b/indico/htdocs/js/indico/modules/sessions/common.js @@ -39,7 +39,8 @@ $.ajax({ url: $(this).data('href'), method: $(this).data('method'), - data: JSON.stringify({colors: {text: text, background: background}}), + data: JSON.stringify({colors: {text: text, background: background}, + is_session_timetable: $(this).data('is-session-timetable')}), dataType: 'json', contentType: 'application/json', error: handleAjaxError, diff --git a/indico/htdocs/js/indico/modules/timetable/timetable/Draw.js b/indico/htdocs/js/indico/modules/timetable/timetable/Draw.js index 8b399df7ab0..2d7bd685093 100644 --- a/indico/htdocs/js/indico/modules/timetable/timetable/Draw.js +++ b/indico/htdocs/js/indico/modules/timetable/timetable/Draw.js @@ -539,6 +539,7 @@ function loadBalloonContent(self, api, editable) { }; if (self.timetable.isSessionTimetable) { urlParams.session_id = self.eventData.sessionId; + urlParams.is_session_timetable = true; } $.ajax({ @@ -684,7 +685,8 @@ function loadBalloonContent(self, api, editable) { $.ajax({ url: $picker.data('href'), method: $picker.data('method'), - data: JSON.stringify({'colors': {'text': text, 'background': background}}), + data: JSON.stringify({'colors': {'text': text, 'background': background}, + 'is_session_timetable': $picker.data('is-session-timetable')}), dataType: 'json', contentType: 'application/json', complete: IndicoUI.Dialogs.Util.progress(), diff --git a/indico/modules/events/timetable/controllers/legacy.py b/indico/modules/events/timetable/controllers/legacy.py index c498bcdadbd..fb11567cee6 100644 --- a/indico/modules/events/timetable/controllers/legacy.py +++ b/indico/modules/events/timetable/controllers/legacy.py @@ -522,10 +522,16 @@ def _process(self): class RHLegacyTimetableEditSession(RHSessionREST): + def _process_args(self): + RHSessionREST._process_args(self) + self.is_session_timetable = request.json.pop('is_session_timetable', False) + def _process_PATCH(self): RHSessionREST._process_PATCH(self) - return jsonify_data(entries=[serialize_entry_update(block.timetable_entry) for block in self.session.blocks], - flash=False) + entries = [serialize_entry_update(block.timetable_entry, + session_=(self.session if self.is_session_timetable else None)) + for block in self.session.blocks] + return jsonify_data(entries=entries, flash=False) class RHLegacyTimetableBreakREST(RHBreakREST): diff --git a/indico/modules/events/timetable/controllers/manage.py b/indico/modules/events/timetable/controllers/manage.py index 585f851eb32..45ebf1de076 100644 --- a/indico/modules/events/timetable/controllers/manage.py +++ b/indico/modules/events/timetable/controllers/manage.py @@ -146,10 +146,12 @@ class RHManageTimetableEntryInfo(RHManageTimetableBase): def _process_args(self): RHManageTimetableBase._process_args(self) + self.is_session_timetable = request.args.get('is_session_timetable', False) self.entry = self.event.timetable_entries.filter_by(id=request.view_args['entry_id']).first_or_404() def _process(self): - html = render_entry_info_balloon(self.entry, editable=True, sess=self.session) + html = render_entry_info_balloon(self.entry, editable=True, sess=self.session, + is_session_timetable=self.is_session_timetable) return jsonify(html=html) diff --git a/indico/modules/events/timetable/templates/balloons/_balloon_utils.html b/indico/modules/events/timetable/templates/balloons/_balloon_utils.html index cc8f3732aec..687213c91c8 100644 --- a/indico/modules/events/timetable/templates/balloons/_balloon_utils.html +++ b/indico/modules/events/timetable/templates/balloons/_balloon_utils.html @@ -1,4 +1,4 @@ -{% macro render_time_and_location(obj, editable, use_event_tz) %} +{% macro render_time_and_location(obj, editable, use_event_tz, is_session_timetable=false) %} {% set tt_entry = obj.timetable_entry %} {% set event = tt_entry.event %} {% set tz = event.tzinfo if use_event_tz else event.display_tzinfo %} @@ -36,11 +36,14 @@ {% endmacro %} -{% macro render_palette_picker(obj, endpoint, color_list) %} +{% macro render_palette_picker(obj, endpoint, color_list, is_session_timetable) %} diff --git a/indico/modules/events/timetable/templates/balloons/block.html b/indico/modules/events/timetable/templates/balloons/block.html index 818edd7a3a5..4917d80df7e 100644 --- a/indico/modules/events/timetable/templates/balloons/block.html +++ b/indico/modules/events/timetable/templates/balloons/block.html @@ -40,7 +40,7 @@
{% if editable and not block.event.is_locked %} {% if can_manage_session %} - {{ render_palette_picker(block.session, 'timetable.session_rest', color_list) }} + {{ render_palette_picker(block.session, 'timetable.session_rest', color_list, is_session_timetable) }} {{ break_.title }}
{% if editable %}
- {{ render_palette_picker(break_, 'timetable.legacy_break_rest', color_list) }} + {{ render_palette_picker(break_, 'timetable.legacy_break_rest', color_list, is_session_timetable) }} diff --git a/indico/modules/events/timetable/util.py b/indico/modules/events/timetable/util.py index e8e62c623c5..f37988b76ab 100644 --- a/indico/modules/events/timetable/util.py +++ b/indico/modules/events/timetable/util.py @@ -255,11 +255,12 @@ def get_category_timetable(categ_ids, start_dt, end_dt, detail_level='event', tz return result -def render_entry_info_balloon(entry, editable=False, sess=None): +def render_entry_info_balloon(entry, editable=False, sess=None, is_session_timetable=False): if entry.break_: return render_template('events/timetable/balloons/break.html', break_=entry.break_, editable=editable, can_manage_event=entry.event.can_manage(session.user), color_list=get_colors(), - event_locked=entry.event.is_locked) + event_locked=entry.event.is_locked, + is_session_timetable=is_session_timetable) elif entry.contribution: return render_template('events/timetable/balloons/contribution.html', contrib=entry.contribution, editable=editable, @@ -270,7 +271,8 @@ def render_entry_info_balloon(entry, editable=False, sess=None): return render_template('events/timetable/balloons/block.html', block=entry.session_block, editable=editable, can_manage_session=sess.can_manage(session.user) if sess else True, can_manage_blocks=sess.can_manage_blocks(session.user) if sess else True, - color_list=get_colors(), event_locked=entry.event.is_locked) + color_list=get_colors(), event_locked=entry.event.is_locked, + is_session_timetable=is_session_timetable) else: raise ValueError("Invalid entry")