Skip to content

Commit 49d4be8

Browse files
committed
Rework the new meeting editor label formatting to store the icon
references directly in the database as HTML. Rework the label update migration to take this into account (can be rerun by running "ietf/manage.py migrate name 0011 --fake" first). Add a little bit of support for the recently added constraints types - the JS does not hint about them, but they do show up without looking silly. - Legacy-Id: 18033
1 parent ab17817 commit 49d4be8

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

ietf/meeting/utils.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from django.template.loader import render_to_string
1515
from django.db.models.expressions import Subquery, OuterRef
1616
from django.utils.html import format_html
17+
from django.utils.safestring import mark_safe
1718

1819
import debug # pyflakes:ignore
1920

@@ -309,16 +310,14 @@ def data_for_meetings_overview(meetings, interim_status=None):
309310

310311
return meetings
311312

312-
def format_constraint_editor_label(label, inner_fmt="{}"):
313-
m = re.match(r'(.*)\(person\)(.*)', label)
314-
if m:
315-
return format_html("{}<i class=\"fa fa-user-o\"></i>{}", format_html(inner_fmt, m.groups()[0]), m.groups()[1])
313+
def reverse_editor_label(label):
314+
reverse_sign = "-"
316315

317-
m = re.match(r"\(([^()]+)\)", label)
316+
m = re.match(r"(<[^>]+>)([^<].*)", label)
318317
if m:
319-
return format_html("<span class=\"encircled\">{}</span>", format_html(inner_fmt, m.groups()[0]))
320-
321-
return format_html(inner_fmt, label)
318+
return m.groups()[0] + reverse_sign + m.groups()[1]
319+
else:
320+
return reverse_sign + label
322321

323322
def preprocess_constraints_for_meeting_schedule_editor(meeting, sessions):
324323
constraints = Constraint.objects.filter(meeting=meeting).prefetch_related('target', 'person', 'timeranges')
@@ -332,10 +331,10 @@ def preprocess_constraints_for_meeting_schedule_editor(meeting, sessions):
332331
slug=n.slug + "-reversed",
333332
name="{} - reversed".format(n.name),
334333
)
335-
reverse_n.formatted_editor_label = format_constraint_editor_label(n.editor_label, inner_fmt="-{}")
334+
reverse_n.formatted_editor_label = mark_safe(reverse_editor_label(n.editor_label))
336335
constraint_names[reverse_n.slug] = reverse_n
337336

338-
n.formatted_editor_label = format_constraint_editor_label(n.editor_label)
337+
n.formatted_editor_label = mark_safe(n.editor_label)
339338
n.countless_formatted_editor_label = format_html(n.formatted_editor_label, count="") if "{count}" in n.formatted_editor_label else n.formatted_editor_label
340339

341340
# convert human-readable rules in the database to constraints on actual sessions
@@ -362,7 +361,7 @@ def add_group_constraints(g1_pk, g2_pk, name_id, person_id):
362361
seen_forward_constraints_for_groups = set()
363362

364363
for c in constraints:
365-
if c.target_id:
364+
if c.target_id and c.name_id != 'wg_adjacent':
366365
add_group_constraints(c.source_id, c.target_id, c.name_id, c.person_id)
367366
seen_forward_constraints_for_groups.add((c.source_id, c.target_id, c.name_id))
368367
reverse_constraints.append(c)
@@ -395,4 +394,20 @@ def format_constraint(c):
395394
for s_pk in sessions_for_group.get(group_pk, []):
396395
formatted_constraints_for_sessions[s_pk][constraint_names[cn_pk]] = [format_constraint(c) for c in cs]
397396

397+
# it's easier for the rest of the code if we treat
398+
# joint_with_groups as a constraint, even if it's not modelled as
399+
# one
400+
joint_with_groups_constraint_name = ConstraintName(
401+
slug='joint_with_groups',
402+
name="Joint session with",
403+
editor_label="<i class=\"fa fa-clone\"></i>",
404+
order=8,
405+
)
406+
joint_with_groups_constraint_name.formatted_editor_label = mark_safe(joint_with_groups_constraint_name.editor_label)
407+
joint_with_groups_constraint_name.countless_formatted_editor_label = joint_with_groups_constraint_name.formatted_editor_label
408+
for s in sessions:
409+
joint_groups = s.joint_with_groups.all()
410+
if joint_groups:
411+
formatted_constraints_for_sessions[s.pk][joint_with_groups_constraint_name] = [g.acronym for g in joint_groups]
412+
398413
return constraints_for_sessions, formatted_constraints_for_sessions, constraint_names

