2424from ietf .group .utils import can_manage_materials
2525from ietf .name .models import SessionStatusName , ConstraintName
2626from ietf .nomcom .utils import DISQUALIFYING_ROLE_QUERY_EXPRESSION
27- from ietf .person .models import Email
27+ from ietf .person .models import Person , Email
2828from ietf .secr .proceedings .proc_utils import import_audio_files
2929
3030def session_time_for_sorting (session , use_meeting_date ):
@@ -319,12 +319,27 @@ def reverse_editor_label(label):
319319 else :
320320 return reverse_sign + label
321321
322- def preprocess_constraints_for_meeting_schedule_editor (meeting , sessions ):
323- constraints = Constraint .objects .filter (meeting = meeting ).prefetch_related ('target' , 'person' , 'timeranges' )
324-
325- # process constraint names
322+ def preprocess_constraints_for_meeting_schedule_editor (meeting , sessions , responsible_ad_for_group ):
323+ # process constraint names - we synthesize extra names to be able
324+ # to treat the concepts in the same manner as the modelled ones
326325 constraint_names = {n .pk : n for n in ConstraintName .objects .all ()}
327326
327+ joint_with_groups_constraint_name = ConstraintName (
328+ slug = 'joint_with_groups' ,
329+ name = "Joint session with" ,
330+ editor_label = "<i class=\" fa fa-clone\" ></i>" ,
331+ order = 8 ,
332+ )
333+ constraint_names [joint_with_groups_constraint_name .slug ] = joint_with_groups_constraint_name
334+
335+ ad_constraint_name = ConstraintName (
336+ slug = 'responsible_ad' ,
337+ name = "Responsible AD" ,
338+ editor_label = "<span class=\" encircled\" >AD</span>" ,
339+ order = 9 ,
340+ )
341+ constraint_names [ad_constraint_name .slug ] = ad_constraint_name
342+
328343 for n in list (constraint_names .values ()):
329344 # add reversed version of the name
330345 reverse_n = ConstraintName (
@@ -338,12 +353,23 @@ def preprocess_constraints_for_meeting_schedule_editor(meeting, sessions):
338353 n .countless_formatted_editor_label = format_html (n .formatted_editor_label , count = "" ) if "{count}" in n .formatted_editor_label else n .formatted_editor_label
339354
340355 # convert human-readable rules in the database to constraints on actual sessions
356+ constraints = list (Constraint .objects .filter (meeting = meeting ).prefetch_related ('target' , 'person' , 'timeranges' ))
357+
358+ # synthesize AD constraints - we can treat them as a special kind of 'bethere'
359+ ad_person_lookup = {p .pk : p for p in Person .objects .filter (pk__in = set (responsible_ad_for_group .values ()))}
360+ groups_at_meeting = {s .group for s in sessions }
361+ for group in groups_at_meeting :
362+ ad = ad_person_lookup .get (responsible_ad_for_group .get (group .pk ))
363+ if ad is not None :
364+ constraints .append (Constraint (meeting = meeting , source = group , person = ad , name = ad_constraint_name ))
365+
366+ # process must not be scheduled at the same time constraints
341367 constraints_for_sessions = defaultdict (list )
342368
343- person_needed_for_groups = defaultdict (set )
369+ person_needed_for_groups = { cn . slug : defaultdict (set ) for cn in constraint_names . values ()}
344370 for c in constraints :
345- if c .name_id == 'bethere' and c . person_id is not None :
346- person_needed_for_groups [c .person_id ].add (c .source_id )
371+ if c .person_id is not None :
372+ person_needed_for_groups [c .name_id ][ c . person_id ].add (c .source_id )
347373
348374 sessions_for_group = defaultdict (list )
349375 for s in sessions :
@@ -367,7 +393,7 @@ def add_group_constraints(g1_pk, g2_pk, name_id, person_id):
367393 reverse_constraints .append (c )
368394
369395 elif c .person_id :
370- for g in person_needed_for_groups .get (c .person_id ):
396+ for g in person_needed_for_groups [ c . name_id ] .get (c .person_id ):
371397 add_group_constraints (c .source_id , g , c .name_id , c .person_id )
372398
373399 for c in reverse_constraints :
@@ -394,17 +420,7 @@ def format_constraint(c):
394420 for s_pk in sessions_for_group .get (group_pk , []):
395421 formatted_constraints_for_sessions [s_pk ][constraint_names [cn_pk ]] = [format_constraint (c ) for c in cs ]
396422
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
423+ # synthesize joint_with_groups constraints
408424 for s in sessions :
409425 joint_groups = s .joint_with_groups .all ()
410426 if joint_groups :
0 commit comments