Skip to content

Commit

Permalink
Serialize only session timetable when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mic4ael committed Jul 30, 2018
1 parent 8ef8ea5 commit 4c3520f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -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
-------------
Expand Down
3 changes: 2 additions & 1 deletion indico/htdocs/js/indico/modules/sessions/common.js
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion indico/htdocs/js/indico/modules/timetable/timetable/Draw.js
Expand Up @@ -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({
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 8 additions & 2 deletions indico/modules/events/timetable/controllers/legacy.py
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion indico/modules/events/timetable/controllers/manage.py
Expand Up @@ -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)


Expand Down
@@ -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 %}
Expand Down Expand Up @@ -36,11 +36,14 @@
</dl>
{% endmacro %}

{% macro render_palette_picker(obj, endpoint, color_list) %}
{% macro render_palette_picker(obj, endpoint, color_list, is_session_timetable) %}
<a class="i-button color-button palette-picker palette-picker-trigger"
style="{{ obj.colors.css }}"
data-method="PATCH"
data-href="{{ url_for(endpoint, obj) }}"
{% if is_session_timetable -%}
data-is-session-timetable="{{ is_session_timetable | tojson | forceescape }}"
{%- endif %}
data-palette="{{ color_list | tojson | forceescape }}"
data-initial-color="{{ obj.colors | tojson | forceescape }}"
title="{% trans %}Change colour{% endtrans %}"></a>
Expand Down
Expand Up @@ -40,7 +40,7 @@
<div class="group right entry-action-buttons">
{% 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) }}
<a class="i-link icon-edit js-dialog-action js-edit js-hide-balloon"
title="{% trans %}Edit session{% endtrans %}"
data-extra-params='{"edit_session": 1}'
Expand Down
Expand Up @@ -5,7 +5,7 @@
<div class="title">{{ break_.title }}</div>
{% if editable %}
<div class="group right entry-action-buttons hide-if-locked">
{{ render_palette_picker(break_, 'timetable.legacy_break_rest', color_list) }}
{{ render_palette_picker(break_, 'timetable.legacy_break_rest', color_list, is_session_timetable) }}
<a class="i-link icon-edit js-dialog-action js-edit js-hide-balloon"
title="{% trans %}Edit break{% endtrans %}"
data-title="{% trans title=break_.title %}Edit break '{{ title }}'{% endtrans %}"></a>
Expand Down
8 changes: 5 additions & 3 deletions indico/modules/events/timetable/util.py
Expand Up @@ -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,
Expand All @@ -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")

Expand Down

0 comments on commit 4c3520f

Please sign in to comment.