ietf/meeting/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def edit_meeting_schedule(request, num=None, owner=None, name=None):
470470
requested_time=True,
471471
requested_by=True,
472472
).exclude(current_status__in=['notmeet', 'disappr', 'deleted', 'apprw']).prefetch_related(
473-
'resources', 'group', 'group__parent', 'group__type',
473+
'resources', 'group', 'group__parent', 'group__type', 'joint_with_groups',
474474
)
475475

476476
if request.method == 'POST':
@@ -507,14 +507,14 @@ def edit_meeting_schedule(request, num=None, owner=None, name=None):
507507
for a in assignments:
508508
assignments_by_session[a.session_id].append(a)
509509

510-
# Prepare timeslot layout, making a timeline per day scaled in
511-
# browser rem units to ensure that everything lines up even if the
512-
# timeslots are not the same in the different rooms
510+
# prepare timeslot layout
513511

514512
min_duration = min(t.duration for t in timeslots_qs)
515513
max_duration = max(t.duration for t in timeslots_qs)
516514

517515
def timedelta_to_css_ems(timedelta):
516+
# we scale the session and slots a bit according to their
517+
# length for an added visual clue
518518
capped_min_d = max(min_duration, datetime.timedelta(minutes=30))
519519
capped_max_d = min(max_duration, datetime.timedelta(hours=4))
520520
capped_timedelta = min(max(capped_min_d, timedelta), capped_max_d)

ietf/name/migrations/0012_update_constraintname_order_and_label.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright The IETF Trust 2020, All Rights Reserved
22

3-
from django.db import migrations
3+
from django.db import migrations, models
44

55

66
class Migration(migrations.Migration):
@@ -12,7 +12,13 @@ def update_editor_labels(apps, schema_editor):
1212
ConstraintName = apps.get_model('name', 'ConstraintName')
1313
for cn in ConstraintName.objects.all():
1414
cn.editor_label = {
15-
'bethere': "(person){count}",
15+
'bethere': "<i class=\"fa fa-user-o\"></i>{count}",
16+
'wg_adjacent': "<i class=\"fa fa-step-forward\"></i>",
17+
'conflict': "<span class=\"encircled\">1</span>",
18+
'conflic2': "<span class=\"encircled\">2</span>",
19+
'conflic3': "<span class=\"encircled\">3</span>",
20+
'time_relation': "&Delta;",
21+
'timerange': "<i class=\"fa fa-calendar-o\"></i>",
1622
}.get(cn.slug, cn.editor_label)
1723

1824
cn.order = {
@@ -31,5 +37,10 @@ def noop(apps, schema_editor):
3137
pass
3238

3339
operations = [
40+
migrations.AlterField(
41+
model_name='constraintname',
42+
name='editor_label',
43+
field=models.CharField(blank=True, help_text='Very short label for producing warnings inline in the sessions in the schedule editor.', max_length=64),
44+
),
3445
migrations.RunPython(update_editor_labels, noop, elidable=True),
3546
]

ietf/name/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TimeSlotTypeName(NameModel):
6969
class ConstraintName(NameModel):
7070
"""conflict, conflic2, conflic3, bethere, timerange, time_relation, wg_adjacent"""
7171
penalty = models.IntegerField(default=0, help_text="The penalty for violating this kind of constraint; for instance 10 (small penalty) or 10000 (large penalty)")
72-
editor_label = models.CharField(max_length=32, blank=True, help_text="Very short label for producing warnings inline in the sessions in the schedule editor.")
72+
editor_label = models.CharField(max_length=64, blank=True, help_text="Very short label for producing warnings inline in the sessions in the schedule editor.")
7373
class TimerangeName(NameModel):
7474
"""(monday|tuesday|wednesday|thursday|friday)-(morning|afternoon-early|afternoon-late)"""
7575
class LiaisonStatementPurposeName(NameModel):

0 commit comments

Comments
 (0)