5555from ietf .ietfauth .utils import role_required , has_role
5656from ietf .mailtrigger .utils import gather_address_lists
5757from ietf .meeting .models import Meeting , Session , Schedule , FloorPlan , SessionPresentation , TimeSlot , SlideSubmission
58- from ietf .meeting .models import SessionStatusName , SchedulingEvent , SchedTimeSessAssignment , Constraint , ConstraintName
58+ from ietf .meeting .models import SessionStatusName , SchedulingEvent , SchedTimeSessAssignment
5959from ietf .meeting .helpers import get_areas , get_person_by_email , get_schedule_by_name
6060from ietf .meeting .helpers import build_all_agenda_slices , get_wg_name_list
6161from ietf .meeting .helpers import get_all_assignments_from_schedule
7777from ietf .meeting .utils import session_requested_by
7878from ietf .meeting .utils import current_session_status
7979from ietf .meeting .utils import data_for_meetings_overview
80+ from ietf .meeting .utils import preprocess_constraints_for_meeting_schedule_editor
8081from ietf .message .utils import infer_message
8182from ietf .secr .proceedings .utils import handle_upload_file
8283from ietf .secr .proceedings .proc_utils import (get_progress_stats , post_process , import_audio_files ,
@@ -623,70 +624,8 @@ def cubehelix(i, total, hue=1.2, start_angle=0.5):
623624 # requesters
624625 requested_by_lookup = {p .pk : p for p in Person .objects .filter (pk__in = set (s .requested_by for s in sessions if s .requested_by ))}
625626
626- # constraints - convert the human-readable rules in the database
627- # to constraints on the actual sessions, compress them and output
628- # them, so that the JS simply has to detect violations and show
629- # the relevant preprocessed label
630- constraints = Constraint .objects .filter (meeting = meeting )
631- person_needed_for_groups = defaultdict (set )
632- for c in constraints :
633- if c .name_id == 'bethere' and c .person_id is not None :
634- person_needed_for_groups [c .person_id ].add (c .source_id )
635-
636- sessions_for_group = defaultdict (list )
637- for s in sessions :
638- if s .group_id is not None :
639- sessions_for_group [s .group_id ].append (s .pk )
640-
641- constraint_names = {n .pk : n for n in ConstraintName .objects .all ()}
642- constraint_names_with_count = set ()
643- constraint_label_replacements = [
644- (re .compile (r"\(person\)" ), lambda match_groups : format_html ("<i class=\" fa fa-user-o\" ></i>" )),
645- (re .compile (r"\(([^()])\)" ), lambda match_groups : format_html ("<span class=\" encircled\" >{}</span>" , match_groups [0 ])),
646- ]
647- for n in list (constraint_names .values ()):
648- # spiff up the labels a bit
649- for pattern , replacer in constraint_label_replacements :
650- m = pattern .match (n .editor_label )
651- if m :
652- n .editor_label = replacer (m .groups ())
653-
654- # add reversed version of the name
655- reverse_n = ConstraintName (
656- slug = n .slug + "-reversed" ,
657- name = "{} - reversed" .format (n .name ),
658- )
659- reverse_n .editor_label = format_html ("<i>{}</i>" , n .editor_label )
660- constraint_names [reverse_n .slug ] = reverse_n
661-
662- constraints_for_sessions = defaultdict (list )
663-
664- def add_group_constraints (g1_pk , g2_pk , name_id , person_id ):
665- if g1_pk != g2_pk :
666- for s1_pk in sessions_for_group .get (g1_pk , []):
667- for s2_pk in sessions_for_group .get (g2_pk , []):
668- if s1_pk != s2_pk :
669- constraints_for_sessions [s1_pk ].append ((name_id , s2_pk , person_id ))
670-
671- reverse_constraints = []
672- seen_forward_constraints_for_groups = set ()
673-
674- for c in constraints :
675- if c .target_id :
676- add_group_constraints (c .source_id , c .target_id , c .name_id , c .person_id )
677- seen_forward_constraints_for_groups .add ((c .source_id , c .target_id , c .name_id ))
678- reverse_constraints .append (c )
679-
680- elif c .person_id :
681- constraint_names_with_count .add (c .name_id )
682-
683- for g in person_needed_for_groups .get (c .person_id ):
684- add_group_constraints (c .source_id , g , c .name_id , c .person_id )
685-
686- for c in reverse_constraints :
687- # suppress reverse constraints in case we have a forward one already
688- if (c .target_id , c .source_id , c .name_id ) not in seen_forward_constraints_for_groups :
689- add_group_constraints (c .target_id , c .source_id , c .name_id + "-reversed" , c .person_id )
627+ # constraints
628+ constraints_for_sessions , formatted_constraints_for_sessions , constraint_names = preprocess_constraints_for_meeting_schedule_editor (meeting , sessions )
690629
691630 unassigned_sessions = []
692631 for s in sessions :
@@ -705,22 +644,25 @@ def add_group_constraints(g1_pk, g2_pk, name_id, person_id):
705644 s .parent_acronym = s .group .parent .acronym if s .group and s .group .parent else ""
706645 s .historic_group_ad_name = ad_names .get (s .group_id )
707646
708- # compress the constraints, so similar constraint explanations
709- # are shared between the conflicting sessions they cover
710- constrained_sessions_grouped_by_explanation = defaultdict (set )
647+ # compress the constraints, so similar constraint labels are
648+ # shared between the conflicting sessions they cover - the JS
649+ # then simply has to detect violations and show the
650+ # preprocessed labels
651+ constrained_sessions_grouped_by_label = defaultdict (set )
711652 for name_id , ts in itertools .groupby (sorted (constraints_for_sessions .get (s .pk , [])), key = lambda t : t [0 ]):
712653 ts = list (ts )
713654 session_pks = (t [1 ] for t in ts )
714655 constraint_name = constraint_names [name_id ]
715- if name_id in constraint_names_with_count :
656+ if "{count}" in constraint_name . formatted_editor_label :
716657 for session_pk , grouped_session_pks in itertools .groupby (session_pks ):
717658 count = sum (1 for i in grouped_session_pks )
718- constrained_sessions_grouped_by_explanation [format_html ("{}{}" , constraint_name .editor_label , count )].add (session_pk )
659+ constrained_sessions_grouped_by_label [format_html (constraint_name .formatted_editor_label , count = count )].add (session_pk )
719660
720661 else :
721- constrained_sessions_grouped_by_explanation [constraint_name .editor_label ].update (session_pks )
662+ constrained_sessions_grouped_by_label [constraint_name .formatted_editor_label ].update (session_pks )
722663
723- s .constrained_sessions = list (constrained_sessions_grouped_by_explanation .items ())
664+ s .constrained_sessions = list (constrained_sessions_grouped_by_label .items ())
665+ s .formatted_constraints = formatted_constraints_for_sessions .get (s .pk , {})
724666
725667 assigned = False
726668 for a in assignments_by_session .get (s .pk , []):
0 commit comments